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');
251 $this->elementEnd('dl');
253 $this->elementStart('dl', 'entity_nickname');
254 $this->element('dt', null, _('Nickname'));
255 $this->elementStart('dd');
256 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
257 $this->element('a', array('href' => $this->profile->profileurl,
258 'rel' => 'me', 'class' => $hasFN),
259 $this->profile->nickname);
260 $this->elementEnd('dd');
261 $this->elementEnd('dl');
263 if ($this->profile->fullname) {
264 $this->elementStart('dl', 'entity_fn');
265 $this->element('dt', null, _('Full name'));
266 $this->elementStart('dd');
267 $this->element('span', 'fn', $this->profile->fullname);
268 $this->elementEnd('dd');
269 $this->elementEnd('dl');
272 if ($this->profile->location) {
273 $this->elementStart('dl', 'entity_location');
274 $this->element('dt', null, _('Location'));
275 $this->element('dd', 'location', $this->profile->location);
276 $this->elementEnd('dl');
279 if ($this->profile->homepage) {
280 $this->elementStart('dl', 'entity_url');
281 $this->element('dt', null, _('URL'));
282 $this->elementStart('dd');
283 $this->element('a', array('href' => $this->profile->homepage,
284 'rel' => 'me', 'class' => 'url'),
285 $this->profile->homepage);
286 $this->elementEnd('dd');
287 $this->elementEnd('dl');
290 if ($this->profile->bio) {
291 $this->elementStart('dl', 'entity_note');
292 $this->element('dt', null, _('Note'));
293 $this->element('dd', 'note', $this->profile->bio);
294 $this->elementEnd('dl');
297 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
298 if (count($tags) > 0) {
299 $this->elementStart('dl', 'entity_tags');
300 $this->element('dt', null, _('Tags'));
301 $this->elementStart('dd');
302 $this->elementStart('ul', 'tags xoxo');
303 foreach ($tags as $tag) {
304 $this->elementStart('li');
305 $this->element('span', 'mark_hash', '#');
306 $this->element('a', array('rel' => 'tag',
307 'href' => common_local_url('peopletag',
308 array('tag' => $tag))),
310 $this->elementEnd('li');
312 $this->elementEnd('ul');
313 $this->elementEnd('dd');
314 $this->elementEnd('dl');
316 $this->elementEnd('div');
318 $this->elementStart('div', 'entity_actions');
319 $this->element('h2', null, _('User actions'));
320 $this->elementStart('ul');
321 $cur = common_current_user();
323 if ($cur && $cur->id == $this->profile->id) {
324 $this->elementStart('li', 'entity_edit');
325 $this->element('a', array('href' => common_local_url('profilesettings'),
326 'title' => _('Edit profile settings')),
328 $this->elementEnd('li');
332 if ($cur->id != $this->profile->id) {
333 $this->elementStart('li', 'entity_subscribe');
334 if ($cur->isSubscribed($this->profile)) {
335 $usf = new UnsubscribeForm($this, $this->profile);
338 $sf = new SubscribeForm($this, $this->profile);
341 $this->elementEnd('li');
344 $this->elementStart('li', 'entity_subscribe');
345 $this->showRemoteSubscribeLink();
346 $this->elementEnd('li');
349 $user = User::staticGet('id', $this->profile->id);
350 if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
351 $this->elementStart('li', 'entity_send-a-message');
352 $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
353 'title' => _('Send a direct message to this user')),
355 $this->elementEnd('li');
357 if ($user->email && $user->emailnotifynudge) {
358 $this->elementStart('li', 'entity_nudge');
359 $nf = new NudgeForm($this, $user);
361 $this->elementEnd('li');
365 if ($cur && $cur->id != $this->profile->id) {
366 $blocked = $cur->hasBlocked($this->profile);
367 $this->elementStart('li', 'entity_block');
369 $ubf = new UnblockForm($this, $this->profile);
372 $bf = new BlockForm($this, $this->profile);
375 $this->elementEnd('li');
377 $this->elementEnd('ul');
378 $this->elementEnd('div');
381 function showRemoteSubscribeLink()
383 $url = common_local_url('remotesubscribe',
384 array('nickname' => $this->profile->nickname));
385 $this->element('a', array('href' => $url,
386 'class' => 'entity_remote_subscribe'),
390 function showNotices()
392 $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
394 $pnl = new ProfileNoticeList($notice, $this);
397 $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
398 'showstream', array('nickname' => $this->user->nickname));
401 function showSections()
403 $this->showSubscriptions();
404 $this->showSubscribers();
406 $this->showStatistics();
407 $cloud = new PersonalTagCloudSection($this, $this->user);
411 function showSubscriptions()
413 $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
415 $this->elementStart('div', array('id' => 'entity_subscriptions',
416 'class' => 'section'));
418 $this->element('h2', null, _('Subscriptions'));
421 $pml = new ProfileMiniList($profile, $this->user, $this);
424 $this->element('p', null, _('(None)'));
428 if ($cnt > PROFILES_PER_MINILIST) {
429 $this->elementStart('p');
430 $this->element('a', array('href' => common_local_url('subscriptions',
431 array('nickname' => $this->profile->nickname)),
433 _('All subscriptions'));
434 $this->elementEnd('p');
437 $this->elementEnd('div');
440 function showSubscribers()
442 $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
444 $this->elementStart('div', array('id' => 'entity_subscribers',
445 'class' => 'section'));
447 $this->element('h2', null, _('Subscribers'));
450 $pml = new ProfileMiniList($profile, $this->user, $this);
453 $this->element('p', null, _('(None)'));
457 if ($cnt > PROFILES_PER_MINILIST) {
458 $this->elementStart('p');
459 $this->element('a', array('href' => common_local_url('subscribers',
460 array('nickname' => $this->profile->nickname)),
462 _('All subscribers'));
463 $this->elementEnd('p');
466 $this->elementEnd('div');
469 function showStatistics()
471 // XXX: WORM cache this
472 $subs = new Subscription();
473 $subs->subscriber = $this->profile->id;
474 $subs_count = (int) $subs->count() - 1;
476 $subbed = new Subscription();
477 $subbed->subscribed = $this->profile->id;
478 $subbed_count = (int) $subbed->count() - 1;
480 $notices = new Notice();
481 $notices->profile_id = $this->profile->id;
482 $notice_count = (int) $notices->count();
484 $this->elementStart('div', array('id' => 'entity_statistics',
485 'class' => 'section'));
487 $this->element('h2', null, _('Statistics'));
490 $this->elementStart('dl', 'entity_member-since');
491 $this->element('dt', null, _('Member since'));
492 $this->element('dd', null, date('j M Y',
493 strtotime($this->profile->created)));
494 $this->elementEnd('dl');
496 $this->elementStart('dl', 'entity_subscriptions');
497 $this->elementStart('dt');
498 $this->element('a', array('href' => common_local_url('subscriptions',
499 array('nickname' => $this->profile->nickname))),
501 $this->elementEnd('dt');
502 $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
503 $this->elementEnd('dl');
505 $this->elementStart('dl', 'entity_subscribers');
506 $this->elementStart('dt');
507 $this->element('a', array('href' => common_local_url('subscribers',
508 array('nickname' => $this->profile->nickname))),
510 $this->elementEnd('dt');
511 $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
512 $this->elementEnd('dl');
514 $this->elementStart('dl', 'entity_notices');
515 $this->element('dt', null, _('Notices'));
516 $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
517 $this->elementEnd('dl');
519 $this->elementEnd('div');
522 function showGroups()
524 $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
526 $this->elementStart('div', array('id' => 'entity_groups',
527 'class' => 'section'));
529 $this->element('h2', null, _('Groups'));
532 $gml = new GroupMiniList($groups, $this->user, $this);
535 $this->element('p', null, _('(None)'));
539 if ($cnt > GROUPS_PER_MINILIST) {
540 $this->elementStart('p');
541 $this->element('a', array('href' => common_local_url('usergroups',
542 array('nickname' => $this->profile->nickname)),
545 $this->elementEnd('p');
548 $this->elementEnd('div');
551 function showAnonymousMessage()
553 $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
554 'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
555 '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
556 $this->user->nickname, $this->user->nickname);
557 $this->elementStart('div', array('id' => 'anon_notice'));
558 $this->raw(common_markup_to_html($m));
559 $this->elementEnd('div');
564 // We don't show the author for a profile, since we already know who it is!
566 class ProfileNoticeList extends NoticeList
568 function newListItem($notice)
570 return new ProfileNoticeListItem($notice, $this->out);
574 class ProfileNoticeListItem extends NoticeListItem
576 function showAuthor()