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
65 if ($this->page == 1) {
66 return $this->user->nickname;
68 return sprintf(_("%s, page %d"),
69 $this->user->nickname,
74 function prepare($args)
76 parent::prepare($args);
78 $nickname_arg = $this->arg('nickname');
79 $nickname = common_canonical_nickname($nickname_arg);
81 // Permanent redirect on non-canonical nickname
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'];
88 common_redirect(common_local_url('showstream', $args), 301);
92 $this->user = User::staticGet('nickname', $nickname);
95 $this->clientError(_('No such user.'), 404);
99 $this->profile = $this->user->getProfile();
101 if (!$this->profile) {
102 $this->serverError(_('User has no profile.'));
106 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
111 function handle($args)
114 // Looks like we're good; start output
116 // For YADIS discovery, we also have a <meta> tag
118 header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
119 $this->user->nickname)));
124 function showContent()
126 $this->showProfile();
127 $this->showNotices();
130 function showLocalNav()
132 $nav = new PersonalGroupNav($this);
136 function showPageTitle()
138 $this->element('h1', NULL, $this->profile->nickname._("'s profile"));
141 function showPageNoticeBlock()
146 function showExportData()
148 $fl = new FeedList($this);
149 $fl->show(array(0=>array('href'=>common_local_url('userrss',
150 array('nickname' => $this->user->nickname)),
152 'version' => 'RSS 1.0',
153 'item' => 'notices'),
154 1=>array('href'=>common_local_url('usertimeline',
155 array('nickname' => $this->user->nickname)),
157 'version' => 'Atom 1.0',
158 'item' => 'usertimeline'),
159 2=>array('href'=>common_local_url('foaf',
160 array('nickname' => $this->user->nickname)),
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)));
193 $this->element('link', array('rel' => 'meta',
194 'href' => common_local_url('foaf', array('nickname' =>
195 $this->user->nickname)),
196 'type' => 'application/rdf+xml',
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))));
203 if ($this->profile->bio) {
204 $this->element('meta', array('name' => 'description',
205 'content' => $this->profile->bio));
208 if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
209 $id = new Microid('mailto:'.$this->user->email,
211 $this->element('meta', array('name' => 'microid',
212 'content' => $id->toString()));
214 if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
215 $id = new Microid('xmpp:'.$this->user->jabber,
217 $this->element('meta', array('name' => 'microid',
218 'content' => $id->toString()));
221 // See https://wiki.mozilla.org/Microsummaries
223 $this->element('link', array('rel' => 'microsummary',
224 'href' => common_local_url('microsummary',
225 array('nickname' => $this->profile->nickname))));
228 function showProfile()
230 $this->elementStart('div', 'entity_profile vcard author');
231 $this->element('h2', null, _('User profile'));
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');
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');
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');
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');
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');
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');
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))),
302 $this->elementEnd('li');
304 $this->elementEnd('ul');
305 $this->elementEnd('dd');
306 $this->elementEnd('dl');
308 $this->elementEnd('div');
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();
317 if ($cur->id != $this->profile->id) {
318 if ($cur->isSubscribed($this->profile)) {
319 $usf = new UnsubscribeForm($this, $this->profile);
322 $sf = new SubscribeForm($this, $this->profile);
327 $this->showRemoteSubscribeLink();
329 $this->elementEnd('li');
331 // common_profile_new_message_nudge($cur, $this->user, $this->profile);
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')),
339 $this->elementEnd('li');
341 if ($user->email && $user->emailnotifynudge) {
342 $this->elementStart('li', array('id' => 'entity_nudge'));
343 $nf = new NudgeForm($this, $user);
345 $this->elementEnd('li');
349 if ($cur && $cur->id != $this->profile->id) {
350 $blocked = $cur->hasBlocked($this->profile);
351 $this->elementStart('li', array('id' => 'entity_block'));
353 $ubf = new UnblockForm($this, $this->profile);
356 $bf = new BlockForm($this, $this->profile);
359 $this->elementEnd('li');
361 $this->elementEnd('ul');
362 $this->elementEnd('div');
365 function showRemoteSubscribeLink()
367 $url = common_local_url('remotesubscribe',
368 array('nickname' => $this->profile->nickname));
369 $this->element('a', array('href' => $url,
370 'id' => 'entity_subscribe_remote'),
374 function showNotices()
376 $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
378 $pnl = new ProfileNoticeList($notice, $this);
381 $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
382 'showstream', array('nickname' => $this->user->nickname));
385 function showSections()
387 $this->showSubscriptions();
388 $this->showSubscribers();
390 $this->showStatistics();
391 $cloud = new PersonalTagCloudSection($this, $this->user);
395 function showSubscriptions()
397 $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
399 $this->elementStart('div', array('id' => 'entity_subscriptions',
400 'class' => 'section'));
402 $this->element('h2', null, _('Subscriptions'));
405 $pml = new ProfileMiniList($profile, $this->user, $this);
408 $this->element('p', null, _('(None)'));
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)),
417 _('All subscriptions'));
418 $this->elementEnd('p');
421 $this->elementEnd('div');
424 function showSubscribers()
426 $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
428 $this->elementStart('div', array('id' => 'entity_subscribers',
429 'class' => 'section'));
431 $this->element('h2', null, _('Subscribers'));
434 $pml = new ProfileMiniList($profile, $this->user, $this);
437 $this->element('p', null, _('(None)'));
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)),
446 _('All subscribers'));
447 $this->elementEnd('p');
450 $this->elementEnd('div');
453 function showStatistics()
455 // XXX: WORM cache this
456 $subs = new Subscription();
457 $subs->subscriber = $this->profile->id;
458 $subs_count = (int) $subs->count() - 1;
460 $subbed = new Subscription();
461 $subbed->subscribed = $this->profile->id;
462 $subbed_count = (int) $subbed->count() - 1;
464 $notices = new Notice();
465 $notices->profile_id = $this->profile->id;
466 $notice_count = (int) $notices->count();
468 $this->elementStart('div', array('id' => 'entity_statistics',
469 'class' => 'section'));
471 $this->element('h2', null, _('Statistics'));
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');
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))),
485 $this->elementEnd('dt');
486 $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
487 $this->elementEnd('dl');
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))),
494 $this->elementEnd('dt');
495 $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
496 $this->elementEnd('dl');
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');
503 $this->elementEnd('div');
506 function showGroups()
508 $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
510 $this->elementStart('div', array('id' => 'entity_groups',
511 'class' => 'section'));
513 $this->element('h2', null, _('Groups'));
516 $gml = new GroupMiniList($groups, $this->user, $this);
519 $this->element('p', null, _('(None)'));
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)),
529 $this->elementEnd('p');
532 $this->elementEnd('div');
535 function showAnonymousMessage()
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');
548 // We don't show the author for a profile, since we already know who it is!
550 class ProfileNoticeList extends NoticeList
552 function newListItem($notice)
554 return new ProfileNoticeListItem($notice, $this->out);
558 class ProfileNoticeListItem extends NoticeListItem
560 function showAuthor()