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 ($this->page == 1) {
71 return $this->user->nickname;
73 return sprintf(_("%s, page %d"),
74 $this->user->nickname,
79 function prepare($args)
81 parent::prepare($args);
83 $nickname_arg = $this->arg('nickname');
84 $nickname = common_canonical_nickname($nickname_arg);
86 // Permanent redirect on non-canonical nickname
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'];
93 common_redirect(common_local_url('showstream', $args), 301);
97 $this->user = User::staticGet('nickname', $nickname);
100 $this->clientError(_('No such user.'), 404);
104 $this->profile = $this->user->getProfile();
106 if (!$this->profile) {
107 $this->serverError(_('User has no profile.'));
111 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
116 function handle($args)
119 // Looks like we're good; start output
121 // For YADIS discovery, we also have a <meta> tag
123 header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
124 $this->user->nickname)));
129 function showContent()
131 $this->showProfile();
132 $this->showNotices();
135 function showLocalNav()
137 $nav = new PersonalGroupNav($this);
141 function showPageTitle()
143 $this->element('h1', NULL, $this->profile->nickname._("'s profile"));
146 function showPageNoticeBlock()
151 function showExportData()
153 $fl = new FeedList($this);
154 $fl->show(array(0=>array('href'=>common_local_url('userrss',
155 array('nickname' => $this->user->nickname)),
157 'version' => 'RSS 1.0',
158 'item' => 'notices'),
159 1=>array('href'=>common_local_url('usertimeline',
160 array('nickname' => $this->user->nickname)),
162 'version' => 'Atom 1.0',
163 'item' => 'usertimeline'),
164 2=>array('href'=>common_local_url('foaf',
165 array('nickname' => $this->user->nickname)),
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)));
198 $this->element('link', array('rel' => 'meta',
199 'href' => common_local_url('foaf', array('nickname' =>
200 $this->user->nickname)),
201 'type' => 'application/rdf+xml',
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))));
208 if ($this->profile->bio) {
209 $this->element('meta', array('name' => 'description',
210 'content' => $this->profile->bio));
213 if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
214 $id = new Microid('mailto:'.$this->user->email,
216 $this->element('meta', array('name' => 'microid',
217 'content' => $id->toString()));
219 if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
220 $id = new Microid('xmpp:'.$this->user->jabber,
222 $this->element('meta', array('name' => 'microid',
223 'content' => $id->toString()));
226 // See https://wiki.mozilla.org/Microsummaries
228 $this->element('link', array('rel' => 'microsummary',
229 'href' => common_local_url('microsummary',
230 array('nickname' => $this->profile->nickname))));
233 function showProfile()
235 $this->elementStart('div', 'entity_profile vcard author');
236 $this->element('h2', null, _('User profile'));
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 $this->elementEnd('dl');
250 $this->elementStart('dl', 'entity_nickname');
251 $this->element('dt', null, _('Nickname'));
252 $this->elementStart('dd');
253 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
254 $this->element('a', array('href' => $this->profile->profileurl,
255 'rel' => 'me', 'class' => $hasFN),
256 $this->profile->nickname);
257 $this->elementEnd('dd');
258 $this->elementEnd('dl');
260 if ($this->profile->fullname) {
261 $this->elementStart('dl', 'entity_fn');
262 $this->element('dt', null, _('Full name'));
263 $this->elementStart('dd');
264 $this->element('span', 'fn', $this->profile->fullname);
265 $this->elementEnd('dd');
266 $this->elementEnd('dl');
269 if ($this->profile->location) {
270 $this->elementStart('dl', 'entity_location');
271 $this->element('dt', null, _('Location'));
272 $this->element('dd', 'location', $this->profile->location);
273 $this->elementEnd('dl');
276 if ($this->profile->homepage) {
277 $this->elementStart('dl', 'entity_url');
278 $this->element('dt', null, _('URL'));
279 $this->elementStart('dd');
280 $this->element('a', array('href' => $this->profile->homepage,
281 'rel' => 'me', 'class' => 'url'),
282 $this->profile->homepage);
283 $this->elementEnd('dd');
284 $this->elementEnd('dl');
287 if ($this->profile->bio) {
288 $this->elementStart('dl', 'entity_note');
289 $this->element('dt', null, _('Note'));
290 $this->element('dd', 'note', $this->profile->bio);
291 $this->elementEnd('dl');
294 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
295 if (count($tags) > 0) {
296 $this->elementStart('dl', 'entity_tags');
297 $this->element('dt', null, _('Tags'));
298 $this->elementStart('dd');
299 $this->elementStart('ul', 'tags xoxo');
300 foreach ($tags as $tag) {
301 $this->elementStart('li');
302 $this->element('span', 'mark_hash', '#');
303 $this->element('a', array('rel' => 'tag',
304 'href' => common_local_url('peopletag',
305 array('tag' => $tag))),
307 $this->elementEnd('li');
309 $this->elementEnd('ul');
310 $this->elementEnd('dd');
311 $this->elementEnd('dl');
313 $this->elementEnd('div');
315 $this->elementStart('div', 'entity_actions');
316 $this->element('h2', null, _('User actions'));
317 $this->elementStart('ul');
318 $cur = common_current_user();
320 if ($cur && $cur->id == $this->profile->id) {
321 $this->elementStart('li', 'entity_edit');
322 $this->element('a', array('href' => common_local_url('profilesettings'),
323 'title' => _('Edit profile settings')),
325 $this->elementEnd('li');
329 if ($cur->id != $this->profile->id) {
330 $this->elementStart('li', 'entity_subscribe');
331 if ($cur->isSubscribed($this->profile)) {
332 $usf = new UnsubscribeForm($this, $this->profile);
335 $sf = new SubscribeForm($this, $this->profile);
338 $this->elementEnd('li');
341 $this->elementStart('li', 'entity_subscribe');
342 $this->showRemoteSubscribeLink();
343 $this->elementEnd('li');
346 $user = User::staticGet('id', $this->profile->id);
347 if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
348 $this->elementStart('li', 'entity_send-a-message');
349 $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
350 'title' => _('Send a direct message to this user')),
352 $this->elementEnd('li');
354 if ($user->email && $user->emailnotifynudge) {
355 $this->elementStart('li', 'entity_nudge');
356 $nf = new NudgeForm($this, $user);
358 $this->elementEnd('li');
362 if ($cur && $cur->id != $this->profile->id) {
363 $blocked = $cur->hasBlocked($this->profile);
364 $this->elementStart('li', 'entity_block');
366 $ubf = new UnblockForm($this, $this->profile);
369 $bf = new BlockForm($this, $this->profile);
372 $this->elementEnd('li');
374 $this->elementEnd('ul');
375 $this->elementEnd('div');
378 function showRemoteSubscribeLink()
380 $url = common_local_url('remotesubscribe',
381 array('nickname' => $this->profile->nickname));
382 $this->element('a', array('href' => $url,
383 'class' => 'entity_remote_subscribe'),
387 function showNotices()
389 $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
391 $pnl = new ProfileNoticeList($notice, $this);
394 $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
395 'showstream', array('nickname' => $this->user->nickname));
398 function showSections()
400 $this->showSubscriptions();
401 $this->showSubscribers();
403 $this->showStatistics();
404 $cloud = new PersonalTagCloudSection($this, $this->user);
408 function showSubscriptions()
410 $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
412 $this->elementStart('div', array('id' => 'entity_subscriptions',
413 'class' => 'section'));
415 $this->element('h2', null, _('Subscriptions'));
418 $pml = new ProfileMiniList($profile, $this->user, $this);
421 $this->element('p', null, _('(None)'));
425 if ($cnt > PROFILES_PER_MINILIST) {
426 $this->elementStart('p');
427 $this->element('a', array('href' => common_local_url('subscriptions',
428 array('nickname' => $this->profile->nickname)),
430 _('All subscriptions'));
431 $this->elementEnd('p');
434 $this->elementEnd('div');
437 function showSubscribers()
439 $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
441 $this->elementStart('div', array('id' => 'entity_subscribers',
442 'class' => 'section'));
444 $this->element('h2', null, _('Subscribers'));
447 $pml = new ProfileMiniList($profile, $this->user, $this);
450 $this->element('p', null, _('(None)'));
454 if ($cnt > PROFILES_PER_MINILIST) {
455 $this->elementStart('p');
456 $this->element('a', array('href' => common_local_url('subscribers',
457 array('nickname' => $this->profile->nickname)),
459 _('All subscribers'));
460 $this->elementEnd('p');
463 $this->elementEnd('div');
466 function showStatistics()
468 // XXX: WORM cache this
469 $subs = new Subscription();
470 $subs->subscriber = $this->profile->id;
471 $subs_count = (int) $subs->count() - 1;
473 $subbed = new Subscription();
474 $subbed->subscribed = $this->profile->id;
475 $subbed_count = (int) $subbed->count() - 1;
477 $notices = new Notice();
478 $notices->profile_id = $this->profile->id;
479 $notice_count = (int) $notices->count();
481 $this->elementStart('div', array('id' => 'entity_statistics',
482 'class' => 'section'));
484 $this->element('h2', null, _('Statistics'));
487 $this->elementStart('dl', 'entity_member-since');
488 $this->element('dt', null, _('Member since'));
489 $this->element('dd', null, date('j M Y',
490 strtotime($this->profile->created)));
491 $this->elementEnd('dl');
493 $this->elementStart('dl', 'entity_subscriptions');
494 $this->elementStart('dt');
495 $this->element('a', array('href' => common_local_url('subscriptions',
496 array('nickname' => $this->profile->nickname))),
498 $this->elementEnd('dt');
499 $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
500 $this->elementEnd('dl');
502 $this->elementStart('dl', 'entity_subscribers');
503 $this->elementStart('dt');
504 $this->element('a', array('href' => common_local_url('subscribers',
505 array('nickname' => $this->profile->nickname))),
507 $this->elementEnd('dt');
508 $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
509 $this->elementEnd('dl');
511 $this->elementStart('dl', 'entity_notices');
512 $this->element('dt', null, _('Notices'));
513 $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
514 $this->elementEnd('dl');
516 $this->elementEnd('div');
519 function showGroups()
521 $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
523 $this->elementStart('div', array('id' => 'entity_groups',
524 'class' => 'section'));
526 $this->element('h2', null, _('Groups'));
529 $gml = new GroupMiniList($groups, $this->user, $this);
532 $this->element('p', null, _('(None)'));
536 if ($cnt > GROUPS_PER_MINILIST) {
537 $this->elementStart('p');
538 $this->element('a', array('href' => common_local_url('usergroups',
539 array('nickname' => $this->profile->nickname)),
542 $this->elementEnd('p');
545 $this->elementEnd('div');
548 function showAnonymousMessage()
550 $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
551 'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
552 '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
553 $this->user->nickname, $this->user->nickname);
554 $this->elementStart('div', array('id' => 'anon_notice'));
555 $this->raw(common_markup_to_html($m));
556 $this->elementEnd('div');
561 // We don't show the author for a profile, since we already know who it is!
563 class ProfileNoticeList extends NoticeList
565 function newListItem($notice)
567 return new ProfileNoticeListItem($notice, $this->out);
571 class ProfileNoticeListItem extends NoticeListItem
573 function showAuthor()