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