]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Added more checked type-hints.
[quix0rs-gnu-social.git] / actions / showstream.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * User profile page
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  Personal
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008-2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/personalgroupnav.php';
36 require_once INSTALLDIR.'/lib/noticelist.php';
37 require_once INSTALLDIR.'/lib/profileminilist.php';
38 require_once INSTALLDIR.'/lib/groupminilist.php';
39 require_once INSTALLDIR.'/lib/feedlist.php';
40
41 /**
42  * User profile page
43  *
44  * When I created this page, "show stream" seemed like the best name for it.
45  * Now, it seems like a really bad name.
46  *
47  * It shows a stream of the user's posts, plus lots of profile info, links
48  * to subscriptions and stuff, etc.
49  *
50  * @category Personal
51  * @package  StatusNet
52  * @author   Evan Prodromou <evan@status.net>
53  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
54  * @link     http://status.net/
55  */
56 class ShowstreamAction extends ProfileAction
57 {
58     var $notice;
59
60     protected function prepare(array $args=array())
61     {
62         parent::prepare($args);
63
64         if (empty($this->tag)) {
65             $stream = new ProfileNoticeStream($this->profile, $this->scoped);
66         } else {
67             $stream = new TaggedProfileNoticeStream($this->profile, $this->tag, $this->scoped);
68         }
69
70         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
71
72         return true;
73     }
74
75
76     function title()
77     {
78         $base = $this->profile->getFancyName();
79         if (!empty($this->tag)) {
80             if ($this->page == 1) {
81                 // TRANS: Page title showing tagged notices in one user's timeline.
82                 // TRANS: %1$s is the username, %2$s is the hash tag.
83                 return sprintf(_('Notices by %1$s tagged %2$s'), $base, $this->tag);
84             } else {
85                 // TRANS: Page title showing tagged notices in one user's timeline.
86                 // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
87                 return sprintf(_('Notices by %1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
88             }
89         } else {
90             if ($this->page == 1) {
91                 return $base;
92             } else {
93                 // TRANS: Extended page title showing tagged notices in one user's timeline.
94                 // TRANS: %1$s is the username, %2$d is the page number.
95                 return sprintf(_('Notices by %1$s, page %2$d'),
96                                $base,
97                                $this->page);
98             }
99         }
100     }
101
102     function showContent()
103     {
104         $this->showNotices();
105     }
106
107     function showProfileBlock()
108     {
109         $block = new AccountProfileBlock($this, $this->profile);
110         $block->show();
111     }
112
113     function showPageNoticeBlock()
114     {
115         return;
116     }
117
118     function getFeeds()
119     {
120         if (!empty($this->tag)) {
121             return array(new Feed(Feed::RSS1,
122                                   common_local_url('userrss',
123                                                    array('nickname' => $this->target->nickname,
124                                                          'tag' => $this->tag)),
125                                   // TRANS: Title for link to notice feed.
126                                   // TRANS: %1$s is a user nickname, %2$s is a hashtag.
127                                   sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
128                                           $this->target->nickname, $this->tag)));
129         }
130
131         return array(new Feed(Feed::JSON,
132                               common_local_url('ApiTimelineUser',
133                                                array(
134                                                     'id' => $this->user->id,
135                                                     'format' => 'as')),
136                               // TRANS: Title for link to notice feed.
137                               // TRANS: %s is a user nickname.
138                               sprintf(_('Notice feed for %s (Activity Streams JSON)'),
139                                       $this->target->nickname)),
140                      new Feed(Feed::RSS1,
141                               common_local_url('userrss',
142                                                array('nickname' => $this->target->nickname)),
143                               // TRANS: Title for link to notice feed.
144                               // TRANS: %s is a user nickname.
145                               sprintf(_('Notice feed for %s (RSS 1.0)'),
146                                       $this->target->nickname)),
147                      new Feed(Feed::RSS2,
148                               common_local_url('ApiTimelineUser',
149                                                array(
150                                                     'id' => $this->user->id,
151                                                     'format' => 'rss')),
152                               // TRANS: Title for link to notice feed.
153                               // TRANS: %s is a user nickname.
154                               sprintf(_('Notice feed for %s (RSS 2.0)'),
155                                       $this->target->nickname)),
156                      new Feed(Feed::ATOM,
157                               common_local_url('ApiTimelineUser',
158                                                array(
159                                                     'id' => $this->user->id,
160                                                     'format' => 'atom')),
161                               // TRANS: Title for link to notice feed.
162                               // TRANS: %s is a user nickname.
163                               sprintf(_('Notice feed for %s (Atom)'),
164                                       $this->target->nickname)),
165                      new Feed(Feed::FOAF,
166                               common_local_url('foaf', array('nickname' =>
167                                                              $this->target->nickname)),
168                               // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
169                               // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
170                               sprintf(_('FOAF for %s'), $this->target->nickname)));
171     }
172
173     function extraHead()
174     {
175         if ($this->profile->bio) {
176             $this->element('meta', array('name' => 'description',
177                                          'content' => $this->profile->bio));
178         }
179
180         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
181             $id = new Microid('mailto:'.$this->user->email,
182                               $this->selfUrl());
183             $this->element('meta', array('name' => 'microid',
184                                          'content' => $id->toString()));
185         }
186
187         // See https://wiki.mozilla.org/Microsummaries
188
189         $this->element('link', array('rel' => 'microsummary',
190                                      'href' => common_local_url('microsummary',
191                                                                 array('nickname' => $this->profile->nickname))));
192
193         $rsd = common_local_url('rsd',
194                                 array('nickname' => $this->profile->nickname));
195
196         // RSD, http://tales.phrasewise.com/rfc/rsd
197         $this->element('link', array('rel' => 'EditURI',
198                                      'type' => 'application/rsd+xml',
199                                      'href' => $rsd));
200
201         if ($this->page != 1) {
202             $this->element('link', array('rel' => 'canonical',
203                                          'href' => $this->profile->profileurl));
204         }
205     }
206
207     function showEmptyListMessage()
208     {
209         // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
210         $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->nickname) . ' ';
211
212         if (common_logged_in()) {
213             $current_user = common_current_user();
214             if ($this->user->id === $current_user->id) {
215                 // TRANS: Second sentence of empty list message for a stream for the user themselves.
216                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
217             } else {
218                 // TRANS: Second sentence of empty  list message for a non-self timeline. %1$s is a user nickname, %2$s is a part of a URL.
219                 // TRANS: This message contains a Markdown link. Keep "](" together.
220                 $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->target->nickname, '@' . $this->target->nickname);
221             }
222         }
223         else {
224             // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
225             // TRANS: This message contains a Markdown link. Keep "](" together.
226             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->nickname);
227         }
228
229         $this->elementStart('div', 'guide');
230         $this->raw(common_markup_to_html($message));
231         $this->elementEnd('div');
232     }
233
234     function showNotices()
235     {
236         $pnl = null;
237         if (Event::handle('ShowStreamNoticeList', array($this->notice, $this, &$pnl))) {
238             $pnl = new ProfileNoticeList($this->notice, $this);
239         }
240         $cnt = $pnl->show();
241         if (0 == $cnt) {
242             $this->showEmptyListMessage();
243         }
244
245         $args = array('nickname' => $this->target->nickname);
246         if (!empty($this->tag))
247         {
248             $args['tag'] = $this->tag;
249         }
250         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
251                           'showstream', $args);
252     }
253
254     function showAnonymousMessage()
255     {
256         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
257             // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
258             // TRANS: This message contains a Markdown link. Keep "](" together.
259             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
260                            'based on the Free Software [StatusNet](http://status.net/) tool. ' .
261                            '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
262                          $this->target->nickname, $this->target->nickname);
263         } else {
264             // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
265             // TRANS: This message contains a Markdown link. Keep "](" together.
266             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
267                            'based on the Free Software [StatusNet](http://status.net/) tool.'),
268                          $this->target->nickname, $this->target->nickname);
269         }
270         $this->elementStart('div', array('id' => 'anon_notice'));
271         $this->raw(common_markup_to_html($m));
272         $this->elementEnd('div');
273     }
274
275     function showSections()
276     {
277         parent::showSections();
278         if (!common_config('performance', 'high')) {
279             $cloud = new PersonalTagCloudSection($this, $this->user);
280             $cloud->show();
281         }
282     }
283
284     function noticeFormOptions()
285     {
286         $options = parent::noticeFormOptions();
287         $cur = common_current_user();
288
289         if (empty($cur) || $cur->id != $this->profile->id) {
290             $options['to_profile'] =  $this->profile;
291         }
292
293         return $options;
294     }
295 }
296
297 // We don't show the author for a profile, since we already know who it is!
298
299 /**
300  * Slightly modified from standard list; the author & avatar are hidden
301  * in CSS. We used to remove them here too, but as it turns out that
302  * confuses the inline reply code... and we hide them in CSS anyway
303  * since realtime updates come through in original form.
304  *
305  * Remaining customization right now is for the repeat marker, where
306  * it'll list who the original poster was instead of who did the repeat
307  * (since the repeater is you, and the repeatee isn't shown!)
308  * This will remain inconsistent if realtime updates come through,
309  * since those'll get rendered as a regular NoticeListItem.
310  */
311 class ProfileNoticeList extends NoticeList
312 {
313     function newListItem(Notice $notice)
314     {
315         return new ProfileNoticeListItem($notice, $this->out);
316     }
317 }
318
319 class ProfileNoticeListItem extends DoFollowListItem
320 {
321     /**
322      * show a link to the author of repeat
323      *
324      * @return void
325      */
326     function showRepeat()
327     {
328         if (!empty($this->repeat)) {
329
330             // FIXME: this code is almost identical to default; need to refactor
331
332             $attrs = array('href' => $this->profile->profileurl,
333                            'class' => 'url');
334
335             if (!empty($this->profile->fullname)) {
336                 $attrs['title'] = $this->profile->getFancyName();
337             }
338
339             $this->out->elementStart('span', 'repeat');
340
341             $text_link = XMLStringer::estring('a', $attrs, $this->profile->nickname);
342
343             // TRANS: Link to the author of a repeated notice. %s is a linked nickname.
344             $this->out->raw(sprintf(_('Repeat of %s'), $text_link));
345
346             $this->out->elementEnd('span');
347         }
348     }
349 }