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 = common_canonical_nickname($this->arg('nickname'));
34 $user = User::staticGet('nickname', $nickname);
37 $this->no_such_user();
41 $profile = $user->getProfile();
44 common_server_error(_('User has no profile.'));
48 # Looks like we're good; start output
50 # For YADIS discovery, we also have a <meta> tag
52 header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
55 common_show_header($profile->nickname,
56 array($this, 'show_header'), $user,
57 array($this, 'show_top'));
59 $this->show_profile($profile);
61 $this->show_notices($user);
66 function show_top($user) {
68 $cur = common_current_user();
70 if ($cur && $cur->id == $user->id) {
71 common_notice_form('showstream');
76 $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('nickname' => $user->nickname)),
78 'version' => 'RSS 1.0',
80 1=>array('href'=>common_local_url('usertimeline', array('nickname' => $user->nickname)),
82 'version' => 'Atom 1.0',
83 'item' => 'usertimeline'),
85 2=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
94 function show_header($user) {
96 common_element('link', array('rel' => 'alternate',
97 'href' => common_local_url('api',
98 array('apiaction' => 'statuses',
99 'method' => 'user_timeline.rss',
100 'argument' => $user->nickname)),
101 'type' => 'application/rss+xml',
102 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
103 common_element('link', array('rel' => 'alternate feed',
104 'href' => common_local_url('api',
105 array('apiaction' => 'statuses',
106 'method' => 'user_timeline.atom',
107 'argument' => $user->nickname)),
108 'type' => 'application/atom+xml',
109 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
110 common_element('link', array('rel' => 'alternate',
111 'href' => common_local_url('userrss', array('nickname' =>
113 'type' => 'application/rdf+xml',
114 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
116 common_element('link', array('rel' => 'meta',
117 'href' => common_local_url('foaf', array('nickname' =>
119 'type' => 'application/rdf+xml',
121 # for remote subscriptions etc.
122 common_element('meta', array('http-equiv' => 'X-XRDS-Location',
123 'content' => common_local_url('xrds', array('nickname' =>
125 $profile = $user->getProfile();
127 common_element('meta', array('name' => 'description',
128 'content' => $profile->bio));
131 if ($user->emailmicroid && $user->email && $profile->profileurl) {
132 common_element('meta', array('name' => 'microid',
133 'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($profile->profileurl))));
135 if ($user->jabbermicroid && $user->jabber && $profile->profileurl) {
136 common_element('meta', array('name' => 'microid',
137 'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($profile->profileurl))));
142 function no_such_user() {
143 $this->client_error(_('No such user.'), 404);
146 function show_profile($profile) {
148 common_element_start('div', array('id' => 'profile'));
150 $this->show_personal($profile);
152 $this->show_last_notice($profile);
154 $cur = common_current_user();
156 $this->show_subscriptions($profile);
158 common_element_end('div');
161 function show_personal($profile) {
163 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
164 common_element_start('div', array('id' => 'profile_avatar'));
165 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
166 'class' => 'avatar profile',
167 'width' => AVATAR_PROFILE_SIZE,
168 'height' => AVATAR_PROFILE_SIZE,
169 'alt' => $profile->nickname));
170 $cur = common_current_user();
172 if ($cur->id != $profile->id) {
173 if ($cur->isSubscribed($profile)) {
174 $this->show_unsubscribe_form($profile);
176 $this->show_subscribe_form($profile);
180 $this->show_remote_subscribe_link($profile);
183 $user = User::staticGet('id', $profile->id);
185 if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
186 common_element('a', array('href' => common_local_url('newmessage', array('to' => $user->id))),
187 _('Send a message'));
190 common_element_end('div');
192 common_element_start('div', array('id' => 'profile_information'));
194 if ($profile->fullname) {
195 common_element('h1', NULL, $profile->fullname . ' (' . $profile->nickname . ')');
197 common_element('h1', NULL, $profile->nickname);
201 if ($profile->location) {
202 common_element('p', 'location', $profile->location);
205 common_element('p', 'description', $profile->bio);
207 if ($profile->homepage) {
208 common_element_start('p', 'website');
209 common_element('a', array('href' => $profile->homepage,
212 common_element_end('p');
215 $this->show_statistics($profile);
217 common_element_end('div');
220 function show_subscribe_form($profile) {
221 common_element_start('form', array('id' => 'subscribe', 'method' => 'post',
222 'action' => common_local_url('subscribe')));
223 common_hidden('token', common_session_token());
224 common_element('input', array('id' => 'subscribeto',
225 'name' => 'subscribeto',
227 'value' => $profile->nickname));
228 common_element('input', array('type' => 'submit',
230 'value' => _('Subscribe')));
231 common_element_end('form');
234 function show_remote_subscribe_link($profile) {
235 $url = common_local_url('remotesubscribe',
236 array('nickname' => $profile->nickname));
237 common_element('a', array('href' => $url,
238 'id' => 'remotesubscribe'),
242 function show_unsubscribe_form($profile) {
243 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'post',
244 'action' => common_local_url('unsubscribe')));
245 common_hidden('token', common_session_token());
246 common_element('input', array('id' => 'unsubscribeto',
247 'name' => 'unsubscribeto',
249 'value' => $profile->nickname));
250 common_element('input', array('type' => 'submit',
252 'value' => _('Unsubscribe')));
253 common_element_end('form');
256 function show_subscriptions($profile) {
259 $subs = DB_DataObject::factory('subscription');
260 $subs->subscriber = $profile->id;
261 $subs->whereAdd('subscribed != ' . $profile->id);
263 $subs->orderBy('created DESC');
265 # We ask for an extra one to know if we need to do another page
267 $subs->limit(0, SUBSCRIPTIONS + 1);
269 $subs_count = $subs->find();
271 common_element_start('div', array('id' => 'subscriptions'));
273 common_element('h2', NULL, _('Subscriptions'));
275 if ($subs_count > 0) {
277 common_element_start('ul', array('id' => 'subscriptions_avatars'));
279 for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
281 if (!$subs->fetch()) {
282 common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
286 $other = Profile::staticGet($subs->subscribed);
289 common_log_db_error($subs, 'SELECT', __FILE__);
293 common_element_start('li');
294 common_element_start('a', array('title' => ($other->fullname) ?
297 'href' => $other->profileurl,
299 'class' => 'subscription'));
300 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
301 common_element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
302 'width' => AVATAR_MINI_SIZE,
303 'height' => AVATAR_MINI_SIZE,
304 'class' => 'avatar mini',
305 'alt' => ($other->fullname) ?
308 common_element_end('a');
309 common_element_end('li');
312 common_element_end('ul');
315 if ($subs_count > SUBSCRIPTIONS) {
316 common_element_start('p', array('id' => 'subscriptions_viewall'));
318 common_element('a', array('href' => common_local_url('subscriptions',
319 array('nickname' => $profile->nickname)),
320 'class' => 'moresubscriptions'),
321 _('All subscriptions'));
322 common_element_end('p');
325 common_element_end('div');
328 function show_statistics($profile) {
330 // XXX: WORM cache this
331 $subs = DB_DataObject::factory('subscription');
332 $subs->subscriber = $profile->id;
333 $subs_count = (int) $subs->count() - 1;
335 $subbed = DB_DataObject::factory('subscription');
336 $subbed->subscribed = $profile->id;
337 $subbed_count = (int) $subbed->count() - 1;
339 $notices = DB_DataObject::factory('notice');
340 $notices->profile_id = $profile->id;
341 $notice_count = (int) $notices->count();
343 common_element_start('div', 'statistics');
344 common_element('h2', 'statistics', _('Statistics'));
347 common_element_start('dl', 'statistics');
348 common_element('dt', 'membersince', _('Member since'));
349 common_element('dd', 'membersince', date('j M Y',
350 strtotime($profile->created)));
352 common_element_start('dt', 'subscriptions');
353 common_element('a', array('href' => common_local_url('subscriptions',
354 array('nickname' => $profile->nickname))),
356 common_element_end('dt');
357 common_element('dd', 'subscriptions', (is_int($subs_count)) ? $subs_count : '0');
358 common_element_start('dt', 'subscribers');
359 common_element('a', array('href' => common_local_url('subscribers',
360 array('nickname' => $profile->nickname))),
362 common_element_end('dt');
363 common_element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
364 common_element('dt', 'notices', _('Notices'));
365 common_element('dd', 'notices', (is_int($notice_count)) ? $notice_count : '0');
366 common_element_end('dl');
368 common_element_end('div');
371 function show_notices($user) {
373 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
375 $notice = $user->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
381 common_element_start('ul', array('id' => 'notices'));
383 while ($notice->fetch()) {
385 if ($cnt > NOTICES_PER_PAGE) {
388 $this->show_notice($notice);
391 common_element_end('ul');
394 common_pagination($page>1, $cnt>NOTICES_PER_PAGE, $page,
395 'showstream', array('nickname' => $user->nickname));
398 function show_last_notice($profile) {
400 common_element('h2', NULL, _('Currently'));
402 $notice = $profile->getCurrentNotice();
405 # FIXME: URL, image, video, audio
406 common_element_start('p', array('class' => 'notice_current'));
407 if ($notice->rendered) {
408 common_raw($notice->rendered);
410 # XXX: may be some uncooked notices in the DB,
411 # we cook them right now. This can probably disappear in future
412 # versions (>> 0.4.x)
413 common_raw(common_render_content($notice->content, $notice));
415 common_element_end('p');
419 function show_notice($notice) {
420 $profile = $notice->getProfile();
421 $user = common_current_user();
424 common_element_start('li', array('class' => 'notice_single',
425 'id' => 'notice-' . $notice->id));
427 if ($user->hasFave($notice)) {
428 common_disfavor_form($notice);
430 common_favor_form($notice);
433 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
434 # FIXME: URL, image, video, audio
435 common_element_start('p');
436 if ($notice->rendered) {
437 common_raw($notice->rendered);
439 # XXX: may be some uncooked notices in the DB,
440 # we cook them right now. This can probably disappear in future
441 # versions (>> 0.4.x)
442 common_raw(common_render_content($notice->content, $notice));
444 common_element_end('p');
445 common_element_start('p', array('class' => 'time'));
446 common_element('a', array('class' => 'permalink',
447 'href' => $noticeurl,
448 'title' => common_exact_date($notice->created)),
449 common_date_string($notice->created));
450 if ($notice->source) {
451 common_text(_(' from '));
452 $this->source_link($notice->source);
454 if ($notice->reply_to) {
455 $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
457 common_element('a', array('class' => 'inreplyto',
458 'href' => $replyurl),
459 _('in reply to...'));
462 common_element_start('a',
463 array('href' => common_local_url('newnotice',
464 array('replyto' => $profile->nickname)),
465 'onclick' => 'doreply("'.$profile->nickname.'"); return false',
466 'title' => _('reply'),
467 'class' => 'replybutton'));
468 common_raw('→');
469 common_element_end('a');
470 if ($user && $notice->profile_id == $user->id) {
471 $deleteurl = common_local_url('deletenotice', array('notice' => $notice->id));
472 common_element_start('a', array('class' => 'deletenotice',
473 'href' => $deleteurl,
474 'title' => _('delete')));
475 common_raw('×');
476 common_element_end('a');
478 common_element_end('p');
479 common_element_end('li');