3 * Laconica, the distributed open-source microblogging tool
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.
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.
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/>.
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/
31 if (!defined('LACONICA')) {
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';
44 * When I created this page, "show stream" seemed like the best name for it.
45 * Now, it seems like a really bad name.
47 * It shows a stream of the user's posts, plus lots of profile info, links
48 * to subscriptions and stuff, etc.
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/
57 class ShowstreamAction extends Action
70 if (!empty($this->profile->fullname)) {
71 $base = $this->profile->fullname . ' (' . $this->user->nickname . ') ';
73 $base = $this->user->nickname;
76 if ($this->page == 1) {
79 return sprintf(_("%s, page %d"),
85 function prepare($args)
87 parent::prepare($args);
89 $nickname_arg = $this->arg('nickname');
90 $nickname = common_canonical_nickname($nickname_arg);
92 // Permanent redirect on non-canonical nickname
94 if ($nickname_arg != $nickname) {
95 $args = array('nickname' => $nickname);
96 if ($this->arg('page') && $this->arg('page') != 1) {
97 $args['page'] = $this->arg['page'];
99 common_redirect(common_local_url('showstream', $args), 301);
103 $this->user = User::staticGet('nickname', $nickname);
106 $this->clientError(_('No such user.'), 404);
110 $this->profile = $this->user->getProfile();
112 if (!$this->profile) {
113 $this->serverError(_('User has no profile.'));
117 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
119 common_set_returnto($this->selfUrl());
124 function handle($args)
127 // Looks like we're good; start output
129 // For YADIS discovery, we also have a <meta> tag
131 header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
132 $this->user->nickname)));
137 function showContent()
139 $this->showProfile();
140 $this->showNotices();
143 function showLocalNav()
145 $nav = new PersonalGroupNav($this);
149 function showPageNoticeBlock()
156 return array(new Feed(Feed::RSS1,
157 common_local_url('userrss',
158 array('nickname' => $this->user->nickname)),
159 sprintf(_('Notice feed for %s (RSS 1.0)'),
160 $this->user->nickname)),
162 common_local_url('api',
163 array('apiaction' => 'statuses',
164 'method' => 'user_timeline',
165 'argument' => $this->user->nickname.'.rss')),
166 sprintf(_('Notice feed for %s (RSS 2.0)'),
167 $this->user->nickname)),
169 common_local_url('api',
170 array('apiaction' => 'statuses',
171 'method' => 'user_timeline',
172 'argument' => $this->user->nickname.'.atom')),
173 sprintf(_('Notice feed for %s (Atom)'),
174 $this->user->nickname)),
176 common_local_url('foaf', array('nickname' =>
177 $this->user->nickname)),
178 sprintf(_('FOAF for %s'), $this->user->nickname)));
183 // for remote subscriptions etc.
184 $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
185 'content' => common_local_url('xrds', array('nickname' =>
186 $this->user->nickname))));
188 if ($this->profile->bio) {
189 $this->element('meta', array('name' => 'description',
190 'content' => $this->profile->bio));
193 if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
194 $id = new Microid('mailto:'.$this->user->email,
196 $this->element('meta', array('name' => 'microid',
197 'content' => $id->toString()));
199 if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
200 $id = new Microid('xmpp:'.$this->user->jabber,
202 $this->element('meta', array('name' => 'microid',
203 'content' => $id->toString()));
206 // See https://wiki.mozilla.org/Microsummaries
208 $this->element('link', array('rel' => 'microsummary',
209 'href' => common_local_url('microsummary',
210 array('nickname' => $this->profile->nickname))));
213 function showProfile()
215 $this->elementStart('div', 'entity_profile vcard author');
216 $this->element('h2', null, _('User profile'));
218 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
219 $this->elementStart('dl', 'entity_depiction');
220 $this->element('dt', null, _('Photo'));
221 $this->elementStart('dd');
222 $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
223 'class' => 'photo avatar',
224 'width' => AVATAR_PROFILE_SIZE,
225 'height' => AVATAR_PROFILE_SIZE,
226 'alt' => $this->profile->nickname));
227 $this->elementEnd('dd');
229 $user = User::staticGet('id', $this->profile->id);
230 $cur = common_current_user();
231 if ($cur && $cur->id == $user->id) {
232 $this->elementStart('dd');
233 $this->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
234 $this->elementEnd('dd');
237 $this->elementEnd('dl');
239 $this->elementStart('dl', 'entity_nickname');
240 $this->element('dt', null, _('Nickname'));
241 $this->elementStart('dd');
242 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
243 $this->element('a', array('href' => $this->profile->profileurl,
244 'rel' => 'me', 'class' => $hasFN),
245 $this->profile->nickname);
246 $this->elementEnd('dd');
247 $this->elementEnd('dl');
249 if ($this->profile->fullname) {
250 $this->elementStart('dl', 'entity_fn');
251 $this->element('dt', null, _('Full name'));
252 $this->elementStart('dd');
253 $this->element('span', 'fn', $this->profile->fullname);
254 $this->elementEnd('dd');
255 $this->elementEnd('dl');
258 if ($this->profile->location) {
259 $this->elementStart('dl', 'entity_location');
260 $this->element('dt', null, _('Location'));
261 $this->element('dd', 'label', $this->profile->location);
262 $this->elementEnd('dl');
265 if ($this->profile->homepage) {
266 $this->elementStart('dl', 'entity_url');
267 $this->element('dt', null, _('URL'));
268 $this->elementStart('dd');
269 $this->element('a', array('href' => $this->profile->homepage,
270 'rel' => 'me', 'class' => 'url'),
271 $this->profile->homepage);
272 $this->elementEnd('dd');
273 $this->elementEnd('dl');
276 if ($this->profile->bio) {
277 $this->elementStart('dl', 'entity_note');
278 $this->element('dt', null, _('Note'));
279 $this->element('dd', 'note', $this->profile->bio);
280 $this->elementEnd('dl');
283 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
284 if (count($tags) > 0) {
285 $this->elementStart('dl', 'entity_tags');
286 $this->element('dt', null, _('Tags'));
287 $this->elementStart('dd');
288 $this->elementStart('ul', 'tags xoxo');
289 foreach ($tags as $tag) {
290 $this->elementStart('li');
291 // Avoid space by using raw output.
292 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
293 common_local_url('peopletag', array('tag' => $tag)) .
294 '">' . $tag . '</a>';
296 $this->elementEnd('li');
298 $this->elementEnd('ul');
299 $this->elementEnd('dd');
300 $this->elementEnd('dl');
302 $this->elementEnd('div');
304 $this->elementStart('div', 'entity_actions');
305 $this->element('h2', null, _('User actions'));
306 $this->elementStart('ul');
307 $cur = common_current_user();
309 if ($cur && $cur->id == $this->profile->id) {
310 $this->elementStart('li', 'entity_edit');
311 $this->element('a', array('href' => common_local_url('profilesettings'),
312 'title' => _('Edit profile settings')),
314 $this->elementEnd('li');
318 if ($cur->id != $this->profile->id) {
319 $this->elementStart('li', 'entity_subscribe');
320 if ($cur->isSubscribed($this->profile)) {
321 $usf = new UnsubscribeForm($this, $this->profile);
324 $sf = new SubscribeForm($this, $this->profile);
327 $this->elementEnd('li');
330 $this->elementStart('li', 'entity_subscribe');
331 $this->showRemoteSubscribeLink();
332 $this->elementEnd('li');
335 if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
336 $this->elementStart('li', 'entity_send-a-message');
337 $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
338 'title' => _('Send a direct message to this user')),
340 $this->elementEnd('li');
342 if ($user->email && $user->emailnotifynudge) {
343 $this->elementStart('li', 'entity_nudge');
344 $nf = new NudgeForm($this, $user);
346 $this->elementEnd('li');
350 if ($cur && $cur->id != $this->profile->id) {
351 $blocked = $cur->hasBlocked($this->profile);
352 $this->elementStart('li', 'entity_block');
354 $ubf = new UnblockForm($this, $this->profile);
357 $bf = new BlockForm($this, $this->profile);
360 $this->elementEnd('li');
362 $this->elementEnd('ul');
363 $this->elementEnd('div');
366 function showRemoteSubscribeLink()
368 $url = common_local_url('remotesubscribe',
369 array('nickname' => $this->profile->nickname));
370 $this->element('a', array('href' => $url,
371 'class' => 'entity_remote_subscribe'),
375 function showNotices()
377 $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
379 $pnl = new ProfileNoticeList($notice, $this);
382 $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
383 'showstream', array('nickname' => $this->user->nickname));
386 function showSections()
388 $this->showSubscriptions();
389 $this->showSubscribers();
391 $this->showStatistics();
392 $cloud = new PersonalTagCloudSection($this, $this->user);
396 function showSubscriptions()
398 $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
400 $this->elementStart('div', array('id' => 'entity_subscriptions',
401 'class' => 'section'));
403 $this->element('h2', null, _('Subscriptions'));
406 $pml = new ProfileMiniList($profile, $this->user, $this);
409 $this->element('p', null, _('(None)'));
413 if ($cnt > PROFILES_PER_MINILIST) {
414 $this->elementStart('p');
415 $this->element('a', array('href' => common_local_url('subscriptions',
416 array('nickname' => $this->profile->nickname)),
418 _('All subscriptions'));
419 $this->elementEnd('p');
422 $this->elementEnd('div');
425 function showSubscribers()
427 $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
429 $this->elementStart('div', array('id' => 'entity_subscribers',
430 'class' => 'section'));
432 $this->element('h2', null, _('Subscribers'));
435 $pml = new ProfileMiniList($profile, $this->user, $this);
438 $this->element('p', null, _('(None)'));
442 if ($cnt > PROFILES_PER_MINILIST) {
443 $this->elementStart('p');
444 $this->element('a', array('href' => common_local_url('subscribers',
445 array('nickname' => $this->profile->nickname)),
447 _('All subscribers'));
448 $this->elementEnd('p');
451 $this->elementEnd('div');
454 function showStatistics()
456 // XXX: WORM cache this
457 $subs = new Subscription();
458 $subs->subscriber = $this->profile->id;
459 $subs_count = (int) $subs->count() - 1;
461 $subbed = new Subscription();
462 $subbed->subscribed = $this->profile->id;
463 $subbed_count = (int) $subbed->count() - 1;
465 $notices = new Notice();
466 $notices->profile_id = $this->profile->id;
467 $notice_count = (int) $notices->count();
469 $this->elementStart('div', array('id' => 'entity_statistics',
470 'class' => 'section'));
472 $this->element('h2', null, _('Statistics'));
475 $this->elementStart('dl', 'entity_member-since');
476 $this->element('dt', null, _('Member since'));
477 $this->element('dd', null, date('j M Y',
478 strtotime($this->profile->created)));
479 $this->elementEnd('dl');
481 $this->elementStart('dl', 'entity_subscriptions');
482 $this->elementStart('dt');
483 $this->element('a', array('href' => common_local_url('subscriptions',
484 array('nickname' => $this->profile->nickname))),
486 $this->elementEnd('dt');
487 $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
488 $this->elementEnd('dl');
490 $this->elementStart('dl', 'entity_subscribers');
491 $this->elementStart('dt');
492 $this->element('a', array('href' => common_local_url('subscribers',
493 array('nickname' => $this->profile->nickname))),
495 $this->elementEnd('dt');
496 $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
497 $this->elementEnd('dl');
499 $this->elementStart('dl', 'entity_notices');
500 $this->element('dt', null, _('Notices'));
501 $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
502 $this->elementEnd('dl');
504 $this->elementEnd('div');
507 function showGroups()
509 $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
511 $this->elementStart('div', array('id' => 'entity_groups',
512 'class' => 'section'));
514 $this->element('h2', null, _('Groups'));
517 $gml = new GroupMiniList($groups, $this->user, $this);
520 $this->element('p', null, _('(None)'));
524 if ($cnt > GROUPS_PER_MINILIST) {
525 $this->elementStart('p');
526 $this->element('a', array('href' => common_local_url('usergroups',
527 array('nickname' => $this->profile->nickname)),
530 $this->elementEnd('p');
533 $this->elementEnd('div');
536 function showAnonymousMessage()
538 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
539 $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
540 'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
541 '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
542 $this->user->nickname, $this->user->nickname);
544 $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
545 'based on the Free Software [Laconica](http://laconi.ca/) tool. '),
546 $this->user->nickname, $this->user->nickname);
548 $this->elementStart('div', array('id' => 'anon_notice'));
549 $this->raw(common_markup_to_html($m));
550 $this->elementEnd('div');
555 // We don't show the author for a profile, since we already know who it is!
557 class ProfileNoticeList extends NoticeList
559 function newListItem($notice)
561 return new ProfileNoticeListItem($notice, $this->out);
565 class ProfileNoticeListItem extends NoticeListItem
567 function showAuthor()