]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/public.php
A little further with notice lists
[quix0rs-gnu-social.git] / actions / public.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Action for displaying the public stream
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Public
23  * @package   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008-2009 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/publicgroupnav.php';
35 require_once INSTALLDIR.'/lib/noticelist.php';
36
37 /**
38  * Action for displaying the public stream
39  *
40  * @category Public
41  * @package  Laconica
42  * @author   Evan Prodromou <evan@controlyourself.ca>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://laconi.ca/
45  *
46  * @see      PublicrssAction
47  * @see      PublicxrdsAction
48  */
49
50 class PublicAction extends Action
51 {
52     /**
53      * page of the stream we're on; default = 1
54      */
55
56     var $page = null;
57
58     /**
59      * Read and validate arguments
60      *
61      * @param array $args URL parameters
62      *
63      * @return boolean success value
64      */
65
66     function prepare($args)
67     {
68         parent::prepare($args);
69         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
70         return true;
71     }
72
73     /**
74      * handle request
75      *
76      * Show the public stream, using recipe method showPage()
77      *
78      * @param array $args arguments, mostly unused
79      *
80      * @return void
81      */
82
83     function handle($args)
84     {
85         parent::handle($args);
86
87         header('X-XRDS-Location: '. common_local_url('publicxrds'));
88
89         $this->showPage();
90     }
91
92     /**
93      * Title of the page
94      *
95      * @return page title, including page number if over 1
96      */
97
98     function title()
99     {
100         if ($this->page > 1) {
101             return sprintf(_('Public timeline, page %d'), $this->page);
102         } else {
103             return _('Public timeline');
104         }
105     }
106
107     /**
108      * Output <head> elements for RSS and Atom feeds
109      *
110      * @return void
111      */
112
113     function showFeeds()
114     {
115         $this->element('link', array('rel' => 'alternate',
116                                      'href' => common_local_url('publicrss'),
117                                      'type' => 'application/rss+xml',
118                                      'title' => _('Public Stream Feed')));
119     }
120
121     /**
122      * Extra head elements
123      *
124      * We include a <meta> element linking to the publicxrds page, for OpenID
125      * client-side authentication.
126      *
127      * @return void
128      */
129
130     function extraHead()
131     {
132         // for client side of OpenID authentication
133         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
134                                      'content' => common_local_url('publicxrds')));
135     }
136
137     /**
138      * Show tabset for this page
139      *
140      * Uses the PublicGroupNav widget
141      *
142      * @return void
143      * @see PublicGroupNav
144      */
145
146     function showLocalNav()
147     {
148         $nav = new PublicGroupNav($this);
149         $nav->show();
150     }
151
152     /**
153      * Fill the content area
154      *
155      * Shows a list of the notices in the public stream, with some pagination
156      * controls.
157      *
158      * @return void
159      */
160
161     function showContent()
162     {
163         $notice = Notice::publicStream(($this->page-1)*NOTICES_PER_PAGE,
164                                        NOTICES_PER_PAGE + 1);
165
166         if (!$notice) {
167             $this->server_error(_('Could not retrieve public stream.'));
168             return;
169         }
170
171         $nl = new NoticeList($notice, $this);
172
173         $cnt = $nl->show();
174
175         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
176                           $this->page, 'public');
177     }
178
179     /**
180      * Makes a list of exported feeds for this page
181      *
182      * @return void
183      *
184      * @todo I18N
185      */
186
187     function showExportData()
188     {
189         $fl = new FeedList($this);
190         $fl->show(array(0 => array('href' => common_local_url('publicrss'),
191                                    'type' => 'rss',
192                                    'version' => 'RSS 1.0',
193                                    'item' => 'publicrss'),
194                         1 => array('href' => common_local_url('publicatom'),
195                                    'type' => 'atom',
196                                    'version' => 'Atom 1.0',
197                                    'item' => 'publicatom')));
198     }
199 }