]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/tag.php
Merge branch 'dev-0.7.x' into link-rel-paginate
[quix0rs-gnu-social.git] / actions / tag.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, 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     function prepare($args)
25     {
26         parent::prepare($args);
27         $taginput = $this->trimmed('tag');
28         $this->tag = common_canonical_tag($taginput);
29
30         if (!$this->tag) {
31             common_redirect(common_local_url('publictagcloud'), 301);
32             return false;
33         }
34
35         if ($this->tag != $taginput) {
36             common_redirect(common_local_url('tag', array('tag' => $this->tag)));
37         }
38
39         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
40         
41         common_set_returnto($this->selfUrl());
42         
43         return true;
44     }
45
46     function title()
47     {
48         if ($this->page == 1) {
49             return sprintf(_("Notices tagged with %s"), $this->tag);
50         } else {
51             return sprintf(_("Notices tagged with %s, page %d"),
52                            $this->tag,
53                            $this->page);
54         }
55     }
56
57     function handle($args)
58     {
59         parent::handle($args);
60
61         $this->showPage();
62     }
63
64     function showFeeds()
65     {
66         $this->element('link', array('rel' => 'alternate',
67                                      'href' => common_local_url('tagrss', array('tag' => $this->tag)),
68                                      'type' => 'application/rss+xml',
69                                      'title' => sprintf(_('Feed for tag %s'), $this->tag)));
70     }
71
72     /**
73      * Output document relationship links
74      *
75      * @return void
76      */
77     function showRelationshipLinks()
78     {
79         // Machine-readable pagination
80         if ($this->page > 1) {
81             $this->element('link', array('rel' => 'next',
82                                          'href' => common_local_url('tag',
83                                                                     array('tag' => $this->tag,
84                                                                           'page' => $this->page - 1)),
85                                          'title' => _('Next Notices')));
86         }
87         $this->element('link', array('rel' => 'prev',
88                                      'href' => common_local_url('tag',
89                                                                 array('tag' => $this->tag,
90                                                                       'page' => $this->page + 1)),
91                                      'title' => _('Previous Notices')));
92     }
93
94     function showPageNotice()
95     {
96         return sprintf(_('Messages tagged "%s", most recent first'), $this->tag);
97     }
98
99     function showExportData()
100     {
101         $fl = new FeedList($this);
102         $fl->show(array(0=>array('href'=>common_local_url('tagrss', array('tag' => $this->tag)),
103                                  'type' => 'rss',
104                                  'version' => 'RSS 1.0',
105                                  'item' => 'tagrss')));
106     }
107
108     function showContent()
109     {
110         $notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
111
112         $nl = new NoticeList($notice, $this);
113
114         $cnt = $nl->show();
115
116         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
117                           $this->page, 'tag', array('tag' => $this->tag));
118     }
119 }