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