From 5897dfa4c37d6a44bcde5dc7569c8b0d30f21b84 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Sun, 17 May 2009 22:06:08 -0400 Subject: Refactored new sections code to proper classes and added notice link to links in notice sections. --- lib/attachmentnoticesection.php | 75 +++++++++++++++++++++++++++++++++++ lib/attachmentsection.php | 80 +++++++++++++++++++++++++++++++++++++ lib/attachmenttagcloudsection.php | 83 +++++++++++++++++++++++++++++++++++++++ lib/frequentattachmentsection.php | 66 +++++++++++++++++++++++++++++++ lib/noticesection.php | 35 +++++++++++++++-- lib/popularnoticesection.php | 2 +- 6 files changed, 336 insertions(+), 5 deletions(-) create mode 100644 lib/attachmentnoticesection.php create mode 100644 lib/attachmentsection.php create mode 100644 lib/attachmenttagcloudsection.php create mode 100644 lib/frequentattachmentsection.php (limited to 'lib') diff --git a/lib/attachmentnoticesection.php b/lib/attachmentnoticesection.php new file mode 100644 index 000000000..eb3176376 --- /dev/null +++ b/lib/attachmentnoticesection.php @@ -0,0 +1,75 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @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 + * @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'; + } +} + diff --git a/lib/attachmentsection.php b/lib/attachmentsection.php new file mode 100644 index 000000000..20e620b9b --- /dev/null +++ b/lib/attachmentsection.php @@ -0,0 +1,80 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @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 + * @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'); + } +} + diff --git a/lib/attachmenttagcloudsection.php b/lib/attachmenttagcloudsection.php new file mode 100644 index 000000000..50bfceccb --- /dev/null +++ b/lib/attachmenttagcloudsection.php @@ -0,0 +1,83 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @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 + * @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; + } +} + diff --git a/lib/frequentattachmentsection.php b/lib/frequentattachmentsection.php new file mode 100644 index 000000000..0ce0d1871 --- /dev/null +++ b/lib/frequentattachmentsection.php @@ -0,0 +1,66 @@ +. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @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 + * @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'; + } +} + diff --git a/lib/noticesection.php b/lib/noticesection.php index 94c2738ef..37aafdaf6 100644 --- a/lib/noticesection.php +++ b/lib/noticesection.php @@ -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'); diff --git a/lib/popularnoticesection.php b/lib/popularnoticesection.php index a8d47ef54..375d5538b 100644 --- a/lib/popularnoticesection.php +++ b/lib/popularnoticesection.php @@ -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))'; -- cgit v1.2.3-54-g00ecf