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