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