forked from GNUsocial/gnu-social
Refactored new sections code to proper classes and added notice link to links in notice sections.
This commit is contained in:
parent
a325144fa0
commit
5897dfa4c3
@ -53,18 +53,6 @@ class AttachmentAction extends Action
|
||||
|
||||
var $attachment = null;
|
||||
|
||||
/**
|
||||
* Profile of the notice object
|
||||
*/
|
||||
|
||||
// var $profile = null;
|
||||
|
||||
/**
|
||||
* Avatar of the profile of the notice object
|
||||
*/
|
||||
|
||||
// var $avatar = null;
|
||||
|
||||
/**
|
||||
* Load attributes based on database arguments
|
||||
*
|
||||
@ -112,8 +100,6 @@ class AttachmentAction extends Action
|
||||
return $a->title();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Last-modified date for page
|
||||
*
|
||||
@ -213,38 +199,11 @@ class AttachmentAction extends Action
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function showAside() {
|
||||
$notice = new Notice;
|
||||
$f2p = new File_to_post;
|
||||
$f2p->file_id = $this->attachment->id;
|
||||
$notice->joinAdd($f2p);
|
||||
$notice->orderBy('created desc');
|
||||
$x = $notice->find();
|
||||
$this->elementStart('ol');
|
||||
while($notice->fetch()) {
|
||||
$this->elementStart('li');
|
||||
$profile = $notice->getProfile();
|
||||
$this->element('a', array('href' => $notice->uri), $profile->nickname . ' on ' . $notice->created);
|
||||
$this->elementEnd('li');
|
||||
}
|
||||
$this->elementEnd('ol');
|
||||
$notice->free();
|
||||
$f2p->free();
|
||||
|
||||
$notice_tag = new Notice_tag;
|
||||
$attachment = new File;
|
||||
|
||||
$query = 'select tag,count(tag) as c from notice_tag join file_to_post on (notice_tag.notice_id=post_id) join notice on notice_id = notice.id where file_id=' . $notice_tag->escape($this->attachment->id) . ' group by tag order by c desc';
|
||||
|
||||
$notice_tag->query($query);
|
||||
$this->elementStart('ol');
|
||||
while($notice_tag->fetch()) {
|
||||
$this->elementStart('li');
|
||||
$href = common_local_url('tag', array('tag' => $notice_tag->tag));
|
||||
$this->element('a', array('href' => $href), $notice_tag->tag . ' (' . $notice_tag->c . ')');
|
||||
$this->elementEnd('li');
|
||||
}
|
||||
$this->elementEnd('ol');
|
||||
function showSections() {
|
||||
$ns = new AttachmentNoticeSection($this);
|
||||
$ns->show();
|
||||
$atcs = new AttachmentTagCloudSection($this);
|
||||
$atcs->show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,17 +49,8 @@ class TagAction extends Action
|
||||
{
|
||||
$pop = new PopularNoticeSection($this);
|
||||
$pop->show();
|
||||
|
||||
$notice_tag = new Notice_tag;
|
||||
$query = 'select file_id, count(file_id) as c from notice_tag join file_to_post on post_id = notice_id where tag="' . $notice_tag->escape($this->tag) . '" group by file_id order by c desc';
|
||||
$notice_tag->query($query);
|
||||
$this->elementStart('ol');
|
||||
while ($notice_tag->fetch()) {
|
||||
$this->elementStart('li');
|
||||
$this->element('a', array('class' => 'attachment', 'href' => common_local_url('attachment', array('attachment' => $notice_tag->file_id))), "Attachment tagged {$notice_tag->c} times");
|
||||
$this->elementEnd('li');
|
||||
}
|
||||
$this->elementEnd('ol');
|
||||
$freqatt = new FrequentAttachmentSection($this);
|
||||
$freqatt->show();
|
||||
}
|
||||
|
||||
function title()
|
||||
|
@ -134,7 +134,7 @@ class Notice extends Memcached_DataObject
|
||||
return _('Too many notices too fast; take a breather and post again in a few minutes.');
|
||||
}
|
||||
|
||||
if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
|
||||
if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $content)) {
|
||||
common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
|
||||
return _('Too many duplicate messages too quickly; take a breather and post again in a few minutes.');
|
||||
}
|
||||
@ -278,8 +278,8 @@ class Notice extends Memcached_DataObject
|
||||
}
|
||||
|
||||
function hasAttachments() {
|
||||
$post = clone($this);
|
||||
$query = "select count(file_id) as n_attachments from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $post->escape($this->id);
|
||||
$post = clone $this;
|
||||
$query = "select count(file_id) as n_attachments from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $post->escape($post->id);
|
||||
$post->query($query);
|
||||
$post->fetch();
|
||||
$n_attachments = intval($post->n_attachments);
|
||||
|
@ -33,6 +33,12 @@ $config['site']['path'] = 'laconica';
|
||||
#Make the site invisible to non-logged-in users
|
||||
#$config['site']['private'] = true;
|
||||
|
||||
# 'direct' for direct notice links in sections
|
||||
# 'attachment' for notice attachment links in sections
|
||||
# left undefined, no link is showed
|
||||
#$config['site']['notice_link'] = 'attachment';
|
||||
#$config['site']['notice_link'] = 'direct';
|
||||
|
||||
# If you want logging sent to a file instead of syslog
|
||||
#$config['site']['logfile'] = '/tmp/laconica.log';
|
||||
|
||||
|
@ -64,7 +64,7 @@ function handleError($error)
|
||||
function main()
|
||||
{
|
||||
// quick check for fancy URL auto-detection support in installer.
|
||||
if ('/check-fancy' === $_SERVER['REDIRECT_URL']) {
|
||||
if (isset($_SERVER['REDIRECT_URL']) && ('/check-fancy' === $_SERVER['REDIRECT_URL'])) {
|
||||
die("Fancy URL support detection succeeded. We suggest you enable this to get fancy (pretty) URLs.");
|
||||
}
|
||||
global $user, $action, $config;
|
||||
|
75
lib/attachmentnoticesection.php
Normal file
75
lib/attachmentnoticesection.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Laconica, the distributed open-source microblogging tool
|
||||
*
|
||||
* FIXME
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Widget
|
||||
* @package Laconica
|
||||
* @author Evan Prodromou <evan@controlyourself.ca>
|
||||
* @copyright 2009 Control Yourself, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://laconi.ca/
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME
|
||||
*
|
||||
* These are the widgets that show interesting data about a person * group, or site.
|
||||
*
|
||||
* @category Widget
|
||||
* @package Laconica
|
||||
* @author Evan Prodromou <evan@controlyourself.ca>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://laconi.ca/
|
||||
*/
|
||||
|
||||
class AttachmentNoticeSection extends NoticeSection
|
||||
{
|
||||
function showContent() {
|
||||
parent::showContent();
|
||||
return false;
|
||||
}
|
||||
|
||||
function getNotices()
|
||||
{
|
||||
$notice = new Notice;
|
||||
$f2p = new File_to_post;
|
||||
$f2p->file_id = $this->out->attachment->id;
|
||||
$notice->joinAdd($f2p);
|
||||
$notice->orderBy('created desc');
|
||||
$notice->selectAdd('post_id as id');
|
||||
$notice->find();
|
||||
return $notice;
|
||||
}
|
||||
|
||||
function title()
|
||||
{
|
||||
return _('Notices where this attachment appears');
|
||||
}
|
||||
|
||||
function divId()
|
||||
{
|
||||
return 'popular_notices';
|
||||
}
|
||||
}
|
||||
|
80
lib/attachmentsection.php
Normal file
80
lib/attachmentsection.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Laconica, the distributed open-source microblogging tool
|
||||
*
|
||||
* Base class for sections showing lists of attachments
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Widget
|
||||
* @package Laconica
|
||||
* @author Evan Prodromou <evan@controlyourself.ca>
|
||||
* @copyright 2009 Control Yourself, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://laconi.ca/
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
define('ATTACHMENTS_PER_SECTION', 6);
|
||||
|
||||
/**
|
||||
* Base class for sections showing lists of attachments
|
||||
*
|
||||
* These are the widgets that show interesting data about a person
|
||||
* group, or site.
|
||||
*
|
||||
* @category Widget
|
||||
* @package Laconica
|
||||
* @author Evan Prodromou <evan@controlyourself.ca>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://laconi.ca/
|
||||
*/
|
||||
|
||||
class AttachmentSection extends Section
|
||||
{
|
||||
function showContent()
|
||||
{
|
||||
$attachments = $this->getAttachments();
|
||||
|
||||
$cnt = 0;
|
||||
|
||||
$this->out->elementStart('ul', 'attachments');
|
||||
|
||||
while ($attachments->fetch() && ++$cnt <= ATTACHMENTS_PER_SECTION) {
|
||||
$this->showAttachment($attachments);
|
||||
}
|
||||
|
||||
$this->out->elementEnd('ul');
|
||||
|
||||
return ($cnt > ATTACHMENTS_PER_SECTION);
|
||||
}
|
||||
|
||||
function getAttachments()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
function showAttachment($attachment)
|
||||
{
|
||||
$this->out->elementStart('li');
|
||||
$this->out->element('a', array('class' => 'attachment', 'href' => common_local_url('attachment', array('attachment' => $attachment->file_id))), "Attachment tagged {$attachment->c} times");
|
||||
$this->out->elementEnd('li');
|
||||
}
|
||||
}
|
||||
|
83
lib/attachmenttagcloudsection.php
Normal file
83
lib/attachmenttagcloudsection.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Laconica, the distributed open-source microblogging tool
|
||||
*
|
||||
* Attachment tag cloud section
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Widget
|
||||
* @package Laconica
|
||||
* @author Evan Prodromou <evan@controlyourself.ca>
|
||||
* @copyright 2009 Control Yourself, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://laconi.ca/
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attachment tag cloud section
|
||||
*
|
||||
* @category Widget
|
||||
* @package Laconica
|
||||
* @author Evan Prodromou <evan@controlyourself.ca>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://laconi.ca/
|
||||
*/
|
||||
|
||||
class AttachmentTagCloudSection extends TagCloudSection
|
||||
{
|
||||
function title()
|
||||
{
|
||||
return _('Tags for this attachment');
|
||||
}
|
||||
|
||||
function showTag($tag, $weight, $relative)
|
||||
{
|
||||
if ($relative > 0.5) {
|
||||
$rel = 'tag-cloud-7';
|
||||
} else if ($relative > 0.4) {
|
||||
$rel = 'tag-cloud-6';
|
||||
} else if ($relative > 0.3) {
|
||||
$rel = 'tag-cloud-5';
|
||||
} else if ($relative > 0.2) {
|
||||
$rel = 'tag-cloud-4';
|
||||
} else if ($relative > 0.1) {
|
||||
$rel = 'tag-cloud-3';
|
||||
} else if ($relative > 0.05) {
|
||||
$rel = 'tag-cloud-2';
|
||||
} else {
|
||||
$rel = 'tag-cloud-1';
|
||||
}
|
||||
|
||||
$this->out->elementStart('li', $rel);
|
||||
$this->out->element('a', array('href' => $this->tagUrl($tag)),
|
||||
$tag);
|
||||
$this->out->elementEnd('li');
|
||||
}
|
||||
|
||||
function getTags()
|
||||
{
|
||||
$notice_tag = new Notice_tag;
|
||||
$query = 'select tag,count(tag) as weight from notice_tag join file_to_post on (notice_tag.notice_id=post_id) join notice on notice_id = notice.id where file_id=' . $notice_tag->escape($this->out->attachment->id) . ' group by tag order by weight desc';
|
||||
$notice_tag->query($query);
|
||||
return $notice_tag;
|
||||
}
|
||||
}
|
||||
|
66
lib/frequentattachmentsection.php
Normal file
66
lib/frequentattachmentsection.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Laconica, the distributed open-source microblogging tool
|
||||
*
|
||||
* FIXME
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Widget
|
||||
* @package Laconica
|
||||
* @author Evan Prodromou <evan@controlyourself.ca>
|
||||
* @copyright 2009 Control Yourself, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://laconi.ca/
|
||||
*/
|
||||
|
||||
if (!defined('LACONICA')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME
|
||||
*
|
||||
* These are the widgets that show interesting data about a person
|
||||
* group, or site.
|
||||
*
|
||||
* @category Widget
|
||||
* @package Laconica
|
||||
* @author Evan Prodromou <evan@controlyourself.ca>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://laconi.ca/
|
||||
*/
|
||||
|
||||
class FrequentAttachmentSection extends AttachmentSection
|
||||
{
|
||||
function getAttachments() {
|
||||
$notice_tag = new Notice_tag;
|
||||
$query = 'select file_id, count(file_id) as c from notice_tag join file_to_post on post_id = notice_id where tag="' . $notice_tag->escape($this->out->tag) . '" group by file_id order by c desc';
|
||||
$notice_tag->query($query);
|
||||
return $notice_tag;
|
||||
}
|
||||
|
||||
function title()
|
||||
{
|
||||
return sprintf(_('Attachments frequently tagged with %s'), $this->out->tag);
|
||||
}
|
||||
|
||||
function divId()
|
||||
{
|
||||
return 'frequent_attachments';
|
||||
}
|
||||
}
|
||||
|
@ -51,17 +51,13 @@ class NoticeSection extends Section
|
||||
function showContent()
|
||||
{
|
||||
$notices = $this->getNotices();
|
||||
|
||||
$cnt = 0;
|
||||
|
||||
$this->out->elementStart('ul', 'notices');
|
||||
|
||||
while ($notices->fetch() && ++$cnt <= NOTICES_PER_SECTION) {
|
||||
$this->showNotice($notices);
|
||||
}
|
||||
|
||||
$this->out->elementEnd('ul');
|
||||
|
||||
return ($cnt > NOTICES_PER_SECTION);
|
||||
}
|
||||
|
||||
@ -100,6 +96,37 @@ class NoticeSection extends Section
|
||||
|
||||
$this->out->elementStart('p', 'entry-content');
|
||||
$this->out->raw($notice->rendered);
|
||||
|
||||
$notice_link_cfg = common_config('site', 'notice_link');
|
||||
if ('direct' === $notice_link_cfg) {
|
||||
$this->out->text(' (');
|
||||
$this->out->element('a', array('href' => $notice->uri), 'see');
|
||||
$this->out->text(')');
|
||||
} elseif ('attachment' === $notice_link_cfg) {
|
||||
if ($count = $notice->hasAttachments()) {
|
||||
// link to attachment(s) pages
|
||||
if (1 === $count) {
|
||||
$f2p = File_to_post::staticGet('post_id', $notice->id);
|
||||
$href = common_local_url('attachment', array('attachment' => $f2p->file_id));
|
||||
$att_class = 'attachment';
|
||||
} else {
|
||||
$href = common_local_url('attachments', array('notice' => $notice->id));
|
||||
$att_class = 'attachments';
|
||||
}
|
||||
|
||||
$clip = theme_path('images/icons/clip.png', 'base');
|
||||
$this->out->elementStart('a', array('class' => $att_class, 'style' => "font-style: italic;", 'href' => $href, 'title' => "# of attachments: $count"));
|
||||
$this->out->raw(" ($count ");
|
||||
$this->out->element('img', array('style' => 'display: inline', 'align' => 'top', 'width' => 20, 'height' => 20, 'src' => $clip, 'alt' => 'alt'));
|
||||
$this->out->text(')');
|
||||
$this->out->elementEnd('a');
|
||||
} else {
|
||||
$this->out->text(' (');
|
||||
$this->out->element('a', array('href' => $notice->uri), 'see');
|
||||
$this->out->text(')');
|
||||
}
|
||||
}
|
||||
|
||||
$this->out->elementEnd('p');
|
||||
if (!empty($notice->value)) {
|
||||
$this->out->elementStart('p');
|
||||
|
@ -51,7 +51,7 @@ class PopularNoticeSection extends NoticeSection
|
||||
if (common_config('db', 'type') == 'pgsql') {
|
||||
$weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
|
||||
if (!empty($this->out->tag)) {
|
||||
$tag = pg_escape_string($this->tag);
|
||||
$tag = pg_escape_string($this->out->tag);
|
||||
}
|
||||
} else {
|
||||
$weightexpr='sum(exp(-(now() - fave.modified) / %s))';
|
||||
|
Loading…
Reference in New Issue
Block a user