3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/stream.php');
24 define('SUBSCRIPTIONS_PER_ROW', 4);
25 define('SUBSCRIPTIONS', 80);
27 class ShowstreamAction extends StreamAction {
29 function handle($args) {
31 parent::handle($args);
33 $nickname_arg = $this->arg('nickname');
34 $nickname = common_canonical_nickname($nickname_arg);
36 # Permanent redirect on non-canonical nickname
38 if ($nickname_arg != $nickname) {
39 $args = array('nickname' => $nickname);
40 if ($this->arg('page') && $this->arg('page') != 1) {
41 $args['page'] = $this->arg['page'];
43 common_redirect(common_local_url('showstream', $args), 301);
47 $user = User::staticGet('nickname', $nickname);
50 $this->no_such_user();
54 $profile = $user->getProfile();
57 common_server_error(_('User has no profile.'));
61 # Looks like we're good; start output
63 # For YADIS discovery, we also have a <meta> tag
65 header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
68 common_show_header($profile->nickname,
69 array($this, 'show_header'), $user,
70 array($this, 'show_top'));
72 $this->show_profile($profile);
74 $this->show_notices($user);
79 function show_top($user) {
80 $cur = common_current_user();
82 if ($cur && $cur->id == $user->id) {
83 common_notice_form('showstream');
88 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('nickname' => $user->nickname)),
90 'version' => 'RSS 1.0',
92 1=>array('href'=>common_local_url('usertimeline', array('nickname' => $user->nickname)),
94 'version' => 'Atom 1.0',
95 'item' => 'usertimeline'),
97 2=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
103 function show_header($user) {
105 common_element('link', array('rel' => 'alternate',
106 'href' => common_local_url('api',
107 array('apiaction' => 'statuses',
108 'method' => 'user_timeline.rss',
109 'argument' => $user->nickname)),
110 'type' => 'application/rss+xml',
111 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
112 common_element('link', array('rel' => 'alternate feed',
113 'href' => common_local_url('api',
114 array('apiaction' => 'statuses',
115 'method' => 'user_timeline.atom',
116 'argument' => $user->nickname)),
117 'type' => 'application/atom+xml',
118 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
119 common_element('link', array('rel' => 'alternate',
120 'href' => common_local_url('userrss', array('nickname' =>
122 'type' => 'application/rdf+xml',
123 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
125 common_element('link', array('rel' => 'meta',
126 'href' => common_local_url('foaf', array('nickname' =>
128 'type' => 'application/rdf+xml',
130 # for remote subscriptions etc.
131 common_element('meta', array('http-equiv' => 'X-XRDS-Location',
132 'content' => common_local_url('xrds', array('nickname' =>
134 $profile = $user->getProfile();
136 common_element('meta', array('name' => 'description',
137 'content' => $profile->bio));
140 if ($user->emailmicroid && $user->email && $profile->profileurl) {
141 common_element('meta', array('name' => 'microid',
142 'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($profile->profileurl))));
144 if ($user->jabbermicroid && $user->jabber && $profile->profileurl) {
145 common_element('meta', array('name' => 'microid',
146 'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($profile->profileurl))));
149 # See https://wiki.mozilla.org/Microsummaries
151 common_element('link', array('rel' => 'microsummary',
152 'href' => common_local_url('microsummary',
153 array('nickname' => $profile->nickname))));
156 function no_such_user() {
157 $this->client_error(_('No such user.'), 404);
160 function show_profile($profile) {
162 common_element_start('div', array('id' => 'profile', 'class' => 'vcard'));
164 $this->show_personal($profile);
166 $this->show_last_notice($profile);
168 $cur = common_current_user();
170 $this->show_subscriptions($profile);
172 common_element_end('div');
175 function show_personal($profile) {
177 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
178 common_element_start('div', array('id' => 'profile_avatar'));
179 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
180 'class' => 'avatar profile photo',
181 'width' => AVATAR_PROFILE_SIZE,
182 'height' => AVATAR_PROFILE_SIZE,
183 'alt' => $profile->nickname));
185 common_element_start('ul', array('id' => 'profile_actions'));
187 common_element_start('li', array('id' => 'profile_subscribe'));
188 $cur = common_current_user();
190 if ($cur->id != $profile->id) {
191 if ($cur->isSubscribed($profile)) {
192 common_unsubscribe_form($profile);
194 common_subscribe_form($profile);
198 $this->show_remote_subscribe_link($profile);
200 common_element_end('li');
202 $user = User::staticGet('id', $profile->id);
203 common_profile_new_message_nudge($cur, $user, $profile);
205 common_element_end('ul');
207 common_element_end('div');
209 common_element_start('div', array('id' => 'profile_information'));
211 if ($profile->fullname) {
212 common_element('h1', array('class' => 'fn'), $profile->fullname . ' (' . $profile->nickname . ')');
214 common_element('h1', array('class' => 'fn nickname'), $profile->nickname);
217 if ($profile->location) {
218 common_element('p', 'location', $profile->location);
221 common_element('p', 'description note', $profile->bio);
223 if ($profile->homepage) {
224 common_element_start('p', 'website');
225 common_element('a', array('href' => $profile->homepage,
226 'rel' => 'me', 'class' => 'url'),
228 common_element_end('p');
231 $this->show_statistics($profile);
233 common_element_end('div');
236 function show_remote_subscribe_link($profile) {
237 $url = common_local_url('remotesubscribe',
238 array('nickname' => $profile->nickname));
239 common_element('a', array('href' => $url,
240 'id' => 'remotesubscribe'),
244 function show_unsubscribe_form($profile) {
245 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'post',
246 'action' => common_local_url('unsubscribe')));
247 common_hidden('token', common_session_token());
248 common_element('input', array('id' => 'unsubscribeto',
249 'name' => 'unsubscribeto',
251 'value' => $profile->nickname));
252 common_element('input', array('type' => 'submit',
254 'value' => _('Unsubscribe')));
255 common_element_end('form');
258 function show_subscriptions($profile) {
261 $subs = DB_DataObject::factory('subscription');
262 $subs->subscriber = $profile->id;
263 $subs->whereAdd('subscribed != ' . $profile->id);
265 $subs->orderBy('created DESC');
267 # We ask for an extra one to know if we need to do another page
269 $subs->limit(0, SUBSCRIPTIONS + 1);
271 $subs_count = $subs->find();
273 common_element_start('div', array('id' => 'subscriptions'));
275 common_element('h2', NULL, _('Subscriptions'));
277 if ($subs_count > 0) {
279 common_element_start('ul', array('id' => 'subscriptions_avatars'));
281 for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
283 if (!$subs->fetch()) {
284 common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
288 $other = Profile::staticGet($subs->subscribed);
291 common_log_db_error($subs, 'SELECT', __FILE__);
295 common_element_start('li', 'vcard');
296 common_element_start('a', array('title' => ($other->fullname) ?
299 'href' => $other->profileurl,
301 'class' => 'subscription fn url'));
302 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
303 common_element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
304 'width' => AVATAR_MINI_SIZE,
305 'height' => AVATAR_MINI_SIZE,
306 'class' => 'avatar mini photo',
307 'alt' => ($other->fullname) ?
310 common_element_end('a');
311 common_element_end('li');
314 common_element_end('ul');
317 if ($subs_count > SUBSCRIPTIONS) {
318 common_element_start('p', array('id' => 'subscriptions_viewall'));
320 common_element('a', array('href' => common_local_url('subscriptions',
321 array('nickname' => $profile->nickname)),
322 'class' => 'moresubscriptions'),
323 _('All subscriptions'));
324 common_element_end('p');
327 common_element_end('div');
330 function show_statistics($profile) {
332 // XXX: WORM cache this
333 $subs = DB_DataObject::factory('subscription');
334 $subs->subscriber = $profile->id;
335 $subs_count = (int) $subs->count() - 1;
337 $subbed = DB_DataObject::factory('subscription');
338 $subbed->subscribed = $profile->id;
339 $subbed_count = (int) $subbed->count() - 1;
341 $notices = DB_DataObject::factory('notice');
342 $notices->profile_id = $profile->id;
343 $notice_count = (int) $notices->count();
345 common_element_start('div', 'statistics');
346 common_element('h2', 'statistics', _('Statistics'));
349 common_element_start('dl', 'statistics');
350 common_element('dt', 'membersince', _('Member since'));
351 common_element('dd', 'membersince', date('j M Y',
352 strtotime($profile->created)));
354 common_element_start('dt', 'subscriptions');
355 common_element('a', array('href' => common_local_url('subscriptions',
356 array('nickname' => $profile->nickname))),
358 common_element_end('dt');
359 common_element('dd', 'subscriptions', (is_int($subs_count)) ? $subs_count : '0');
360 common_element_start('dt', 'subscribers');
361 common_element('a', array('href' => common_local_url('subscribers',
362 array('nickname' => $profile->nickname))),
364 common_element_end('dt');
365 common_element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
366 common_element('dt', 'notices', _('Notices'));
367 common_element('dd', 'notices', (is_int($notice_count)) ? $notice_count : '0');
368 # XXX: link these to something
369 common_element('dt', 'tags', _('Tags'));
370 common_element_start('dd', 'tags');
371 $tags = Profile_tag::getTags($profile->id, $profile->id);
373 common_element_start('ul', 'tags xoxo');
374 foreach ($tags as $tag) {
375 common_element_start('li');
376 common_element('a', array('rel' => 'bookmark tag',
377 'href' => common_local_url('peopletag',
378 array('tag' => $tag))),
380 common_element_end('li');
382 common_element_end('ul');
383 common_element_end('dd');
385 common_element_end('dl');
387 common_element_end('div');
390 function show_notices($user) {
392 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
394 $notice = $user->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
400 common_element_start('ul', array('id' => 'notices'));
402 while ($notice->fetch()) {
404 if ($cnt > NOTICES_PER_PAGE) {
407 $this->show_notice($notice);
410 common_element_end('ul');
413 common_pagination($page>1, $cnt>NOTICES_PER_PAGE, $page,
414 'showstream', array('nickname' => $user->nickname));
417 function show_last_notice($profile) {
419 common_element('h2', NULL, _('Currently'));
421 $notice = $profile->getCurrentNotice();
424 # FIXME: URL, image, video, audio
425 common_element_start('p', array('class' => 'notice_current'));
426 if ($notice->rendered) {
427 common_raw($notice->rendered);
429 # XXX: may be some uncooked notices in the DB,
430 # we cook them right now. This can probably disappear in future
431 # versions (>> 0.4.x)
432 common_raw(common_render_content($notice->content, $notice));
434 common_element_end('p');
438 function show_notice($notice) {
439 $profile = $notice->getProfile();
440 $user = common_current_user();
443 common_element_start('li', array('class' => 'notice_single hentry',
444 'id' => 'notice-' . $notice->id));
446 if ($user->hasFave($notice)) {
447 common_disfavor_form($notice);
449 common_favor_form($notice);
452 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
453 # FIXME: URL, image, video, audio
454 common_element_start('p', 'entry-title');
455 if ($notice->rendered) {
456 common_raw($notice->rendered);
458 # XXX: may be some uncooked notices in the DB,
459 # we cook them right now. This can probably disappear in future
460 # versions (>> 0.4.x)
461 common_raw(common_render_content($notice->content, $notice));
463 common_element_end('p');
464 common_element_start('p', array('class' => 'time'));
465 common_element_start('a', array('class' => 'permalink',
467 'href' => $noticeurl));
468 common_element('abbr', array('class' => 'published',
469 'title' => common_date_iso8601($notice->created)),
470 common_date_string($notice->created));
471 common_element_end('a');
473 if ($notice->source) {
474 common_text(_(' from '));
475 $this->source_link($notice->source);
477 if ($notice->reply_to) {
478 $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
480 common_element('a', array('class' => 'inreplyto',
481 'href' => $replyurl),
482 _('in reply to...'));
485 common_element_start('a',
486 array('href' => common_local_url('newnotice',
487 array('replyto' => $profile->nickname)),
488 'onclick' => 'doreply("'.$profile->nickname.'"); return false',
489 'title' => _('reply'),
490 'class' => 'replybutton'));
491 common_raw('→');
492 common_element_end('a');
493 if ($user && $notice->profile_id == $user->id) {
494 $deleteurl = common_local_url('deletenotice', array('notice' => $notice->id));
495 common_element_start('a', array('class' => 'deletenotice',
496 'href' => $deleteurl,
497 'title' => _('delete')));
498 common_raw('×');
499 common_element_end('a');
502 common_element_end('p');
503 common_element_end('li');