]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Added mark_hash for content (i.e., to indicate tags with the
[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          $this->element('h1', NULL, $this->profile->nickname._("'s profile"));
136     }
137
138     function showPageNoticeBlock()
139     {
140         return;
141     }
142
143     function showExportData()
144     {
145         $fl = new FeedList($this);
146         $fl->show(array(0=>array('href'=>common_local_url('userrss',
147                                                           array('nickname' => $this->user->nickname)),
148                                  'type' => 'rss',
149                                  'version' => 'RSS 1.0',
150                                  'item' => 'notices'),
151                         1=>array('href'=>common_local_url('usertimeline',
152                                                           array('nickname' => $this->user->nickname)),
153                                  'type' => 'atom',
154                                  'version' => 'Atom 1.0',
155                                  'item' => 'usertimeline'),
156                         2=>array('href'=>common_local_url('foaf',
157                                                           array('nickname' => $this->user->nickname)),
158                                  'type' => 'rdf',
159                                  'version' => 'FOAF',
160                                  'item' => 'foaf')));
161     }
162
163     function showFeeds()
164     {
165         // Feeds
166         $this->element('link', array('rel' => 'alternate',
167                                      'href' => common_local_url('api',
168                                                                 array('apiaction' => 'statuses',
169                                                                       'method' => 'user_timeline.rss',
170                                                                       'argument' => $this->user->nickname)),
171                                      'type' => 'application/rss+xml',
172                                      'title' => sprintf(_('Notice feed for %s'), $this->user->nickname)));
173         $this->element('link', array('rel' => 'alternate feed',
174                                      'href' => common_local_url('api',
175                                                                 array('apiaction' => 'statuses',
176                                                                       'method' => 'user_timeline.atom',
177                                                                       'argument' => $this->user->nickname)),
178                                      'type' => 'application/atom+xml',
179                                      'title' => sprintf(_('Notice feed for %s'), $this->user->nickname)));
180         $this->element('link', array('rel' => 'alternate',
181                                      'href' => common_local_url('userrss', array('nickname' =>
182                                                                                $this->user->nickname)),
183                                      'type' => 'application/rdf+xml',
184                                      'title' => sprintf(_('Notice feed for %s'), $this->user->nickname)));
185     }
186
187     function extraHead()
188     {
189         // FOAF
190         $this->element('link', array('rel' => 'meta',
191                                      'href' => common_local_url('foaf', array('nickname' =>
192                                                                               $this->user->nickname)),
193                                      'type' => 'application/rdf+xml',
194                                      'title' => 'FOAF'));
195         // for remote subscriptions etc.
196         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
197                                      'content' => common_local_url('xrds', array('nickname' =>
198                                                                                $this->user->nickname))));
199
200         if ($this->profile->bio) {
201             $this->element('meta', array('name' => 'description',
202                                          'content' => $this->profile->bio));
203         }
204
205         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
206             $id = new Microid('mailto:'.$this->user->email,
207                               $this->selfUrl());
208             $this->element('meta', array('name' => 'microid',
209                                          'content' => $id->toString()));
210         }
211         if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
212             $id = new Microid('xmpp:'.$this->user->jabber,
213                               $this->selfUrl());
214             $this->element('meta', array('name' => 'microid',
215                                          'content' => $id->toString()));
216         }
217
218         // See https://wiki.mozilla.org/Microsummaries
219
220         $this->element('link', array('rel' => 'microsummary',
221                                      'href' => common_local_url('microsummary',
222                                                                 array('nickname' => $this->profile->nickname))));
223     }
224
225     function showProfile()
226     {
227         $this->elementStart('div', array('id' => 'user_profile', 'class' => 'vcard author'));
228         $this->element('h2', null, _('User profile'));
229
230         $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
231         $this->elementStart('dl', 'user_depiction');
232         $this->element('dt', null, _('Photo'));
233         $this->elementStart('dd');
234         $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
235                                     'class' => 'photo avatar',
236                                     'width' => AVATAR_PROFILE_SIZE,
237                                     'height' => AVATAR_PROFILE_SIZE,
238                                     'alt' => $this->profile->nickname));
239         $this->elementEnd('dd');
240         $this->elementEnd('dl');
241
242         if ($this->profile->fullname) {
243             $this->elementStart('dl', 'user_fn');
244             $this->element('dt', null, _('Full name'));
245             $this->elementStart('dd');
246             $this->element('span', 'fn', $this->profile->fullname);
247             $this->elementEnd('dd');
248             $this->elementEnd('dl');
249         }
250         $this->elementStart('dl', 'user_nickname');
251         $this->element('dt', null, _('Nickname'));
252         $this->elementStart('dd');
253             $this->element('a', array('href' => $this->profile->profileurl,
254                                       'rel' => 'me', 'class' => 'fn nickname url uid'),
255                            $this->profile->nickname);
256         $this->elementEnd('dd');
257         $this->elementEnd('dl');
258
259         if ($this->profile->location) {
260             $this->elementStart('dl', 'user_location');
261             $this->element('dt', null, _('Location'));
262             $this->element('dd', 'location', $this->profile->location);
263             $this->elementEnd('dl');
264         }
265
266         if ($this->profile->homepage) {
267             $this->elementStart('dl', 'user_url');
268             $this->element('dt', null, _('URL'));
269             $this->elementStart('dd');
270             $this->element('a', array('href' => $this->profile->homepage,
271                                       'rel' => 'me', 'class' => 'url'),
272                            $this->profile->homepage);
273             $this->elementEnd('dd');
274             $this->elementEnd('dl');
275         }
276
277         if ($this->profile->bio) {
278             $this->elementStart('dl', 'user_note');
279             $this->element('dt', null, _('Note'));
280             $this->element('dd', 'note', $this->profile->bio);
281             $this->elementEnd('dl');
282         }
283
284         $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
285         if (count($tags) > 0) {
286             $this->elementStart('dl', 'user_tags');
287             $this->element('dt', null, _('Tags'));
288             $this->elementStart('dd', 'tags');
289             $this->elementStart('ul', 'tags xoxo');
290             foreach ($tags as $tag) {
291                 $this->elementStart('li');
292                 $this->element('span', 'mark_hash', '#');
293                 $this->element('a', array('rel' => 'tag',
294                                           'href' => common_local_url('peopletag',
295                                                                      array('tag' => $tag))),
296                                $tag);
297                 $this->elementEnd('li');
298             }
299             $this->elementEnd('ul');
300             $this->elementEnd('dd');
301             $this->elementEnd('dl');
302         }
303         $this->elementEnd('div');
304
305
306         $this->elementStart('div', array('id' => 'user_actions'));
307         $this->element('h2', null, _('User actions'));
308         $this->elementStart('ul');
309         $this->elementStart('li', array('id' => 'user_subscribe'));
310         $cur = common_current_user();
311         if ($cur) {
312             if ($cur->id != $this->profile->id) {
313                 if ($cur->isSubscribed($this->profile)) {
314                     $sf = new SubscribeForm($this, $this->profile);
315                     $sf->show();
316                 } else {
317                     $usf = new UnsubscribeForm($this, $this->profile);
318                     $usf->show();
319                 }
320             }
321         } else {
322             $this->showRemoteSubscribeLink();
323         }
324         $this->elementEnd('li');
325
326         common_profile_new_message_nudge($cur, $this->user, $this->profile);
327
328         if ($cur && $cur->id != $this->profile->id) {
329             $blocked = $cur->hasBlocked($this->profile);
330             $this->elementStart('li', array('id' => 'user_block'));
331             if ($blocked) {
332                 $bf = new BlockForm($this, $this->profile);
333                 $bf->show();
334             } else {
335                 $ubf = new UnblockForm($this, $this->profile);
336                 $ubf->show();
337             }
338             $this->elementEnd('li');
339         }
340         $this->elementEnd('ul');
341         $this->elementEnd('div');
342     }
343
344     function showRemoteSubscribeLink()
345     {
346         $url = common_local_url('remotesubscribe',
347                                 array('nickname' => $this->profile->nickname));
348         $this->element('a', array('href' => $url,
349                                   'id' => 'remotesubscribe'),
350                        _('Subscribe'));
351     }
352
353     function showNotices()
354     {
355         $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
356
357         $pnl = new ProfileNoticeList($notice, $this);
358         $cnt = $pnl->show();
359
360         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
361                           'showstream', array('nickname' => $this->user->nickname));
362     }
363
364     function showSections()
365     {
366         $this->showStatistics();
367         $this->showSubscriptions();
368     }
369
370     function showSubscriptions()
371     {
372         $subs = new Subscription();
373         $subs->subscriber = $this->profile->id;
374         $subs->whereAdd('subscribed != ' . $this->profile->id);
375
376         $subs->orderBy('created DESC');
377
378         // We ask for an extra one to know if we need to do another page
379
380         $subs->limit(0, SUBSCRIPTIONS + 1);
381
382         $subs_count = $subs->find();
383
384         $this->elementStart('div', array('id' => 'user_subscriptions',
385                                          'class' => 'section'));
386
387         $this->element('h2', null, _('Subscriptions'));
388
389         if ($subs_count > 0) {
390
391             $this->elementStart('ul', 'users');
392
393             for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
394
395                 if (!$subs->fetch()) {
396                     common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
397                     break;
398                 }
399
400                 $other = Profile::staticGet($subs->subscribed);
401
402                 if (!$other) {
403                     common_log_db_error($subs, 'SELECT', __FILE__);
404                     continue;
405                 }
406
407                 $this->elementStart('li', 'vcard');
408                 $this->elementStart('a', array('title' => ($other->fullname) ?
409                                                 $other->fullname :
410                                                 $other->nickname,
411                                                 'href' => $other->profileurl,
412                                                 'rel' => 'contact',
413                                                  'class' => 'url'));
414                 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
415                 $this->element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) :  common_default_avatar(AVATAR_MINI_SIZE)),
416                                             'width' => AVATAR_MINI_SIZE,
417                                             'height' => AVATAR_MINI_SIZE,
418                                             'class' => 'avatar photo',
419                                             'alt' =>  ($other->fullname) ?
420                                             $other->fullname :
421                                             $other->nickname));
422                 $this->element('span', 'fn nickname', $other->nickname);
423                 $this->elementEnd('a');
424                 $this->elementEnd('li');
425             }
426
427             $this->elementEnd('ul');
428         }
429
430         if ($subs_count > SUBSCRIPTIONS) {
431             $this->elementStart('p');
432
433             $this->element('a', array('href' => common_local_url('subscriptions',
434                                                                  array('nickname' => $this->profile->nickname)),
435                                       'class' => 'mores'),
436                            _('All subscriptions'));
437             $this->elementEnd('p');
438         }
439
440         $this->elementEnd('div');
441     }
442
443     function showStatistics()
444     {
445         // XXX: WORM cache this
446         $subs = new Subscription();
447         $subs->subscriber = $this->profile->id;
448         $subs_count = (int) $subs->count() - 1;
449
450         $subbed = new Subscription();
451         $subbed->subscribed = $this->profile->id;
452         $subbed_count = (int) $subbed->count() - 1;
453
454         $notices = new Notice();
455         $notices->profile_id = $this->profile->id;
456         $notice_count = (int) $notices->count();
457
458         $this->elementStart('div', array('id' => 'user_statistics',
459                                          'class' => 'section'));
460
461         $this->element('h2', null, _('Statistics'));
462
463         // Other stats...?
464         $this->elementStart('dl', 'user_member-since');
465         $this->element('dt', null, _('Member since'));
466         $this->element('dd', null, date('j M Y',
467                                                  strtotime($this->profile->created)));
468         $this->elementEnd('dl');
469
470         $this->elementStart('dl', 'user_subscriptions');
471         $this->elementStart('dt');
472         $this->element('a', array('href' => common_local_url('subscriptions',
473                                                              array('nickname' => $this->profile->nickname))),
474                        _('Subscriptions'));
475         $this->elementEnd('dt');
476         $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
477         $this->elementEnd('dl');
478
479         $this->elementStart('dl', 'user_subscribers');
480         $this->elementStart('dt');
481         $this->element('a', array('href' => common_local_url('subscribers',
482                                                              array('nickname' => $this->profile->nickname))),
483                        _('Subscribers'));
484         $this->elementEnd('dt');
485         $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
486         $this->elementEnd('dl');
487
488         $this->elementStart('dl', 'user_notices');
489         $this->element('dt', null, _('Notices'));
490         $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
491         $this->elementEnd('dl');
492
493         $this->elementEnd('div');
494     }
495
496 }
497
498 // We don't show the author for a profile, since we already know who it is!
499
500 class ProfileNoticeList extends NoticeList
501 {
502     function newListItem($notice)
503     {
504         return new ProfileNoticeListItem($notice, $this->out);
505     }
506 }
507
508 class ProfileNoticeListItem extends NoticeListItem
509 {
510     function showAuthor()
511     {
512         return;
513     }
514 }