]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/sitestreamaction.php
Type-hint is array here.
[quix0rs-gnu-social.git] / lib / sitestreamaction.php
1 <?php
2
3 if (!defined('GNUSOCIAL')) { exit(1); }
4
5 // Farther than any human will go
6
7 define('MAX_PUBLIC_PAGE', 100);
8
9 class SitestreamAction extends ManagedAction
10 {
11     /**
12      * page of the stream we're on; default = 1
13      */
14
15     var $page = null;
16     var $notice;
17
18     protected $stream = null;
19
20     function isReadOnly($args)
21     {
22         return true;
23     }
24
25     protected function doPreparation()
26     {
27         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
28
29         if ($this->page > MAX_PUBLIC_PAGE) {
30             // TRANS: Client error displayed when requesting a public timeline page beyond the page limit.
31             // TRANS: %s is the page limit.
32             $this->clientError(sprintf(_('Beyond the page limit (%s).'), MAX_PUBLIC_PAGE));
33         }
34
35         common_set_returnto($this->selfUrl());
36
37         $this->streamPrepare();
38
39         $this->notice = $this->stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
40                                             NOTICES_PER_PAGE + 1);
41
42         if (!$this->notice) {
43             // TRANS: Server error displayed when a public timeline cannot be retrieved.
44             $this->serverError(_('Could not retrieve public timeline.'));
45         }
46
47         if ($this->page > 1 && $this->notice->N == 0){
48             // TRANS: Client error when page not found (404).
49             $this->clientError(_('No such page.'), 404);
50         }
51
52         return true;
53     }
54
55     /**
56      * Title of the page
57      *
58      * @return page title, including page number if over 1
59      */
60     function title()
61     {
62         if ($this->page > 1) {
63             // TRANS: Title for all public timeline pages but the first.
64             // TRANS: %d is the page number.
65             return sprintf(_('Public timeline, page %d'), $this->page);
66         } else {
67             // TRANS: Title for the first public timeline page.
68             return _('Public timeline');
69         }
70     }
71
72     function extraHead()
73     {
74         parent::extraHead();
75         $rsd = common_local_url('rsd');
76
77         // RSD, http://tales.phrasewise.com/rfc/rsd
78
79         $this->element('link', array('rel' => 'EditURI',
80                                      'type' => 'application/rsd+xml',
81                                      'href' => $rsd));
82
83         if ($this->page != 1) {
84             $this->element('link', array('rel' => 'canonical',
85                                          'href' => common_local_url('public')));
86         }
87     }
88
89     /**
90      * Output <head> elements for RSS and Atom feeds
91      *
92      * @return void
93      */
94     function getFeeds()
95     {
96         return array(new Feed(Feed::JSON,
97                               common_local_url('ApiTimelinePublic',
98                                                array('format' => 'as')),
99                               // TRANS: Link description for public timeline feed.
100                               _('Public Timeline Feed (Activity Streams JSON)')),
101                     new Feed(Feed::RSS1, common_local_url('publicrss'),
102                               // TRANS: Link description for public timeline feed.
103                               _('Public Timeline Feed (RSS 1.0)')),
104                      new Feed(Feed::RSS2,
105                               common_local_url('ApiTimelinePublic',
106                                                array('format' => 'rss')),
107                               // TRANS: Link description for public timeline feed.
108                               _('Public Timeline Feed (RSS 2.0)')),
109                      new Feed(Feed::ATOM,
110                               common_local_url('ApiTimelinePublic',
111                                                array('format' => 'atom')),
112                               // TRANS: Link description for public timeline feed.
113                               _('Public Timeline Feed (Atom)')));
114     }
115
116     function showEmptyList()
117     {
118         // TRANS: Text displayed for public feed when there are no public notices.
119         $message = _('This is the public timeline for %%site.name%% but no one has posted anything yet.') . ' ';
120
121         if (common_logged_in()) {
122             // TRANS: Additional text displayed for public feed when there are no public notices for a logged in user.
123             $message .= _('Be the first to post!');
124         }
125         else {
126             if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
127                 // TRANS: Additional text displayed for public feed when there are no public notices for a not logged in user.
128                 $message .= _('Why not [register an account](%%action.register%%) and be the first to post!');
129             }
130         }
131
132         $this->elementStart('div', 'guide');
133         $this->raw(common_markup_to_html($message));
134         $this->elementEnd('div');
135     }
136
137     /**
138      * Fill the content area
139      *
140      * Shows a list of the notices in the public stream, with some pagination
141      * controls.
142      *
143      * @return void
144      */
145     function showContent()
146     {
147         if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
148             $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
149         } else {
150             $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped);
151         }
152
153         $cnt = $nl->show();
154
155         if ($cnt == 0) {
156             $this->showEmptyList();
157         }
158
159         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
160                           $this->page, $this->action);
161     }
162
163     function showAnonymousMessage()
164     {
165         if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
166             // TRANS: Message for not logged in users at an invite-only site trying to view the public feed of notices.
167             // TRANS: This message contains Markdown links. Please mind the formatting.
168             $m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
169                    'based on the Free Software [StatusNet](http://status.net/) tool. ' .
170                    '[Join now](%%action.register%%) to share notices about yourself with friends, family, and colleagues! ' .
171                    '([Read more](%%doc.help%%))');
172         } else {
173             // TRANS: Message for not logged in users at a closed site trying to view the public feed of notices.
174             // TRANS: This message contains Markdown links. Please mind the formatting.
175             $m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
176                    'based on the Free Software [StatusNet](http://status.net/) tool.');
177         }
178         $this->elementStart('div', array('id' => 'anon_notice'));
179         $this->raw(common_markup_to_html($m));
180         $this->elementEnd('div');
181     }
182 }