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 $user =& common_current_user();
144 if ($user && ($user->id == $this->profile->id)) {
145 $this->element('h1', NULL, _("Your profile"));
147 $this->element('h1', NULL, sprintf(_('%s\'s profile'), $this->profile->nickname));
151 function showPageNoticeBlock()
156 function showExportData()
158 $fl = new FeedList($this);
159 $fl->show(array(0=>array('href'=>common_local_url('userrss',
160 array('nickname' => $this->user->nickname)),
162 'version' => 'RSS 1.0',
163 'item' => 'notices'),
164 1=>array('href'=>common_local_url('usertimeline',
165 array('nickname' => $this->user->nickname)),
167 'version' => 'Atom 1.0',
168 'item' => 'usertimeline'),
169 2=>array('href'=>common_local_url('foaf',
170 array('nickname' => $this->user->nickname)),
178 $this->element('link', array('rel' => 'alternate',
179 'type' => 'application/rss+xml',
180 'href' => common_local_url('userrss',
181 array('nickname' => $this->user->nickname)),
182 'title' => sprintf(_('Notice feed for %s (RSS)'),
183 $this->user->nickname)));
185 $this->element('link',
186 array('rel' => 'alternate',
187 'href' => common_local_url('api',
188 array('apiaction' => 'statuses',
189 'method' => 'user_timeline.atom',
190 'argument' => $this->user->nickname)),
191 'type' => 'application/atom+xml',
192 'title' => sprintf(_('Notice feed for %s (Atom)'),
193 $this->user->nickname)));
199 $this->element('link', array('rel' => 'meta',
200 'href' => common_local_url('foaf', array('nickname' =>
201 $this->user->nickname)),
202 'type' => 'application/rdf+xml',
204 // for remote subscriptions etc.
205 $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
206 'content' => common_local_url('xrds', array('nickname' =>
207 $this->user->nickname))));
209 if ($this->profile->bio) {
210 $this->element('meta', array('name' => 'description',
211 'content' => $this->profile->bio));
214 if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
215 $id = new Microid('mailto:'.$this->user->email,
217 $this->element('meta', array('name' => 'microid',
218 'content' => $id->toString()));
220 if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
221 $id = new Microid('xmpp:'.$this->user->jabber,
223 $this->element('meta', array('name' => 'microid',
224 'content' => $id->toString()));
227 // See https://wiki.mozilla.org/Microsummaries
229 $this->element('link', array('rel' => 'microsummary',
230 'href' => common_local_url('microsummary',
231 array('nickname' => $this->profile->nickname))));
234 function showProfile()
236 $this->elementStart('div', 'entity_profile vcard author');
237 $this->element('h2', null, _('User profile'));
239 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
240 $this->elementStart('dl', 'entity_depiction');
241 $this->element('dt', null, _('Photo'));
242 $this->elementStart('dd');
243 $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
244 'class' => 'photo avatar',
245 'width' => AVATAR_PROFILE_SIZE,
246 'height' => AVATAR_PROFILE_SIZE,
247 'alt' => $this->profile->nickname));
248 $this->elementEnd('dd');
249 $this->elementEnd('dl');
251 $this->elementStart('dl', 'entity_nickname');
252 $this->element('dt', null, _('Nickname'));
253 $this->elementStart('dd');
254 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
255 $this->element('a', array('href' => $this->profile->profileurl,
256 'rel' => 'me', 'class' => $hasFN),
257 $this->profile->nickname);
258 $this->elementEnd('dd');
259 $this->elementEnd('dl');
261 if ($this->profile->fullname) {
262 $this->elementStart('dl', 'entity_fn');
263 $this->element('dt', null, _('Full name'));
264 $this->elementStart('dd');
265 $this->element('span', 'fn', $this->profile->fullname);
266 $this->elementEnd('dd');
267 $this->elementEnd('dl');
270 if ($this->profile->location) {
271 $this->elementStart('dl', 'entity_location');
272 $this->element('dt', null, _('Location'));
273 $this->element('dd', 'location', $this->profile->location);
274 $this->elementEnd('dl');
277 if ($this->profile->homepage) {
278 $this->elementStart('dl', 'entity_url');
279 $this->element('dt', null, _('URL'));
280 $this->elementStart('dd');
281 $this->element('a', array('href' => $this->profile->homepage,
282 'rel' => 'me', 'class' => 'url'),
283 $this->profile->homepage);
284 $this->elementEnd('dd');
285 $this->elementEnd('dl');
288 if ($this->profile->bio) {
289 $this->elementStart('dl', 'entity_note');
290 $this->element('dt', null, _('Note'));
291 $this->element('dd', 'note', $this->profile->bio);
292 $this->elementEnd('dl');
295 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
296 if (count($tags) > 0) {
297 $this->elementStart('dl', 'entity_tags');
298 $this->element('dt', null, _('Tags'));
299 $this->elementStart('dd');
300 $this->elementStart('ul', 'tags xoxo');
301 foreach ($tags as $tag) {
302 $this->elementStart('li');
303 $this->element('span', 'mark_hash', '#');
304 $this->element('a', array('rel' => 'tag',
305 'href' => common_local_url('peopletag',
306 array('tag' => $tag))),
308 $this->elementEnd('li');
310 $this->elementEnd('ul');
311 $this->elementEnd('dd');
312 $this->elementEnd('dl');
314 $this->elementEnd('div');
316 $this->elementStart('div', 'entity_actions');
317 $this->element('h2', null, _('User actions'));
318 $this->elementStart('ul');
319 $cur = common_current_user();
321 if ($cur && $cur->id == $this->profile->id) {
322 $this->elementStart('li', 'entity_edit');
323 $this->element('a', array('href' => common_local_url('profilesettings'),
324 'title' => _('Edit profile settings')),
326 $this->elementEnd('li');
330 if ($cur->id != $this->profile->id) {
331 $this->elementStart('li', 'entity_subscribe');
332 if ($cur->isSubscribed($this->profile)) {
333 $usf = new UnsubscribeForm($this, $this->profile);
336 $sf = new SubscribeForm($this, $this->profile);
339 $this->elementEnd('li');
342 $this->elementStart('li', 'entity_subscribe');
343 $this->showRemoteSubscribeLink();
344 $this->elementEnd('li');
347 $user = User::staticGet('id', $this->profile->id);
348 if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
349 $this->elementStart('li', 'entity_send-a-message');
350 $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
351 'title' => _('Send a direct message to this user')),
353 $this->elementEnd('li');
355 if ($user->email && $user->emailnotifynudge) {
356 $this->elementStart('li', 'entity_nudge');
357 $nf = new NudgeForm($this, $user);
359 $this->elementEnd('li');
363 if ($cur && $cur->id != $this->profile->id) {
364 $blocked = $cur->hasBlocked($this->profile);
365 $this->elementStart('li', 'entity_block');
367 $ubf = new UnblockForm($this, $this->profile);
370 $bf = new BlockForm($this, $this->profile);
373 $this->elementEnd('li');
375 $this->elementEnd('ul');
376 $this->elementEnd('div');
379 function showRemoteSubscribeLink()
381 $url = common_local_url('remotesubscribe',
382 array('nickname' => $this->profile->nickname));
383 $this->element('a', array('href' => $url,
384 'class' => 'entity_remote_subscribe'),
388 function showNotices()
390 $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
392 $pnl = new ProfileNoticeList($notice, $this);
395 $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
396 'showstream', array('nickname' => $this->user->nickname));
399 function showSections()
401 $this->showSubscriptions();
402 $this->showSubscribers();
404 $this->showStatistics();
405 $cloud = new PersonalTagCloudSection($this, $this->user);
409 function showSubscriptions()
411 $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
413 $this->elementStart('div', array('id' => 'entity_subscriptions',
414 'class' => 'section'));
416 $this->element('h2', null, _('Subscriptions'));
419 $pml = new ProfileMiniList($profile, $this->user, $this);
422 $this->element('p', null, _('(None)'));
426 if ($cnt > PROFILES_PER_MINILIST) {
427 $this->elementStart('p');
428 $this->element('a', array('href' => common_local_url('subscriptions',
429 array('nickname' => $this->profile->nickname)),
431 _('All subscriptions'));
432 $this->elementEnd('p');
435 $this->elementEnd('div');
438 function showSubscribers()
440 $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
442 $this->elementStart('div', array('id' => 'entity_subscribers',
443 'class' => 'section'));
445 $this->element('h2', null, _('Subscribers'));
448 $pml = new ProfileMiniList($profile, $this->user, $this);
451 $this->element('p', null, _('(None)'));
455 if ($cnt > PROFILES_PER_MINILIST) {
456 $this->elementStart('p');
457 $this->element('a', array('href' => common_local_url('subscribers',
458 array('nickname' => $this->profile->nickname)),
460 _('All subscribers'));
461 $this->elementEnd('p');
464 $this->elementEnd('div');
467 function showStatistics()
469 // XXX: WORM cache this
470 $subs = new Subscription();
471 $subs->subscriber = $this->profile->id;
472 $subs_count = (int) $subs->count() - 1;
474 $subbed = new Subscription();
475 $subbed->subscribed = $this->profile->id;
476 $subbed_count = (int) $subbed->count() - 1;
478 $notices = new Notice();
479 $notices->profile_id = $this->profile->id;
480 $notice_count = (int) $notices->count();
482 $this->elementStart('div', array('id' => 'entity_statistics',
483 'class' => 'section'));
485 $this->element('h2', null, _('Statistics'));
488 $this->elementStart('dl', 'entity_member-since');
489 $this->element('dt', null, _('Member since'));
490 $this->element('dd', null, date('j M Y',
491 strtotime($this->profile->created)));
492 $this->elementEnd('dl');
494 $this->elementStart('dl', 'entity_subscriptions');
495 $this->elementStart('dt');
496 $this->element('a', array('href' => common_local_url('subscriptions',
497 array('nickname' => $this->profile->nickname))),
499 $this->elementEnd('dt');
500 $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
501 $this->elementEnd('dl');
503 $this->elementStart('dl', 'entity_subscribers');
504 $this->elementStart('dt');
505 $this->element('a', array('href' => common_local_url('subscribers',
506 array('nickname' => $this->profile->nickname))),
508 $this->elementEnd('dt');
509 $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
510 $this->elementEnd('dl');
512 $this->elementStart('dl', 'entity_notices');
513 $this->element('dt', null, _('Notices'));
514 $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
515 $this->elementEnd('dl');
517 $this->elementEnd('div');
520 function showGroups()
522 $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
524 $this->elementStart('div', array('id' => 'entity_groups',
525 'class' => 'section'));
527 $this->element('h2', null, _('Groups'));
530 $gml = new GroupMiniList($groups, $this->user, $this);
533 $this->element('p', null, _('(None)'));
537 if ($cnt > GROUPS_PER_MINILIST) {
538 $this->elementStart('p');
539 $this->element('a', array('href' => common_local_url('usergroups',
540 array('nickname' => $this->profile->nickname)),
543 $this->elementEnd('p');
546 $this->elementEnd('div');
549 function showAnonymousMessage()
551 $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
552 'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
553 '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
554 $this->user->nickname, $this->user->nickname);
555 $this->elementStart('div', array('id' => 'anon_notice'));
556 $this->raw(common_markup_to_html($m));
557 $this->elementEnd('div');
562 // We don't show the author for a profile, since we already know who it is!
564 class ProfileNoticeList extends NoticeList
566 function newListItem($notice)
568 return new ProfileNoticeListItem($notice, $this->out);
572 class ProfileNoticeListItem extends NoticeListItem
574 function showAuthor()