]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/tag.php
merge 0.9.x into 1.0.x
[quix0rs-gnu-social.git] / actions / tag.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
21
22 // @todo FIXME: documentation missing.
23 class TagAction extends Action
24 {
25     var $notice;
26
27     function prepare($args)
28     {
29         parent::prepare($args);
30         $taginput = $this->trimmed('tag');
31         $this->tag = common_canonical_tag($taginput);
32
33         if (!$this->tag) {
34             common_redirect(common_local_url('publictagcloud'), 301);
35             return false;
36         }
37
38         if ($this->tag != $taginput) {
39             common_redirect(common_local_url('tag', array('tag' => $this->tag)),
40                             301);
41             return false;
42         }
43
44         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
45
46         common_set_returnto($this->selfUrl());
47
48         $this->notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
49
50         if($this->page > 1 && $this->notice->N == 0){
51             // TRANS: Server error when page not found (404).
52             $this->serverError(_('No such page.'),$code=404);
53         }
54
55         return true;
56     }
57
58     function title()
59     {
60         if ($this->page == 1) {
61             // TRANS: Title for first page of notices with tags.
62             // TRANS: %s is the tag.
63             return sprintf(_('Notices tagged with %s'), $this->tag);
64         } else {
65             // TRANS: Title for all but the first page of notices with tags.
66             // TRANS: %1$s is the tag, %2$d is the page number.
67             return sprintf(_('Notices tagged with %1$s, page %2$d'),
68                            $this->tag,
69                            $this->page);
70         }
71     }
72
73     function handle($args)
74     {
75         parent::handle($args);
76
77         $this->showPage();
78     }
79
80     function getFeeds()
81     {
82         return array(new Feed(Feed::RSS1,
83                               common_local_url('tagrss',
84                                                array('tag' => $this->tag)),
85                               // TRANS: Link label for feed on "notices with tag" page.
86                               // TRANS: %s is the tag the feed is for.
87                               sprintf(_('Notice feed for tag %s (RSS 1.0)'),
88                                       $this->tag)),
89                      new Feed(Feed::RSS2,
90                               common_local_url('ApiTimelineTag',
91                                                array('format' => 'rss',
92                                                      'tag' => $this->tag)),
93                               // TRANS: Link label for feed on "notices with tag" page.
94                               // TRANS: %s is the tag the feed is for.
95                               sprintf(_('Notice feed for tag %s (RSS 2.0)'),
96                                       $this->tag)),
97                      new Feed(Feed::ATOM,
98                               common_local_url('ApiTimelineTag',
99                                                array('format' => 'atom',
100                                                      'tag' => $this->tag)),
101                               // TRANS: Link label for feed on "notices with tag" page.
102                               // TRANS: %s is the tag the feed is for.
103                               sprintf(_('Notice feed for tag %s (Atom)'),
104                                       $this->tag)));
105     }
106
107     function showContent()
108     {
109         if(Event::handle('StartTagShowContent', array($this))) {
110
111             $nl = new NoticeList($this->notice, $this);
112
113             $cnt = $nl->show();
114
115             $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
116                               $this->page, 'tag', array('tag' => $this->tag));
117
118             Event::handle('EndTagShowContent', array($this));
119         }
120     }
121
122     function isReadOnly($args)
123     {
124         return true;
125     }
126 }