]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/tag.php
Cosmetic changes to common_redirect, clientError, serverError
[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     var $tag;
27     var $page;
28
29     function prepare($args)
30     {
31         parent::prepare($args);
32         $taginput = $this->trimmed('tag');
33         $this->tag = common_canonical_tag($taginput);
34
35         if (!$this->tag) {
36             common_redirect(common_local_url('publictagcloud'), 301);
37         }
38
39         if ($this->tag != $taginput) {
40             common_redirect(common_local_url('tag', array('tag' => $this->tag)), 301);
41         }
42
43         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
44
45         common_set_returnto($this->selfUrl());
46
47         $this->notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
48
49         if($this->page > 1 && $this->notice->N == 0){
50             // TRANS: Server error when page not found (404).
51             $this->serverError(_('No such page.'),$code=404);
52         }
53
54         return true;
55     }
56
57     function title()
58     {
59         if ($this->page == 1) {
60             // TRANS: Title for first page of notices with tags.
61             // TRANS: %s is the tag.
62             return sprintf(_('Notices tagged with %s'), $this->tag);
63         } else {
64             // TRANS: Title for all but the first page of notices with tags.
65             // TRANS: %1$s is the tag, %2$d is the page number.
66             return sprintf(_('Notices tagged with %1$s, page %2$d'),
67                            $this->tag,
68                            $this->page);
69         }
70     }
71
72     function handle($args)
73     {
74         parent::handle($args);
75
76         $this->showPage();
77     }
78
79     function getFeeds()
80     {
81         return array(new Feed(Feed::JSON,
82                               common_local_url('ApiTimelineTag',
83                                                array('format' => 'as',
84                                                      '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 (Activity Streams JSON)'),
88                                       $this->tag)),
89                      new Feed(Feed::RSS1,
90                               common_local_url('tagrss',
91                                                array('tag' => $this->tag)),
92                               // TRANS: Link label for feed on "notices with tag" page.
93                               // TRANS: %s is the tag the feed is for.
94                               sprintf(_('Notice feed for tag %s (RSS 1.0)'),
95                                       $this->tag)),
96                      new Feed(Feed::RSS2,
97                               common_local_url('ApiTimelineTag',
98                                                array('format' => 'rss',
99                                                      'tag' => $this->tag)),
100                               // TRANS: Link label for feed on "notices with tag" page.
101                               // TRANS: %s is the tag the feed is for.
102                               sprintf(_('Notice feed for tag %s (RSS 2.0)'),
103                                       $this->tag)),
104                      new Feed(Feed::ATOM,
105                               common_local_url('ApiTimelineTag',
106                                                array('format' => 'atom',
107                                                      'tag' => $this->tag)),
108                               // TRANS: Link label for feed on "notices with tag" page.
109                               // TRANS: %s is the tag the feed is for.
110                               sprintf(_('Notice feed for tag %s (Atom)'),
111                                       $this->tag)));
112     }
113
114     function showContent()
115     {
116         if(Event::handle('StartTagShowContent', array($this))) {
117
118             $nl = new NoticeList($this->notice, $this);
119
120             $cnt = $nl->show();
121
122             $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
123                               $this->page, 'tag', array('tag' => $this->tag));
124
125             Event::handle('EndTagShowContent', array($this));
126         }
127     }
128
129     function isReadOnly($args)
130     {
131         return true;
132     }
133 }