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;
113 common_set_returnto($this->selfUrl());
118 function handle($args)
121 // Looks like we're good; start output
123 // For YADIS discovery, we also have a <meta> tag
125 header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
126 $this->user->nickname)));
131 function showContent()
133 $this->showProfile();
134 $this->showNotices();
137 function showLocalNav()
139 $nav = new PersonalGroupNav($this);
143 function showPageTitle()
145 $user =& common_current_user();
146 if ($user && ($user->id == $this->profile->id)) {
147 $this->element('h1', NULL, _("Your profile"));
149 $this->element('h1', NULL, sprintf(_('%s\'s profile'), $this->profile->nickname));
153 function showPageNoticeBlock()
158 function showExportData()
160 $fl = new FeedList($this);
161 $fl->show(array(0=>array('href'=>common_local_url('userrss',
162 array('nickname' => $this->user->nickname)),
164 'version' => 'RSS 1.0',
165 'item' => 'notices'),
166 1=>array('href'=>common_local_url('usertimeline',
167 array('nickname' => $this->user->nickname)),
169 'version' => 'Atom 1.0',
170 'item' => 'usertimeline'),
171 2=>array('href'=>common_local_url('foaf',
172 array('nickname' => $this->user->nickname)),
180 $this->element('link', array('rel' => 'alternate',
181 'type' => 'application/rss+xml',
182 'href' => common_local_url('userrss',
183 array('nickname' => $this->user->nickname)),
184 'title' => sprintf(_('Notice feed for %s (RSS)'),
185 $this->user->nickname)));
187 $this->element('link',
188 array('rel' => 'alternate',
189 'href' => common_local_url('api',
190 array('apiaction' => 'statuses',
191 'method' => 'user_timeline.atom',
192 'argument' => $this->user->nickname)),
193 'type' => 'application/atom+xml',
194 'title' => sprintf(_('Notice feed for %s (Atom)'),
195 $this->user->nickname)));
201 $this->element('link', array('rel' => 'meta',
202 'href' => common_local_url('foaf', array('nickname' =>
203 $this->user->nickname)),
204 'type' => 'application/rdf+xml',
206 // for remote subscriptions etc.
207 $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
208 'content' => common_local_url('xrds', array('nickname' =>
209 $this->user->nickname))));
211 if ($this->profile->bio) {
212 $this->element('meta', array('name' => 'description',
213 'content' => $this->profile->bio));
216 if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
217 $id = new Microid('mailto:'.$this->user->email,
219 $this->element('meta', array('name' => 'microid',
220 'content' => $id->toString()));
222 if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
223 $id = new Microid('xmpp:'.$this->user->jabber,
225 $this->element('meta', array('name' => 'microid',
226 'content' => $id->toString()));
229 // See https://wiki.mozilla.org/Microsummaries
231 $this->element('link', array('rel' => 'microsummary',
232 'href' => common_local_url('microsummary',
233 array('nickname' => $this->profile->nickname))));
236 function showProfile()
238 $this->elementStart('div', 'entity_profile vcard author');
239 $this->element('h2', null, _('User profile'));
241 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
242 $this->elementStart('dl', 'entity_depiction');
243 $this->element('dt', null, _('Photo'));
244 $this->elementStart('dd');
245 $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
246 'class' => 'photo avatar',
247 'width' => AVATAR_PROFILE_SIZE,
248 'height' => AVATAR_PROFILE_SIZE,
249 'alt' => $this->profile->nickname));
250 $this->elementEnd('dd');
252 $user = User::staticGet('id', $this->profile->id);
253 $cur = common_current_user();
254 if ($cur && $cur->id == $user->id) {
255 $this->elementStart('dd');
256 $this->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
257 $this->elementEnd('dd');
260 $this->elementEnd('dl');
262 $this->elementStart('dl', 'entity_nickname');
263 $this->element('dt', null, _('Nickname'));
264 $this->elementStart('dd');
265 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
266 $this->element('a', array('href' => $this->profile->profileurl,
267 'rel' => 'me', 'class' => $hasFN),
268 $this->profile->nickname);
269 $this->elementEnd('dd');
270 $this->elementEnd('dl');
272 if ($this->profile->fullname) {
273 $this->elementStart('dl', 'entity_fn');
274 $this->element('dt', null, _('Full name'));
275 $this->elementStart('dd');
276 $this->element('span', 'fn', $this->profile->fullname);
277 $this->elementEnd('dd');
278 $this->elementEnd('dl');
281 if ($this->profile->location) {
282 $this->elementStart('dl', 'entity_location');
283 $this->element('dt', null, _('Location'));
284 $this->element('dd', 'location', $this->profile->location);
285 $this->elementEnd('dl');
288 if ($this->profile->homepage) {
289 $this->elementStart('dl', 'entity_url');
290 $this->element('dt', null, _('URL'));
291 $this->elementStart('dd');
292 $this->element('a', array('href' => $this->profile->homepage,
293 'rel' => 'me', 'class' => 'url'),
294 $this->profile->homepage);
295 $this->elementEnd('dd');
296 $this->elementEnd('dl');
299 if ($this->profile->bio) {
300 $this->elementStart('dl', 'entity_note');
301 $this->element('dt', null, _('Note'));
302 $this->element('dd', 'note', $this->profile->bio);
303 $this->elementEnd('dl');
306 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
307 if (count($tags) > 0) {
308 $this->elementStart('dl', 'entity_tags');
309 $this->element('dt', null, _('Tags'));
310 $this->elementStart('dd');
311 $this->elementStart('ul', 'tags xoxo');
312 foreach ($tags as $tag) {
313 $this->elementStart('li');
314 $this->element('span', 'mark_hash', '#');
315 $this->element('a', array('rel' => 'tag',
316 'href' => common_local_url('peopletag',
317 array('tag' => $tag))),
319 $this->elementEnd('li');
321 $this->elementEnd('ul');
322 $this->elementEnd('dd');
323 $this->elementEnd('dl');
325 $this->elementEnd('div');
327 $this->elementStart('div', 'entity_actions');
328 $this->element('h2', null, _('User actions'));
329 $this->elementStart('ul');
330 $cur = common_current_user();
332 if ($cur && $cur->id == $this->profile->id) {
333 $this->elementStart('li', 'entity_edit');
334 $this->element('a', array('href' => common_local_url('profilesettings'),
335 'title' => _('Edit profile settings')),
337 $this->elementEnd('li');
341 if ($cur->id != $this->profile->id) {
342 $this->elementStart('li', 'entity_subscribe');
343 if ($cur->isSubscribed($this->profile)) {
344 $usf = new UnsubscribeForm($this, $this->profile);
347 $sf = new SubscribeForm($this, $this->profile);
350 $this->elementEnd('li');
353 $this->elementStart('li', 'entity_subscribe');
354 $this->showRemoteSubscribeLink();
355 $this->elementEnd('li');
358 if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
359 $this->elementStart('li', 'entity_send-a-message');
360 $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
361 'title' => _('Send a direct message to this user')),
363 $this->elementEnd('li');
365 if ($user->email && $user->emailnotifynudge) {
366 $this->elementStart('li', 'entity_nudge');
367 $nf = new NudgeForm($this, $user);
369 $this->elementEnd('li');
373 if ($cur && $cur->id != $this->profile->id) {
374 $blocked = $cur->hasBlocked($this->profile);
375 $this->elementStart('li', 'entity_block');
377 $ubf = new UnblockForm($this, $this->profile);
380 $bf = new BlockForm($this, $this->profile);
383 $this->elementEnd('li');
385 $this->elementEnd('ul');
386 $this->elementEnd('div');
389 function showRemoteSubscribeLink()
391 $url = common_local_url('remotesubscribe',
392 array('nickname' => $this->profile->nickname));
393 $this->element('a', array('href' => $url,
394 'class' => 'entity_remote_subscribe'),
398 function showNotices()
400 $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
402 $pnl = new ProfileNoticeList($notice, $this);
405 $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
406 'showstream', array('nickname' => $this->user->nickname));
409 function showSections()
411 $this->showSubscriptions();
412 $this->showSubscribers();
414 $this->showStatistics();
415 $cloud = new PersonalTagCloudSection($this, $this->user);
419 function showSubscriptions()
421 $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
423 $this->elementStart('div', array('id' => 'entity_subscriptions',
424 'class' => 'section'));
426 $this->element('h2', null, _('Subscriptions'));
429 $pml = new ProfileMiniList($profile, $this->user, $this);
432 $this->element('p', null, _('(None)'));
436 if ($cnt > PROFILES_PER_MINILIST) {
437 $this->elementStart('p');
438 $this->element('a', array('href' => common_local_url('subscriptions',
439 array('nickname' => $this->profile->nickname)),
441 _('All subscriptions'));
442 $this->elementEnd('p');
445 $this->elementEnd('div');
448 function showSubscribers()
450 $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
452 $this->elementStart('div', array('id' => 'entity_subscribers',
453 'class' => 'section'));
455 $this->element('h2', null, _('Subscribers'));
458 $pml = new ProfileMiniList($profile, $this->user, $this);
461 $this->element('p', null, _('(None)'));
465 if ($cnt > PROFILES_PER_MINILIST) {
466 $this->elementStart('p');
467 $this->element('a', array('href' => common_local_url('subscribers',
468 array('nickname' => $this->profile->nickname)),
470 _('All subscribers'));
471 $this->elementEnd('p');
474 $this->elementEnd('div');
477 function showStatistics()
479 // XXX: WORM cache this
480 $subs = new Subscription();
481 $subs->subscriber = $this->profile->id;
482 $subs_count = (int) $subs->count() - 1;
484 $subbed = new Subscription();
485 $subbed->subscribed = $this->profile->id;
486 $subbed_count = (int) $subbed->count() - 1;
488 $notices = new Notice();
489 $notices->profile_id = $this->profile->id;
490 $notice_count = (int) $notices->count();
492 $this->elementStart('div', array('id' => 'entity_statistics',
493 'class' => 'section'));
495 $this->element('h2', null, _('Statistics'));
498 $this->elementStart('dl', 'entity_member-since');
499 $this->element('dt', null, _('Member since'));
500 $this->element('dd', null, date('j M Y',
501 strtotime($this->profile->created)));
502 $this->elementEnd('dl');
504 $this->elementStart('dl', 'entity_subscriptions');
505 $this->elementStart('dt');
506 $this->element('a', array('href' => common_local_url('subscriptions',
507 array('nickname' => $this->profile->nickname))),
509 $this->elementEnd('dt');
510 $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
511 $this->elementEnd('dl');
513 $this->elementStart('dl', 'entity_subscribers');
514 $this->elementStart('dt');
515 $this->element('a', array('href' => common_local_url('subscribers',
516 array('nickname' => $this->profile->nickname))),
518 $this->elementEnd('dt');
519 $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
520 $this->elementEnd('dl');
522 $this->elementStart('dl', 'entity_notices');
523 $this->element('dt', null, _('Notices'));
524 $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
525 $this->elementEnd('dl');
527 $this->elementEnd('div');
530 function showGroups()
532 $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
534 $this->elementStart('div', array('id' => 'entity_groups',
535 'class' => 'section'));
537 $this->element('h2', null, _('Groups'));
540 $gml = new GroupMiniList($groups, $this->user, $this);
543 $this->element('p', null, _('(None)'));
547 if ($cnt > GROUPS_PER_MINILIST) {
548 $this->elementStart('p');
549 $this->element('a', array('href' => common_local_url('usergroups',
550 array('nickname' => $this->profile->nickname)),
553 $this->elementEnd('p');
556 $this->elementEnd('div');
559 function showAnonymousMessage()
561 $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
562 'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
563 '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
564 $this->user->nickname, $this->user->nickname);
565 $this->elementStart('div', array('id' => 'anon_notice'));
566 $this->raw(common_markup_to_html($m));
567 $this->elementEnd('div');
572 // We don't show the author for a profile, since we already know who it is!
574 class ProfileNoticeList extends NoticeList
576 function newListItem($notice)
578 return new ProfileNoticeListItem($notice, $this->out);
582 class ProfileNoticeListItem extends NoticeListItem
584 function showAuthor()