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