]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/public.php
6ecdf2e50ab337bdcabd7364dbca35a09a2558d4
[quix0rs-gnu-social.git] / actions / public.php
1 <?php
2 /**
3  * StatusNet, 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   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !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 // Farther than any human will go
39
40 define('MAX_PUBLIC_PAGE', 100);
41
42 /**
43  * Action for displaying the public stream
44  *
45  * @category Public
46  * @package  StatusNet
47  * @author   Evan Prodromou <evan@status.net>
48  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49  * @link     http://status.net/
50  *
51  * @see      PublicrssAction
52  * @see      PublicxrdsAction
53  */
54 class PublicAction extends Action
55 {
56     /**
57      * page of the stream we're on; default = 1
58      */
59
60     var $page = null;
61     var $notice;
62     var $userProfile = null;
63
64     function isReadOnly($args)
65     {
66         return true;
67     }
68
69     /**
70      * Read and validate arguments
71      *
72      * @param array $args URL parameters
73      *
74      * @return boolean success value
75      */
76     function prepare($args)
77     {
78         parent::prepare($args);
79         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
80
81         if ($this->page > MAX_PUBLIC_PAGE) {
82             // TRANS: Client error displayed when requesting a public timeline page beyond the page limit.
83             // TRANS: %s is the page limit.
84             $this->clientError(sprintf(_('Beyond the page limit (%s).'), MAX_PUBLIC_PAGE));
85         }
86
87         common_set_returnto($this->selfUrl());
88
89         $this->userProfile = Profile::current();
90
91         $user = common_current_user();
92
93         if (!empty($user) && $user->streamModeOnly()) {
94             $stream = new PublicNoticeStream($this->userProfile);
95         } else {
96             $stream = new ThreadingPublicNoticeStream($this->userProfile);
97         }
98
99         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
100                                             NOTICES_PER_PAGE + 1);
101
102         if (!$this->notice) {
103             // TRANS: Server error displayed when a public timeline cannot be retrieved.
104             $this->serverError(_('Could not retrieve public timeline.'));
105         }
106
107         if($this->page > 1 && $this->notice->N == 0){
108             // TRANS: Server error when page not found (404).
109             $this->serverError(_('No such page.'),$code=404);
110         }
111
112         return true;
113     }
114
115     /**
116      * handle request
117      *
118      * Show the public stream, using recipe method showPage()
119      *
120      * @param array $args arguments, mostly unused
121      *
122      * @return void
123      */
124     function handle($args)
125     {
126         parent::handle($args);
127
128         $this->showPage();
129     }
130
131     /**
132      * Title of the page
133      *
134      * @return page title, including page number if over 1
135      */
136     function title()
137     {
138         if ($this->page > 1) {
139             // TRANS: Title for all public timeline pages but the first.
140             // TRANS: %d is the page number.
141             return sprintf(_('Public timeline, page %d'), $this->page);
142         } else {
143             // TRANS: Title for the first public timeline page.
144             return _('Public timeline');
145         }
146     }
147
148     function extraHead()
149     {
150         parent::extraHead();
151         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
152                                            'content' => common_local_url('publicxrds')));
153
154         $rsd = common_local_url('rsd');
155
156         // RSD, http://tales.phrasewise.com/rfc/rsd
157
158         $this->element('link', array('rel' => 'EditURI',
159                                      'type' => 'application/rsd+xml',
160                                      'href' => $rsd));
161
162         if ($this->page != 1) {
163             $this->element('link', array('rel' => 'canonical',
164                                          'href' => common_local_url('public')));
165         }
166     }
167
168     /**
169      * Output <head> elements for RSS and Atom feeds
170      *
171      * @return void
172      */
173     function getFeeds()
174     {
175         return array(new Feed(Feed::JSON,
176                               common_local_url('ApiTimelinePublic',
177                                                array('format' => 'as')),
178                               // TRANS: Link description for public timeline feed.
179                               _('Public Timeline Feed (Activity Streams JSON)')),
180                     new Feed(Feed::RSS1, common_local_url('publicrss'),
181                               // TRANS: Link description for public timeline feed.
182                               _('Public Timeline Feed (RSS 1.0)')),
183                      new Feed(Feed::RSS2,
184                               common_local_url('ApiTimelinePublic',
185                                                array('format' => 'rss')),
186                               // TRANS: Link description for public timeline feed.
187                               _('Public Timeline Feed (RSS 2.0)')),
188                      new Feed(Feed::ATOM,
189                               common_local_url('ApiTimelinePublic',
190                                                array('format' => 'atom')),
191                               // TRANS: Link description for public timeline feed.
192                               _('Public Timeline Feed (Atom)')));
193     }
194
195     function showEmptyList()
196     {
197         // TRANS: Text displayed for public feed when there are no public notices.
198         $message = _('This is the public timeline for %%site.name%% but no one has posted anything yet.') . ' ';
199
200         if (common_logged_in()) {
201             // TRANS: Additional text displayed for public feed when there are no public notices for a logged in user.
202             $message .= _('Be the first to post!');
203         }
204         else {
205             if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
206                 // TRANS: Additional text displayed for public feed when there are no public notices for a not logged in user.
207                 $message .= _('Why not [register an account](%%action.register%%) and be the first to post!');
208             }
209         }
210
211         $this->elementStart('div', 'guide');
212         $this->raw(common_markup_to_html($message));
213         $this->elementEnd('div');
214     }
215
216     /**
217      * Fill the content area
218      *
219      * Shows a list of the notices in the public stream, with some pagination
220      * controls.
221      *
222      * @return void
223      */
224     function showContent()
225     {
226         $user = common_current_user();
227
228         if (!empty($user) && $user->streamModeOnly()) {
229             $nl = new NoticeList($this->notice, $this);
230         } else {
231             $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
232         }
233
234         $cnt = $nl->show();
235
236         if ($cnt == 0) {
237             $this->showEmptyList();
238         }
239
240         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
241                           $this->page, 'public');
242     }
243
244     function showSections()
245     {
246         // Show invite button, as long as site isn't closed, and
247         // we have a logged in user.
248         if (common_config('invite', 'enabled') && !common_config('site', 'closed') && common_logged_in()) {
249             if (!common_config('site', 'private')) {
250                 $ibs = new InviteButtonSection(
251                     $this,
252                     // TRANS: Button text for inviting more users to the StatusNet instance.
253                     // TRANS: Less business/enterprise-oriented language for public sites.
254                     _m('BUTTON', 'Send invite')
255                 );
256             } else {
257                 $ibs = new InviteButtonSection($this);
258             }
259             $ibs->show();
260         }
261
262         $p = Profile::current();
263
264         $pop = new PopularNoticeSection($this, $p);
265         $pop->show();
266         if (!common_config('performance', 'high')) {
267             $cloud = new PublicTagCloudSection($this);
268             $cloud->show();
269         }
270         $feat = new FeaturedUsersSection($this);
271         $feat->show();
272     }
273
274     function showAnonymousMessage()
275     {
276         if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
277             // TRANS: Message for not logged in users at an invite-only site trying to view the public feed of notices.
278             // TRANS: This message contains Markdown links. Please mind the formatting.
279             $m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
280                    'based on the Free Software [StatusNet](http://status.net/) tool. ' .
281                    '[Join now](%%action.register%%) to share notices about yourself with friends, family, and colleagues! ' .
282                    '([Read more](%%doc.help%%))');
283         } else {
284             // TRANS: Message for not logged in users at a closed site trying to view the public feed of notices.
285             // TRANS: This message contains Markdown links. Please mind the formatting.
286             $m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
287                    'based on the Free Software [StatusNet](http://status.net/) tool.');
288         }
289         $this->elementStart('div', array('id' => 'anon_notice'));
290         $this->raw(common_markup_to_html($m));
291         $this->elementEnd('div');
292     }
293 }
294
295 class ThreadingPublicNoticeStream extends ThreadingNoticeStream
296 {
297     function __construct($profile)
298     {
299         parent::__construct(new PublicNoticeStream($profile));
300     }
301 }