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