]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Merge branch 'master' of git://gitorious.org/laconica/mainline
[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) ? $avatar->displayUrl() : Avatar::defaultImage(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
252         $user = User::staticGet('id', $this->profile->id);
253         $cur = common_current_user();
254         if ($cur && $cur->id == $user->id) {
255             $this->elementStart('dd');
256             $this->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
257             $this->elementEnd('dd');
258         }
259
260         $this->elementEnd('dl');
261
262         $this->elementStart('dl', 'entity_nickname');
263         $this->element('dt', null, _('Nickname'));
264         $this->elementStart('dd');
265         $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
266         $this->element('a', array('href' => $this->profile->profileurl,
267                                   'rel' => 'me', 'class' => $hasFN),
268                        $this->profile->nickname);
269         $this->elementEnd('dd');
270         $this->elementEnd('dl');
271
272         if ($this->profile->fullname) {
273             $this->elementStart('dl', 'entity_fn');
274             $this->element('dt', null, _('Full name'));
275             $this->elementStart('dd');
276             $this->element('span', 'fn', $this->profile->fullname);
277             $this->elementEnd('dd');
278             $this->elementEnd('dl');
279         }
280
281         if ($this->profile->location) {
282             $this->elementStart('dl', 'entity_location');
283             $this->element('dt', null, _('Location'));
284             $this->element('dd', 'location', $this->profile->location);
285             $this->elementEnd('dl');
286         }
287
288         if ($this->profile->homepage) {
289             $this->elementStart('dl', 'entity_url');
290             $this->element('dt', null, _('URL'));
291             $this->elementStart('dd');
292             $this->element('a', array('href' => $this->profile->homepage,
293                                       'rel' => 'me', 'class' => 'url'),
294                            $this->profile->homepage);
295             $this->elementEnd('dd');
296             $this->elementEnd('dl');
297         }
298
299         if ($this->profile->bio) {
300             $this->elementStart('dl', 'entity_note');
301             $this->element('dt', null, _('Note'));
302             $this->element('dd', 'note', $this->profile->bio);
303             $this->elementEnd('dl');
304         }
305
306         $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
307         if (count($tags) > 0) {
308             $this->elementStart('dl', 'entity_tags');
309             $this->element('dt', null, _('Tags'));
310             $this->elementStart('dd');
311             $this->elementStart('ul', 'tags xoxo');
312             foreach ($tags as $tag) {
313                 $this->elementStart('li');
314                 $this->element('span', 'mark_hash', '#');
315                 $this->element('a', array('rel' => 'tag',
316                                           'href' => common_local_url('peopletag',
317                                                                      array('tag' => $tag))),
318                                $tag);
319                 $this->elementEnd('li');
320             }
321             $this->elementEnd('ul');
322             $this->elementEnd('dd');
323             $this->elementEnd('dl');
324         }
325         $this->elementEnd('div');
326
327         $this->elementStart('div', 'entity_actions');
328         $this->element('h2', null, _('User actions'));
329         $this->elementStart('ul');
330         $cur = common_current_user();
331
332         if ($cur && $cur->id == $this->profile->id) {
333             $this->elementStart('li', 'entity_edit');
334             $this->element('a', array('href' => common_local_url('profilesettings'),
335                                       'title' => _('Edit profile settings')),
336                            _('Edit'));
337             $this->elementEnd('li');
338         }
339
340         if ($cur) {
341             if ($cur->id != $this->profile->id) {
342                 $this->elementStart('li', 'entity_subscribe');
343                 if ($cur->isSubscribed($this->profile)) {
344                     $usf = new UnsubscribeForm($this, $this->profile);
345                     $usf->show();
346                 } else {
347                     $sf = new SubscribeForm($this, $this->profile);
348                     $sf->show();
349                 }
350                 $this->elementEnd('li');
351             }
352         } else {
353             $this->elementStart('li', 'entity_subscribe');
354             $this->showRemoteSubscribeLink();
355             $this->elementEnd('li');
356         }
357
358         if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
359             $this->elementStart('li', 'entity_send-a-message');
360             $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
361                                       'title' => _('Send a direct message to this user')),
362                            _('Message'));
363             $this->elementEnd('li');
364
365             if ($user->email && $user->emailnotifynudge) {
366                 $this->elementStart('li', 'entity_nudge');
367                 $nf = new NudgeForm($this, $user);
368                 $nf->show();
369                 $this->elementEnd('li');
370             }
371         }
372
373         if ($cur && $cur->id != $this->profile->id) {
374             $blocked = $cur->hasBlocked($this->profile);
375             $this->elementStart('li', 'entity_block');
376             if ($blocked) {
377                 $ubf = new UnblockForm($this, $this->profile);
378                 $ubf->show();
379             } else {
380                 $bf = new BlockForm($this, $this->profile);
381                 $bf->show();
382             }
383             $this->elementEnd('li');
384         }
385         $this->elementEnd('ul');
386         $this->elementEnd('div');
387     }
388
389     function showRemoteSubscribeLink()
390     {
391         $url = common_local_url('remotesubscribe',
392                                 array('nickname' => $this->profile->nickname));
393         $this->element('a', array('href' => $url,
394                                   'class' => 'entity_remote_subscribe'),
395                        _('Subscribe'));
396     }
397
398     function showNotices()
399     {
400         $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
401
402         $pnl = new ProfileNoticeList($notice, $this);
403         $cnt = $pnl->show();
404
405         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
406                           'showstream', array('nickname' => $this->user->nickname));
407     }
408
409     function showSections()
410     {
411         $this->showSubscriptions();
412         $this->showSubscribers();
413         $this->showGroups();
414         $this->showStatistics();
415         $cloud = new PersonalTagCloudSection($this, $this->user);
416         $cloud->show();
417     }
418
419     function showSubscriptions()
420     {
421         $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
422
423         $this->elementStart('div', array('id' => 'entity_subscriptions',
424                                          'class' => 'section'));
425
426         $this->element('h2', null, _('Subscriptions'));
427
428         if ($profile) {
429             $pml = new ProfileMiniList($profile, $this->user, $this);
430             $cnt = $pml->show();
431             if ($cnt == 0) {
432                 $this->element('p', null, _('(None)'));
433             }
434         }
435
436         if ($cnt > PROFILES_PER_MINILIST) {
437             $this->elementStart('p');
438             $this->element('a', array('href' => common_local_url('subscriptions',
439                                                                  array('nickname' => $this->profile->nickname)),
440                                       'class' => 'more'),
441                            _('All subscriptions'));
442             $this->elementEnd('p');
443         }
444
445         $this->elementEnd('div');
446     }
447
448     function showSubscribers()
449     {
450         $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
451
452         $this->elementStart('div', array('id' => 'entity_subscribers',
453                                          'class' => 'section'));
454
455         $this->element('h2', null, _('Subscribers'));
456
457         if ($profile) {
458             $pml = new ProfileMiniList($profile, $this->user, $this);
459             $cnt = $pml->show();
460             if ($cnt == 0) {
461                 $this->element('p', null, _('(None)'));
462             }
463         }
464
465         if ($cnt > PROFILES_PER_MINILIST) {
466             $this->elementStart('p');
467             $this->element('a', array('href' => common_local_url('subscribers',
468                                                                  array('nickname' => $this->profile->nickname)),
469                                       'class' => 'more'),
470                            _('All subscribers'));
471             $this->elementEnd('p');
472         }
473
474         $this->elementEnd('div');
475     }
476
477     function showStatistics()
478     {
479         // XXX: WORM cache this
480         $subs = new Subscription();
481         $subs->subscriber = $this->profile->id;
482         $subs_count = (int) $subs->count() - 1;
483
484         $subbed = new Subscription();
485         $subbed->subscribed = $this->profile->id;
486         $subbed_count = (int) $subbed->count() - 1;
487
488         $notices = new Notice();
489         $notices->profile_id = $this->profile->id;
490         $notice_count = (int) $notices->count();
491
492         $this->elementStart('div', array('id' => 'entity_statistics',
493                                          'class' => 'section'));
494
495         $this->element('h2', null, _('Statistics'));
496
497         // Other stats...?
498         $this->elementStart('dl', 'entity_member-since');
499         $this->element('dt', null, _('Member since'));
500         $this->element('dd', null, date('j M Y',
501                                         strtotime($this->profile->created)));
502         $this->elementEnd('dl');
503
504         $this->elementStart('dl', 'entity_subscriptions');
505         $this->elementStart('dt');
506         $this->element('a', array('href' => common_local_url('subscriptions',
507                                                              array('nickname' => $this->profile->nickname))),
508                        _('Subscriptions'));
509         $this->elementEnd('dt');
510         $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
511         $this->elementEnd('dl');
512
513         $this->elementStart('dl', 'entity_subscribers');
514         $this->elementStart('dt');
515         $this->element('a', array('href' => common_local_url('subscribers',
516                                                              array('nickname' => $this->profile->nickname))),
517                        _('Subscribers'));
518         $this->elementEnd('dt');
519         $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
520         $this->elementEnd('dl');
521
522         $this->elementStart('dl', 'entity_notices');
523         $this->element('dt', null, _('Notices'));
524         $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
525         $this->elementEnd('dl');
526
527         $this->elementEnd('div');
528     }
529
530     function showGroups()
531     {
532         $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
533
534         $this->elementStart('div', array('id' => 'entity_groups',
535                                          'class' => 'section'));
536
537         $this->element('h2', null, _('Groups'));
538
539         if ($groups) {
540             $gml = new GroupMiniList($groups, $this->user, $this);
541             $cnt = $gml->show();
542             if ($cnt == 0) {
543                 $this->element('p', null, _('(None)'));
544             }
545         }
546
547         if ($cnt > GROUPS_PER_MINILIST) {
548             $this->elementStart('p');
549             $this->element('a', array('href' => common_local_url('usergroups',
550                                                                  array('nickname' => $this->profile->nickname)),
551                                       'class' => 'more'),
552                            _('All groups'));
553             $this->elementEnd('p');
554         }
555
556         $this->elementEnd('div');
557     }
558
559     function showAnonymousMessage()
560     {
561                 $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
562                        'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
563                        '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
564                      $this->user->nickname, $this->user->nickname);
565         $this->elementStart('div', array('id' => 'anon_notice'));
566         $this->raw(common_markup_to_html($m));
567         $this->elementEnd('div');
568     }
569
570 }
571
572 // We don't show the author for a profile, since we already know who it is!
573
574 class ProfileNoticeList extends NoticeList
575 {
576     function newListItem($notice)
577     {
578         return new ProfileNoticeListItem($notice, $this->out);
579     }
580 }
581
582 class ProfileNoticeListItem extends NoticeListItem
583 {
584     function showAuthor()
585     {
586         return;
587     }
588 }