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