]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/tag.php
Merge commit 'refs/merge-requests/30' of https://gitorious.org/social/mainline into...
[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('GNUSOCIAL')) { exit(1); }
21
22 // @todo FIXME: documentation missing.
23 class TagAction extends ManagedAction
24 {
25     var $notice;
26     var $tag;
27     var $page;
28
29     protected function prepare(array $args=array())
30     {
31         parent::prepare($args);
32
33         $taginput = $this->trimmed('tag');
34         $this->tag = common_canonical_tag($taginput);
35
36         if (empty($this->tag)) {
37             common_redirect(common_local_url('publictagcloud'), 301);
38         }
39
40         // after common_canonical_tag we have a lowercase, no-specials tag string
41         if ($this->tag !== $taginput) {
42             common_redirect(common_local_url('tag', array('tag' => $this->tag)), 301);
43         }
44
45         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
46
47         common_set_returnto($this->selfUrl());
48
49         $this->notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
50
51         if($this->page > 1 && $this->notice->N == 0){
52             // TRANS: Client error when page not found (404).
53             $this->clientError(_('No such page.'), 404);
54         }
55
56         return true;
57     }
58
59     function title()
60     {
61         if ($this->page == 1) {
62             // TRANS: Title for first page of notices with tags.
63             // TRANS: %s is the tag.
64             return sprintf(_('Notices tagged with %s'), $this->tag);
65         } else {
66             // TRANS: Title for all but the first page of notices with tags.
67             // TRANS: %1$s is the tag, %2$d is the page number.
68             return sprintf(_('Notices tagged with %1$s, page %2$d'),
69                            $this->tag,
70                            $this->page);
71         }
72     }
73
74     function getFeeds()
75     {
76         return array(new Feed(Feed::JSON,
77                               common_local_url('ApiTimelineTag',
78                                                array('format' => 'as',
79                                                      'tag' => $this->tag)),
80                               // TRANS: Link label for feed on "notices with tag" page.
81                               // TRANS: %s is the tag the feed is for.
82                               sprintf(_('Notice feed for tag %s (Activity Streams JSON)'),
83                                       $this->tag)),
84                      new Feed(Feed::RSS1,
85                               common_local_url('tagrss',
86                                                array('tag' => $this->tag)),
87                               // TRANS: Link label for feed on "notices with tag" page.
88                               // TRANS: %s is the tag the feed is for.
89                               sprintf(_('Notice feed for tag %s (RSS 1.0)'),
90                                       $this->tag)),
91                      new Feed(Feed::RSS2,
92                               common_local_url('ApiTimelineTag',
93                                                array('format' => 'rss',
94                                                      '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 2.0)'),
98                                       $this->tag)),
99                      new Feed(Feed::ATOM,
100                               common_local_url('ApiTimelineTag',
101                                                array('format' => 'atom',
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 (Atom)'),
106                                       $this->tag)));
107     }
108
109     protected function showContent()
110     {
111         if(Event::handle('StartTagShowContent', array($this))) {
112
113             $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
114
115             $cnt = $nl->show();
116
117             $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
118                               $this->page, 'tag', array('tag' => $this->tag));
119
120             Event::handle('EndTagShowContent', array($this));
121         }
122     }
123
124     function isReadOnly($args)
125     {
126         return true;
127     }
128 }