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