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