]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/public.php
Add groups by notice to public
[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 require_once INSTALLDIR.'/lib/feedlist.php';
37
38 /**
39  * Action for displaying the public stream
40  *
41  * @category Public
42  * @package  Laconica
43  * @author   Evan Prodromou <evan@controlyourself.ca>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://laconi.ca/
46  *
47  * @see      PublicrssAction
48  * @see      PublicxrdsAction
49  */
50
51 class PublicAction extends Action
52 {
53     /**
54      * page of the stream we're on; default = 1
55      */
56
57     var $page = null;
58
59     /**
60      * Read and validate arguments
61      *
62      * @param array $args URL parameters
63      *
64      * @return boolean success value
65      */
66
67     function prepare($args)
68     {
69         parent::prepare($args);
70         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
71         return true;
72     }
73
74     /**
75      * handle request
76      *
77      * Show the public stream, using recipe method showPage()
78      *
79      * @param array $args arguments, mostly unused
80      *
81      * @return void
82      */
83
84     function handle($args)
85     {
86         parent::handle($args);
87
88         header('X-XRDS-Location: '. common_local_url('publicxrds'));
89
90         $this->showPage();
91     }
92
93     /**
94      * Title of the page
95      *
96      * @return page title, including page number if over 1
97      */
98
99     function title()
100     {
101         if ($this->page > 1) {
102             return sprintf(_('Public timeline, page %d'), $this->page);
103         } else {
104             return _('Public timeline');
105         }
106     }
107
108     /**
109      * Output <head> elements for RSS and Atom feeds
110      *
111      * @return void
112      */
113
114     function showFeeds()
115     {
116         $this->element('link', array('rel' => 'alternate',
117                                      'href' => common_local_url('publicrss'),
118                                      'type' => 'application/rss+xml',
119                                      'title' => _('Public Stream Feed')));
120     }
121
122     /**
123      * Extra head elements
124      *
125      * We include a <meta> element linking to the publicxrds page, for OpenID
126      * client-side authentication.
127      *
128      * @return void
129      */
130
131     function extraHead()
132     {
133         // for client side of OpenID authentication
134         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
135                                      'content' => common_local_url('publicxrds')));
136     }
137
138     /**
139      * Show tabset for this page
140      *
141      * Uses the PublicGroupNav widget
142      *
143      * @return void
144      * @see PublicGroupNav
145      */
146
147     function showLocalNav()
148     {
149         $nav = new PublicGroupNav($this);
150         $nav->show();
151     }
152
153     /**
154      * Fill the content area
155      *
156      * Shows a list of the notices in the public stream, with some pagination
157      * controls.
158      *
159      * @return void
160      */
161
162     function showContent()
163     {
164         $notice = Notice::publicStream(($this->page-1)*NOTICES_PER_PAGE,
165                                        NOTICES_PER_PAGE + 1);
166
167         if (!$notice) {
168             $this->serverError(_('Could not retrieve public stream.'));
169             return;
170         }
171
172         $nl = new NoticeList($notice, $this);
173
174         $cnt = $nl->show();
175
176         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
177                           $this->page, 'public');
178     }
179
180     /**
181      * Makes a list of exported feeds for this page
182      *
183      * @return void
184      *
185      * @todo I18N
186      */
187
188     function showExportData()
189     {
190         $fl = new FeedList($this);
191         $fl->show(array(0 => array('href' => common_local_url('publicrss'),
192                                    'type' => 'rss',
193                                    'version' => 'RSS 1.0',
194                                    'item' => 'publicrss'),
195                         1 => array('href' => common_local_url('publicatom'),
196                                    'type' => 'atom',
197                                    'version' => 'Atom 1.0',
198                                    'item' => 'publicatom')));
199     }
200
201     function showSections()
202     {
203         $top = new TopPostersSection($this);
204         $top->show();
205         $pop = new PopularNoticeSection($this);
206         $pop->show();
207         $gbp = new GroupsByPostsSection($this);
208         $gbp->show();
209     }
210 }