]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/tag.php
fd29942a2dadf28756bd04dde515b8dd44b6460b
[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('LACONICA')) { exit(1); }
21
22 class TagAction extends Action
23 {
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             $this->serverError(_('No such page'),$code=404);
52         }
53
54         return true;
55     }
56
57     function showSections()
58     {
59         $pop = new PopularNoticeSection($this);
60         $pop->show();
61     }
62
63     function title()
64     {
65         if ($this->page == 1) {
66             return sprintf(_("Notices tagged with %s"), $this->tag);
67         } else {
68             return sprintf(_("Notices tagged with %s, page %d"),
69                            $this->tag,
70                            $this->page);
71         }
72     }
73
74     function handle($args)
75     {
76         parent::handle($args);
77
78         $this->showPage();
79     }
80
81     function getFeeds()
82     {
83         return array(new Feed(Feed::RSS1,
84                               common_local_url('tagrss',
85                                                array('tag' => $this->tag)),
86                               sprintf(_('Notice feed for tag %s (RSS 1.0)'),
87                                       $this->tag)),
88                      new Feed(Feed::RSS2,   
89                               common_local_url('api',
90                                                array('apiaction' => 'tags',
91                                                      'method' => 'timeline',
92                                                      'argument' => $this->tag.'.rss')),
93                               sprintf(_('Notice feed for %s group (RSS 2.0)'),
94                                       $this->tag)),
95                      new Feed(Feed::ATOM,
96                               common_local_url('api',
97                                                array('apiaction' => 'tags',
98                                                      'method' => 'timeline',
99                                                      'argument' => $this->tag.'.atom')),
100                               sprintf(_('Notice feed for tag %s (Atom)'),
101                                       $this->tag)));
102     }
103
104     function showContent()
105     {
106         $nl = new NoticeList($this->notice, $this);
107
108         $cnt = $nl->show();
109
110         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
111                           $this->page, 'tag', array('tag' => $this->tag));
112     }
113
114     function isReadOnly($args)
115     {
116         return true;
117     }
118 }