]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Trac #894 and #1013 - fixed bad redirects after delete notice
[quix0rs-gnu-social.git] / actions / showstream.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @author    Sarven Capadisli <csarven@controlyourself.ca>
26  * @copyright 2008-2009 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!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  Laconica
52  * @author   Evan Prodromou <evan@controlyourself.ca>
53  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
54  * @link     http://laconi.ca/
55  */
56
57 class ShowstreamAction extends Action
58 {
59     var $user = null;
60     var $page = null;
61     var $profile = null;
62
63     function isReadOnly()
64     {
65         return true;
66     }
67
68     function title()
69     {
70         if ($this->page == 1) {
71             return $this->user->nickname;
72         } else {
73             return sprintf(_("%s, page %d"),
74                            $this->user->nickname,
75                            $this->page);
76         }
77     }
78
79     function prepare($args)
80     {
81         parent::prepare($args);
82
83         $nickname_arg = $this->arg('nickname');
84         $nickname = common_canonical_nickname($nickname_arg);
85
86         // Permanent redirect on non-canonical nickname
87
88         if ($nickname_arg != $nickname) {
89             $args = array('nickname' => $nickname);
90             if ($this->arg('page') && $this->arg('page') != 1) {
91                 $args['page'] = $this->arg['page'];
92             }
93             common_redirect(common_local_url('showstream', $args), 301);
94             return false;
95         }
96
97         $this->user = User::staticGet('nickname', $nickname);
98
99         if (!$this->user) {
100             $this->clientError(_('No such user.'), 404);
101             return false;
102         }
103
104         $this->profile = $this->user->getProfile();
105
106         if (!$this->profile) {
107             $this->serverError(_('User has no profile.'));
108             return false;
109         }
110
111         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
112
113         common_set_returnto($this->selfUrl());
114         
115         return true;
116     }
117
118     function handle($args)
119     {
120
121         // Looks like we're good; start output
122
123         // For YADIS discovery, we also have a <meta> tag
124
125         header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
126                                                                    $this->user->nickname)));
127
128         $this->showPage();
129     }
130
131     function showContent()
132     {
133         $this->showProfile();
134         $this->showNotices();
135     }
136
137     function showLocalNav()
138     {
139         $nav = new PersonalGroupNav($this);
140         $nav->show();
141     }
142
143     function showPageTitle()
144     {
145         $user =& common_current_user();
146         if ($user && ($user->id == $this->profile->id)) {
147             $this->element('h1', NULL, _("Your profile"));
148         } else {
149             $this->element('h1', NULL, sprintf(_('%s\'s profile'), $this->profile->nickname));
150         }
151     }
152
153     function showPageNoticeBlock()
154     {
155         return;
156     }
157
158     function showExportData()
159     {
160         $fl = new FeedList($this);
161         $fl->show(array(0=>array('href'=>common_local_url('userrss',
162                                                           array('nickname' => $this->user->nickname)),
163                                  'type' => 'rss',
164                                  'version' => 'RSS 1.0',
165                                  'item' => 'notices'),
166                         1=>array('href'=>common_local_url('usertimeline',
167                                                           array('nickname' => $this->user->nickname)),
168                                  'type' => 'atom',
169                                  'version' => 'Atom 1.0',
170                                  'item' => 'usertimeline'),
171                         2=>array('href'=>common_local_url('foaf',
172                                                           array('nickname' => $this->user->nickname)),
173                                  'type' => 'rdf',
174                                  'version' => 'FOAF',
175                                  'item' => 'foaf')));
176     }
177
178     function showFeeds()
179     {
180         $this->element('link', array('rel' => 'alternate',
181                         'type' => 'application/rss+xml',
182                         'href' => common_local_url('userrss',
183                          array('nickname' => $this->user->nickname)),
184                                'title' => sprintf(_('Notice feed for %s (RSS)'),
185                                  $this->user->nickname)));
186
187          $this->element('link',
188              array('rel' => 'alternate',
189                    'href' => common_local_url('api',
190                      array('apiaction' => 'statuses',
191                            'method' => 'user_timeline.atom',
192                            'argument' => $this->user->nickname)),
193                            'type' => 'application/atom+xml',
194                            'title' => sprintf(_('Notice feed for %s (Atom)'),
195                              $this->user->nickname)));
196     }
197
198     function extraHead()
199     {
200         // FOAF
201         $this->element('link', array('rel' => 'meta',
202                                      'href' => common_local_url('foaf', array('nickname' =>
203                                                                               $this->user->nickname)),
204                                      'type' => 'application/rdf+xml',
205                                      'title' => 'FOAF'));
206         // for remote subscriptions etc.
207         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
208                                      'content' => common_local_url('xrds', array('nickname' =>
209                                                                                $this->user->nickname))));
210
211         if ($this->profile->bio) {
212             $this->element('meta', array('name' => 'description',
213                                          'content' => $this->profile->bio));
214         }
215
216         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
217             $id = new Microid('mailto:'.$this->user->email,
218                               $this->selfUrl());
219             $this->element('meta', array('name' => 'microid',
220                                          'content' => $id->toString()));
221         }
222         if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
223             $id = new Microid('xmpp:'.$this->user->jabber,
224                               $this->selfUrl());
225             $this->element('meta', array('name' => 'microid',
226                                          'content' => $id->toString()));
227         }
228
229         // See https://wiki.mozilla.org/Microsummaries
230
231         $this->element('link', array('rel' => 'microsummary',
232                                      'href' => common_local_url('microsummary',
233                                                                 array('nickname' => $this->profile->nickname))));
234     }
235
236     function showProfile()
237     {
238         $this->elementStart('div', 'entity_profile vcard author');
239         $this->element('h2', null, _('User profile'));
240
241         $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
242         $this->elementStart('dl', 'entity_depiction');
243         $this->element('dt', null, _('Photo'));
244         $this->elementStart('dd');
245         $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
246                                     'class' => 'photo avatar',
247                                     'width' => AVATAR_PROFILE_SIZE,
248                                     'height' => AVATAR_PROFILE_SIZE,
249                                     'alt' => $this->profile->nickname));
250         $this->elementEnd('dd');
251         $this->elementEnd('dl');
252
253         $this->elementStart('dl', 'entity_nickname');
254         $this->element('dt', null, _('Nickname'));
255         $this->elementStart('dd');
256         $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
257         $this->element('a', array('href' => $this->profile->profileurl,
258                                   'rel' => 'me', 'class' => $hasFN),
259                             $this->profile->nickname);
260         $this->elementEnd('dd');
261         $this->elementEnd('dl');
262
263         if ($this->profile->fullname) {
264             $this->elementStart('dl', 'entity_fn');
265             $this->element('dt', null, _('Full name'));
266             $this->elementStart('dd');
267             $this->element('span', 'fn', $this->profile->fullname);
268             $this->elementEnd('dd');
269             $this->elementEnd('dl');
270         }
271
272         if ($this->profile->location) {
273             $this->elementStart('dl', 'entity_location');
274             $this->element('dt', null, _('Location'));
275             $this->element('dd', 'location', $this->profile->location);
276             $this->elementEnd('dl');
277         }
278
279         if ($this->profile->homepage) {
280             $this->elementStart('dl', 'entity_url');
281             $this->element('dt', null, _('URL'));
282             $this->elementStart('dd');
283             $this->element('a', array('href' => $this->profile->homepage,
284                                       'rel' => 'me', 'class' => 'url'),
285                            $this->profile->homepage);
286             $this->elementEnd('dd');
287             $this->elementEnd('dl');
288         }
289
290         if ($this->profile->bio) {
291             $this->elementStart('dl', 'entity_note');
292             $this->element('dt', null, _('Note'));
293             $this->element('dd', 'note', $this->profile->bio);
294             $this->elementEnd('dl');
295         }
296
297         $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
298         if (count($tags) > 0) {
299             $this->elementStart('dl', 'entity_tags');
300             $this->element('dt', null, _('Tags'));
301             $this->elementStart('dd');
302             $this->elementStart('ul', 'tags xoxo');
303             foreach ($tags as $tag) {
304                 $this->elementStart('li');
305                 $this->element('span', 'mark_hash', '#');
306                 $this->element('a', array('rel' => 'tag',
307                                           'href' => common_local_url('peopletag',
308                                                                      array('tag' => $tag))),
309                                $tag);
310                 $this->elementEnd('li');
311             }
312             $this->elementEnd('ul');
313             $this->elementEnd('dd');
314             $this->elementEnd('dl');
315         }
316         $this->elementEnd('div');
317
318         $this->elementStart('div', 'entity_actions');
319         $this->element('h2', null, _('User actions'));
320         $this->elementStart('ul');
321         $cur = common_current_user();
322
323         if ($cur && $cur->id == $this->profile->id) {
324             $this->elementStart('li', 'entity_edit');
325             $this->element('a', array('href' => common_local_url('profilesettings'),
326                                       'title' => _('Edit profile settings')),
327                                       _('Edit'));
328             $this->elementEnd('li');
329         }
330
331         if ($cur) {
332             if ($cur->id != $this->profile->id) {
333                 $this->elementStart('li', 'entity_subscribe');
334                 if ($cur->isSubscribed($this->profile)) {
335                     $usf = new UnsubscribeForm($this, $this->profile);
336                     $usf->show();
337                 } else {
338                     $sf = new SubscribeForm($this, $this->profile);
339                     $sf->show();
340                 }
341                 $this->elementEnd('li');
342             }
343         } else {
344             $this->elementStart('li', 'entity_subscribe');
345             $this->showRemoteSubscribeLink();
346             $this->elementEnd('li');
347         }
348
349         $user = User::staticGet('id', $this->profile->id);
350         if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
351            $this->elementStart('li', 'entity_send-a-message');
352             $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
353                                       'title' => _('Send a direct message to this user')),
354                            _('Message'));
355             $this->elementEnd('li');
356
357             if ($user->email && $user->emailnotifynudge) {
358                 $this->elementStart('li', 'entity_nudge');
359                 $nf = new NudgeForm($this, $user);
360                 $nf->show();
361                 $this->elementEnd('li');
362             }
363         }
364
365         if ($cur && $cur->id != $this->profile->id) {
366             $blocked = $cur->hasBlocked($this->profile);
367             $this->elementStart('li', 'entity_block');
368             if ($blocked) {
369                 $ubf = new UnblockForm($this, $this->profile);
370                 $ubf->show();
371             } else {
372                 $bf = new BlockForm($this, $this->profile);
373                 $bf->show();
374             }
375             $this->elementEnd('li');
376         }
377         $this->elementEnd('ul');
378         $this->elementEnd('div');
379     }
380
381     function showRemoteSubscribeLink()
382     {
383         $url = common_local_url('remotesubscribe',
384                                 array('nickname' => $this->profile->nickname));
385         $this->element('a', array('href' => $url,
386                                   'class' => 'entity_remote_subscribe'),
387                        _('Subscribe'));
388     }
389
390     function showNotices()
391     {
392         $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
393
394         $pnl = new ProfileNoticeList($notice, $this);
395         $cnt = $pnl->show();
396
397         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
398                           'showstream', array('nickname' => $this->user->nickname));
399     }
400
401     function showSections()
402     {
403         $this->showSubscriptions();
404         $this->showSubscribers();
405         $this->showGroups();
406         $this->showStatistics();
407         $cloud = new PersonalTagCloudSection($this, $this->user);
408         $cloud->show();
409     }
410
411     function showSubscriptions()
412     {
413         $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
414
415         $this->elementStart('div', array('id' => 'entity_subscriptions',
416                                          'class' => 'section'));
417
418         $this->element('h2', null, _('Subscriptions'));
419
420         if ($profile) {
421             $pml = new ProfileMiniList($profile, $this->user, $this);
422             $cnt = $pml->show();
423             if ($cnt == 0) {
424                 $this->element('p', null, _('(None)'));
425             }
426         }
427
428         if ($cnt > PROFILES_PER_MINILIST) {
429             $this->elementStart('p');
430             $this->element('a', array('href' => common_local_url('subscriptions',
431                                                                  array('nickname' => $this->profile->nickname)),
432                                       'class' => 'more'),
433                            _('All subscriptions'));
434             $this->elementEnd('p');
435         }
436
437         $this->elementEnd('div');
438     }
439
440     function showSubscribers()
441     {
442         $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
443
444         $this->elementStart('div', array('id' => 'entity_subscribers',
445                                          'class' => 'section'));
446
447         $this->element('h2', null, _('Subscribers'));
448
449         if ($profile) {
450             $pml = new ProfileMiniList($profile, $this->user, $this);
451             $cnt = $pml->show();
452             if ($cnt == 0) {
453                 $this->element('p', null, _('(None)'));
454             }
455         }
456
457         if ($cnt > PROFILES_PER_MINILIST) {
458             $this->elementStart('p');
459             $this->element('a', array('href' => common_local_url('subscribers',
460                                                                  array('nickname' => $this->profile->nickname)),
461                                       'class' => 'more'),
462                            _('All subscribers'));
463             $this->elementEnd('p');
464         }
465
466         $this->elementEnd('div');
467     }
468
469     function showStatistics()
470     {
471         // XXX: WORM cache this
472         $subs = new Subscription();
473         $subs->subscriber = $this->profile->id;
474         $subs_count = (int) $subs->count() - 1;
475
476         $subbed = new Subscription();
477         $subbed->subscribed = $this->profile->id;
478         $subbed_count = (int) $subbed->count() - 1;
479
480         $notices = new Notice();
481         $notices->profile_id = $this->profile->id;
482         $notice_count = (int) $notices->count();
483
484         $this->elementStart('div', array('id' => 'entity_statistics',
485                                          'class' => 'section'));
486
487         $this->element('h2', null, _('Statistics'));
488
489         // Other stats...?
490         $this->elementStart('dl', 'entity_member-since');
491         $this->element('dt', null, _('Member since'));
492         $this->element('dd', null, date('j M Y',
493                                                  strtotime($this->profile->created)));
494         $this->elementEnd('dl');
495
496         $this->elementStart('dl', 'entity_subscriptions');
497         $this->elementStart('dt');
498         $this->element('a', array('href' => common_local_url('subscriptions',
499                                                              array('nickname' => $this->profile->nickname))),
500                        _('Subscriptions'));
501         $this->elementEnd('dt');
502         $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
503         $this->elementEnd('dl');
504
505         $this->elementStart('dl', 'entity_subscribers');
506         $this->elementStart('dt');
507         $this->element('a', array('href' => common_local_url('subscribers',
508                                                              array('nickname' => $this->profile->nickname))),
509                        _('Subscribers'));
510         $this->elementEnd('dt');
511         $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
512         $this->elementEnd('dl');
513
514         $this->elementStart('dl', 'entity_notices');
515         $this->element('dt', null, _('Notices'));
516         $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
517         $this->elementEnd('dl');
518
519         $this->elementEnd('div');
520     }
521
522     function showGroups()
523     {
524         $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
525
526         $this->elementStart('div', array('id' => 'entity_groups',
527                                          'class' => 'section'));
528
529         $this->element('h2', null, _('Groups'));
530
531         if ($groups) {
532             $gml = new GroupMiniList($groups, $this->user, $this);
533             $cnt = $gml->show();
534             if ($cnt == 0) {
535                 $this->element('p', null, _('(None)'));
536             }
537         }
538
539         if ($cnt > GROUPS_PER_MINILIST) {
540             $this->elementStart('p');
541             $this->element('a', array('href' => common_local_url('usergroups',
542                                                                  array('nickname' => $this->profile->nickname)),
543                                       'class' => 'more'),
544                            _('All groups'));
545             $this->elementEnd('p');
546         }
547
548         $this->elementEnd('div');
549     }
550
551     function showAnonymousMessage()
552     {
553                 $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
554                        'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
555                        '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
556                      $this->user->nickname, $this->user->nickname);
557         $this->elementStart('div', array('id' => 'anon_notice'));
558         $this->raw(common_markup_to_html($m));
559         $this->elementEnd('div');
560     }
561
562 }
563
564 // We don't show the author for a profile, since we already know who it is!
565
566 class ProfileNoticeList extends NoticeList
567 {
568     function newListItem($notice)
569     {
570         return new ProfileNoticeListItem($notice, $this->out);
571     }
572 }
573
574 class ProfileNoticeListItem extends NoticeListItem
575 {
576     function showAuthor()
577     {
578         return;
579     }
580 }