3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 class TagAction extends Action
24 function prepare($args)
26 parent::prepare($args);
27 $taginput = $this->trimmed('tag');
28 $this->tag = common_canonical_tag($taginput);
31 common_redirect(common_local_url('publictagcloud'), 301);
35 if ($this->tag != $taginput) {
36 common_redirect(common_local_url('tag', array('tag' => $this->tag)),
41 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
43 common_set_returnto($this->selfUrl());
48 function showSections()
50 $pop = new PopularNoticeSection($this);
53 $notice_tag = new Notice_tag;
54 $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';
55 $notice_tag->query($query);
56 $this->elementStart('ol');
57 while ($notice_tag->fetch()) {
58 $this->elementStart('li');
59 $this->element('a', array('class' => 'attachment', 'href' => common_local_url('attachment', array('attachment' => $notice_tag->file_id))), "Attachment tagged {$notice_tag->c} times");
60 $this->elementEnd('li');
62 $this->elementEnd('ol');
67 if ($this->page == 1) {
68 return sprintf(_("Notices tagged with %s"), $this->tag);
70 return sprintf(_("Notices tagged with %s, page %d"),
76 function handle($args)
78 parent::handle($args);
85 return array(new Feed(Feed::RSS1,
86 common_local_url('tagrss', array('tag' => $this->tag)),
87 sprintf(_('Feed for tag %s'), $this->tag)));
91 * Output document relationship links
95 function showRelationshipLinks()
97 $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
98 $this->page, 'tag', array('tag' => $this->tag));
101 function showPageNotice()
103 return sprintf(_('Messages tagged "%s", most recent first'), $this->tag);
106 function showContent()
108 $notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
110 $nl = new NoticeList($notice, $this);
114 $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
115 $this->page, 'tag', array('tag' => $this->tag));
118 function isReadOnly($args)