summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Millette <millette@controlyourself.ca>2009-05-17 22:06:08 -0400
committerRobin Millette <millette@controlyourself.ca>2009-05-17 22:06:08 -0400
commit5897dfa4c37d6a44bcde5dc7569c8b0d30f21b84 (patch)
tree6e882a25153ec071b4aa119bfdbd705ff51e2c90
parenta325144fa0ba769de1cdb554cac04e0116912b66 (diff)
Refactored new sections code to proper classes and added notice link to links in notice sections.
-rw-r--r--actions/attachment.php53
-rw-r--r--actions/tag.php13
-rw-r--r--classes/Notice.php6
-rw-r--r--config.php.sample6
-rw-r--r--index.php2
-rw-r--r--lib/attachmentnoticesection.php75
-rw-r--r--lib/attachmentsection.php80
-rw-r--r--lib/attachmenttagcloudsection.php83
-rw-r--r--lib/frequentattachmentsection.php66
-rw-r--r--lib/noticesection.php35
-rw-r--r--lib/popularnoticesection.php2
11 files changed, 354 insertions, 67 deletions
diff --git a/actions/attachment.php b/actions/attachment.php
index 981882a5b..b9187ff08 100644
--- a/actions/attachment.php
+++ b/actions/attachment.php
@@ -54,18 +54,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
*
* Loads all the DB stuff
@@ -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();
}
}
+
diff --git a/actions/tag.php b/actions/tag.php
index 2202f9bb0..47420e4c3 100644
--- a/actions/tag.php
+++ b/actions/tag.php
@@ -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()
diff --git a/classes/Notice.php b/classes/Notice.php
index 30508070e..f6ac4f780 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -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);
diff --git a/config.php.sample b/config.php.sample
index 0e6bf0e5f..826b086a3 100644
--- a/config.php.sample
+++ b/config.php.sample
@@ -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';
diff --git a/index.php b/index.php
index cfef21189..1b4fbf81b 100644
--- a/index.php
+++ b/index.php
@@ -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;
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 @@
+<?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';
+ }
+}
+
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 @@
+<?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');
+ }
+}
+
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 @@
+<?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;
+ }
+}
+
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 @@
+<?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';
+ }
+}
+
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&nbsp");
+ $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))';