]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
60270cfd7cb1514af2ca20f9f0f0dc879eeca8c7
[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  * @copyright 2008-2009 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/personalgroupnav.php';
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
37
38 /**
39  * User profile page
40  *
41  * When I created this page, "show stream" seemed like the best name for it.
42  * Now, it seems like a really bad name.
43  *
44  * It shows a stream of the user's posts, plus lots of profile info, links
45  * to subscriptions and stuff, etc.
46  *
47  * @category Personal
48  * @package  Laconica
49  * @author   Evan Prodromou <evan@controlyourself.ca>
50  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
51  * @link     http://laconi.ca/
52  */
53
54 class ShowstreamAction extends Action
55 {
56     var $user = null;
57     var $page = null;
58     var $profile = null;
59
60     function title()
61     {
62         if ($this->page == 1) {
63             return $this->user->nickname;
64         } else {
65             return sprintf(_("%s, page %d"),
66                            $this->user->nickname,
67                            $this->page);
68         }
69     }
70
71     function prepare($args)
72     {
73         parent::prepare($args);
74
75         $nickname_arg = $this->arg('nickname');
76         $nickname = common_canonical_nickname($nickname_arg);
77
78         // Permanent redirect on non-canonical nickname
79
80         if ($nickname_arg != $nickname) {
81             $args = array('nickname' => $nickname);
82             if ($this->arg('page') && $this->arg('page') != 1) {
83                 $args['page'] = $this->arg['page'];
84             }
85             common_redirect(common_local_url('showstream', $args), 301);
86             return false;
87         }
88
89         $this->user = User::staticGet('nickname', $nickname);
90
91         if (!$this->user) {
92             $this->clientError(_('No such user.'), 404);
93             return false;
94         }
95
96         $this->profile = $this->user->getProfile();
97
98         if (!$this->profile) {
99             $this->serverError(_('User has no profile.'));
100             return false;
101         }
102
103         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
104
105         return true;
106     }
107
108     function handle($args)
109     {
110
111         // Looks like we're good; start output
112
113         // For YADIS discovery, we also have a <meta> tag
114
115         header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
116                                                                    $this->user->nickname)));
117
118         $this->showPage();
119     }
120
121     function showContent()
122     {
123         $this->showProfile();
124         $this->showNotices();
125     }
126
127     function showLocalNav()
128     {
129         $nav = new PersonalGroupNav($this);
130         $nav->show();
131     }
132
133     function showPageTitle()
134     {
135         // Don't show the H1; we have one in the profile block
136     }
137
138     function showExportData()
139     {
140         $fl = new FeedList($this);
141         $fl->show(array(0=>array('href'=>common_local_url('userrss',
142                                                           array('nickname' => $this->user->nickname)),
143                                  'type' => 'rss',
144                                  'version' => 'RSS 1.0',
145                                  'item' => 'notices'),
146                         1=>array('href'=>common_local_url('usertimeline',
147                                                           array('nickname' => $this->user->nickname)),
148                                  'type' => 'atom',
149                                  'version' => 'Atom 1.0',
150                                  'item' => 'usertimeline'),
151                         2=>array('href'=>common_local_url('foaf',
152                                                           array('nickname' => $this->user->nickname)),
153                                  'type' => 'rdf',
154                                  'version' => 'FOAF',
155                                  'item' => 'foaf')));
156     }
157
158     function showFeeds()
159     {
160         // Feeds
161         $this->element('link', array('rel' => 'alternate',
162                                      'href' => common_local_url('api',
163                                                                 array('apiaction' => 'statuses',
164                                                                       'method' => 'user_timeline.rss',
165                                                                       'argument' => $this->user->nickname)),
166                                      'type' => 'application/rss+xml',
167                                      'title' => sprintf(_('Notice feed for %s'), $this->user->nickname)));
168         $this->element('link', array('rel' => 'alternate feed',
169                                      'href' => common_local_url('api',
170                                                                 array('apiaction' => 'statuses',
171                                                                       'method' => 'user_timeline.atom',
172                                                                       'argument' => $this->user->nickname)),
173                                      'type' => 'application/atom+xml',
174                                      'title' => sprintf(_('Notice feed for %s'), $this->user->nickname)));
175         $this->element('link', array('rel' => 'alternate',
176                                      'href' => common_local_url('userrss', array('nickname' =>
177                                                                                $this->user->nickname)),
178                                      'type' => 'application/rdf+xml',
179                                      'title' => sprintf(_('Notice feed for %s'), $this->user->nickname)));
180     }
181
182     function extraHead()
183     {
184         // FOAF
185         $this->element('link', array('rel' => 'meta',
186                                      'href' => common_local_url('foaf', array('nickname' =>
187                                                                               $this->user->nickname)),
188                                      'type' => 'application/rdf+xml',
189                                      'title' => 'FOAF'));
190         // for remote subscriptions etc.
191         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
192                                      'content' => common_local_url('xrds', array('nickname' =>
193                                                                                $this->user->nickname))));
194
195         if ($this->profile->bio) {
196             $this->element('meta', array('name' => 'description',
197                                          'content' => $this->profile->bio));
198         }
199
200         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
201             $id = new Microid('mailto:'.$this->user->email,
202                               $this->selfUrl());
203             $this->element('meta', array('name' => 'microid',
204                                          'content' => $id->toString()));
205         }
206         if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
207             $id = new Microid('xmpp:'.$this->user->jabber,
208                               $this->selfUrl());
209             $this->element('meta', array('name' => 'microid',
210                                          'content' => $id->toString()));
211         }
212
213         // See https://wiki.mozilla.org/Microsummaries
214
215         $this->element('link', array('rel' => 'microsummary',
216                                      'href' => common_local_url('microsummary',
217                                                                 array('nickname' => $this->profile->nickname))));
218     }
219
220     function showProfile()
221     {
222         $this->elementStart('div', array('id' => 'user_profile', 'class' => 'vcard author'));
223         $this->element('h2', null, _('User profile'));
224
225         $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
226         $this->elementStart('dl', 'user_depiction');
227         $this->element('dt', null, _('Photo'));
228         $this->elementStart('dd');
229         $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
230                                     'class' => 'photo avatar',
231                                     'width' => AVATAR_PROFILE_SIZE,
232                                     'height' => AVATAR_PROFILE_SIZE,
233                                     'alt' => $this->profile->nickname));
234         $this->elementEnd('dd');
235         $this->elementEnd('dl');
236
237         if ($this->profile->fullname) {
238             $this->elementStart('dl', 'user_fn');
239             $this->element('dt', null, _('Full name'));
240             $this->elementStart('dd');
241             $this->element('a', array('href' => $this->profile->homepage,
242                                       'rel' => 'me', 'class' => 'fn url uid'),
243                            $this->profile->fullname);
244             $this->elementEnd('dd');
245             $this->elementEnd('dl');
246         }
247
248         $this->elementStart('dl', 'user_nickname');
249         $this->element('dt', null, _('Nickname'));
250         $this->elementStart('dd');
251         $this->element('span', 'fn nickname', $this->profile->nickname);
252         $this->elementEnd('dd');
253         $this->elementEnd('dl');
254
255         if ($this->profile->location) {
256             $this->elementStart('dl', 'user_location');
257             $this->element('dt', null, _('Location'));
258             $this->element('dd', 'location', $this->profile->location);
259             $this->elementEnd('dl');
260         }
261
262         if ($this->profile->homepage) {
263             $this->elementStart('dl', 'user_url');
264             $this->element('dt', null, _('URL'));
265             $this->elementStart('dd');
266             $this->element('a', array('href' => $this->profile->homepage,
267                                       'rel' => 'me', 'class' => 'url'),
268                            $this->profile->homepage);
269             $this->elementEnd('dd');
270             $this->elementEnd('dl');
271         }
272
273         if ($this->profile->bio) {
274             $this->elementStart('dl', 'user_note');
275             $this->element('dt', null, _('Note'));
276             $this->element('dd', 'note', $this->profile->bio);
277             $this->elementEnd('dl');
278         }
279
280         $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
281         if (count($tags) > 0) {
282             $this->elementStart('dl', 'user_tags');
283             $this->element('dt', null, _('Tags'));
284             $this->elementStart('dd', 'tags');
285             $this->elementStart('ul', 'tags xoxo');
286             foreach ($tags as $tag) {
287                 $this->elementStart('li');
288                 $this->element('a', array('rel' => 'tag',
289                                           'href' => common_local_url('peopletag',
290                                                                      array('tag' => $tag))),
291                                $tag);
292                 $this->elementEnd('li');
293             }
294             $this->elementEnd('ul');
295             $this->elementEnd('dd');
296             $this->elementEnd('dl');
297         }
298         $this->elementEnd('div');
299
300
301         $this->elementStart('div', array('id' => 'user_actions'));
302         $this->element('h2', null, _('User actions'));
303         $this->elementStart('ul');
304         $this->elementStart('li', array('id' => 'user_subscribe'));
305         $cur = common_current_user();
306         if ($cur) {
307             if ($cur->id != $this->profile->id) {
308                 if ($cur->isSubscribed($this->profile)) {
309                     $sf = new SubscribeForm($this, $this->profile);
310                     $sf->show();
311                 } else {
312                     $usf = new UnsubscribeForm($this, $this->profile);
313                     $usf->show();
314                 }
315             }
316         } else {
317             $this->showRemoteSubscribeLink();
318         }
319         $this->elementEnd('li');
320
321         common_profile_new_message_nudge($cur, $this->user, $this->profile);
322
323         if ($cur && $cur->id != $this->profile->id) {
324             $blocked = $cur->hasBlocked($this->profile);
325             $this->elementStart('li', array('id' => 'user_block'));
326             if ($blocked) {
327                 $bf = new BlockForm($this, $this->profile);
328                 $bf->show();
329             } else {
330                 $ubf = new UnblockForm($this, $this->profile);
331                 $ubf->show();
332             }
333             $this->elementEnd('li');
334         }
335         $this->elementEnd('ul');
336         $this->elementEnd('div');
337
338         $this->elementEnd('div');
339     }
340
341     function showRemoteSubscribeLink()
342     {
343         $url = common_local_url('remotesubscribe',
344                                 array('nickname' => $this->profile->nickname));
345         $this->element('a', array('href' => $url,
346                                   'id' => 'remotesubscribe'),
347                        _('Subscribe'));
348     }
349
350     function showNotices()
351     {
352         $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
353
354         $pnl = new ProfileNoticeList($notice, $this);
355         $cnt = $pnl->show();
356
357         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
358                           'showstream', array('nickname' => $this->user->nickname));
359     }
360
361     function showSections()
362     {
363         $this->showStatistics();
364         $this->showSubscriptions();
365     }
366
367     function showSubscriptions()
368     {
369         $subs = new Subscription();
370         $subs->subscriber = $this->profile->id;
371         $subs->whereAdd('subscribed != ' . $this->profile->id);
372
373         $subs->orderBy('created DESC');
374
375         // We ask for an extra one to know if we need to do another page
376
377         $subs->limit(0, SUBSCRIPTIONS + 1);
378
379         $subs_count = $subs->find();
380
381         $this->elementStart('div', array('id' => 'subscriptions',
382                                          'class' => 'section'));
383
384         $this->element('h2', null, _('Subscriptions'));
385
386         if ($subs_count > 0) {
387
388             $this->elementStart('ul', array('id' => 'subscriptions_avatars'));
389
390             for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
391
392                 if (!$subs->fetch()) {
393                     common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
394                     break;
395                 }
396
397                 $other = Profile::staticGet($subs->subscribed);
398
399                 if (!$other) {
400                     common_log_db_error($subs, 'SELECT', __FILE__);
401                     continue;
402                 }
403
404                 $this->elementStart('li', 'vcard');
405                 $this->elementStart('a', array('title' => ($other->fullname) ?
406                                                 $other->fullname :
407                                                 $other->nickname,
408                                                 'href' => $other->profileurl,
409                                                 'rel' => 'contact',
410                                                  'class' => 'subscription fn url'));
411                 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
412                 $this->element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) :  common_default_avatar(AVATAR_MINI_SIZE)),
413                                             'width' => AVATAR_MINI_SIZE,
414                                             'height' => AVATAR_MINI_SIZE,
415                                             'class' => 'avatar mini photo',
416                                             'alt' =>  ($other->fullname) ?
417                                             $other->fullname :
418                                             $other->nickname));
419                 $this->elementEnd('a');
420                 $this->elementEnd('li');
421             }
422
423             $this->elementEnd('ul');
424         }
425
426         if ($subs_count > SUBSCRIPTIONS) {
427             $this->elementStart('p', array('id' => 'subscriptions_viewall'));
428
429             $this->element('a', array('href' => common_local_url('subscriptions',
430                                                                  array('nickname' => $this->profile->nickname)),
431                                       'class' => 'moresubscriptions'),
432                            _('All subscriptions'));
433             $this->elementEnd('p');
434         }
435
436         $this->elementEnd('div');
437     }
438
439     function showStatistics()
440     {
441         // XXX: WORM cache this
442         $subs = new Subscription();
443         $subs->subscriber = $this->profile->id;
444         $subs_count = (int) $subs->count() - 1;
445
446         $subbed = new Subscription();
447         $subbed->subscribed = $this->profile->id;
448         $subbed_count = (int) $subbed->count() - 1;
449
450         $notices = new Notice();
451         $notices->profile_id = $this->profile->id;
452         $notice_count = (int) $notices->count();
453
454         $this->elementStart('div', array('id' => 'statistics',
455                                          'class' => 'section'));
456
457         $this->element('h2', 'statistics', _('Statistics'));
458
459         // Other stats...?
460         $this->elementStart('dl', 'statistics');
461         $this->element('dt', 'membersince', _('Member since'));
462         $this->element('dd', 'membersince', date('j M Y',
463                                                  strtotime($this->profile->created)));
464
465         $this->elementStart('dt', 'subscriptions');
466         $this->element('a', array('href' => common_local_url('subscriptions',
467                                                              array('nickname' => $this->profile->nickname))),
468                        _('Subscriptions'));
469         $this->elementEnd('dt');
470         $this->element('dd', 'subscriptions', (is_int($subs_count)) ? $subs_count : '0');
471         $this->elementStart('dt', 'subscribers');
472         $this->element('a', array('href' => common_local_url('subscribers',
473                                                              array('nickname' => $this->profile->nickname))),
474                        _('Subscribers'));
475         $this->elementEnd('dt');
476         $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
477         $this->element('dt', 'notices', _('Notices'));
478         $this->element('dd', 'notices', (is_int($notice_count)) ? $notice_count : '0');
479         $this->elementEnd('dl');
480
481         $this->elementEnd('div');
482     }
483
484 }
485
486 // We don't show the author for a profile, since we already know who it is!
487
488 class ProfileNoticeList extends NoticeList
489 {
490     function newListItem($notice)
491     {
492         return new ProfileNoticeListItem($notice, $this->out);
493     }
494 }
495
496 class ProfileNoticeListItem extends NoticeListItem
497 {
498     function showAuthor()
499     {
500         return;
501     }
502 }