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');
77 function show_header($user) {
79 common_element('link', array('rel' => 'alternate',
80 'href' => common_local_url('api',
81 array('apiaction' => 'statuses',
82 'method' => 'user_timeline.rss',
83 'argument' => $user->nickname)),
84 'type' => 'application/rss+xml',
85 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
86 common_element('link', array('rel' => 'alternate feed',
87 'href' => common_local_url('api',
88 array('apiaction' => 'statuses',
89 'method' => 'user_timeline.atom',
90 'argument' => $user->nickname)),
91 'type' => 'application/atom+xml',
92 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
93 common_element('link', array('rel' => 'alternate',
94 'href' => common_local_url('userrss', array('nickname' =>
96 'type' => 'application/rdf+xml',
97 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
99 common_element('link', array('rel' => 'meta',
100 'href' => common_local_url('foaf', array('nickname' =>
102 'type' => 'application/rdf+xml',
104 # for remote subscriptions etc.
105 common_element('meta', array('http-equiv' => 'X-XRDS-Location',
106 'content' => common_local_url('xrds', array('nickname' =>
108 $profile = $user->getProfile();
110 common_element('meta', array('name' => 'description',
111 'content' => $profile->bio));
114 if ($user->emailmicroid && $user->email && $profile->profileurl) {
115 common_element('meta', array('name' => 'microid',
116 'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($profile->profileurl))));
118 if ($user->jabbermicroid && $user->jabber && $profile->profileurl) {
119 common_element('meta', array('name' => 'microid',
120 'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($profile->profileurl))));
125 function no_such_user() {
126 $this->client_error(_('No such user.'), 404);
129 function show_profile($profile) {
131 common_element_start('div', array('id' => 'profile'));
133 $this->show_personal($profile);
135 $this->show_last_notice($profile);
137 $cur = common_current_user();
139 $this->show_subscriptions($profile);
141 common_element_end('div');
144 function show_personal($profile) {
146 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
147 common_element_start('div', array('id' => 'profile_avatar'));
148 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
149 'class' => 'avatar profile',
150 'width' => AVATAR_PROFILE_SIZE,
151 'height' => AVATAR_PROFILE_SIZE,
152 'alt' => $profile->nickname));
153 $cur = common_current_user();
155 if ($cur->id != $profile->id) {
156 if ($cur->isSubscribed($profile)) {
157 $this->show_unsubscribe_form($profile);
159 $this->show_subscribe_form($profile);
163 $this->show_remote_subscribe_link($profile);
166 $user = User::staticGet('id', $profile->id);
168 if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
169 common_element('a', array('href' => common_local_url('newmessage', array('to' => $user->id))),
170 _('Send a message'));
173 common_element_end('div');
175 common_element_start('div', array('id' => 'profile_information'));
177 if ($profile->fullname) {
178 common_element('h1', NULL, $profile->fullname . ' (' . $profile->nickname . ')');
180 common_element('h1', NULL, $profile->nickname);
184 if ($profile->location) {
185 common_element('p', 'location', $profile->location);
188 common_element('p', 'description', $profile->bio);
190 if ($profile->homepage) {
191 common_element_start('p', 'website');
192 common_element('a', array('href' => $profile->homepage,
195 common_element_end('p');
198 $this->show_statistics($profile);
200 common_element_end('div');
203 function show_subscribe_form($profile) {
204 common_element_start('form', array('id' => 'subscribe', 'method' => 'post',
205 'action' => common_local_url('subscribe')));
206 common_hidden('token', common_session_token());
207 common_element('input', array('id' => 'subscribeto',
208 'name' => 'subscribeto',
210 'value' => $profile->nickname));
211 common_element('input', array('type' => 'submit',
213 'value' => _('Subscribe')));
214 common_element_end('form');
217 function show_remote_subscribe_link($profile) {
218 $url = common_local_url('remotesubscribe',
219 array('nickname' => $profile->nickname));
220 common_element('a', array('href' => $url,
221 'id' => 'remotesubscribe'),
225 function show_unsubscribe_form($profile) {
226 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'post',
227 'action' => common_local_url('unsubscribe')));
228 common_hidden('token', common_session_token());
229 common_element('input', array('id' => 'unsubscribeto',
230 'name' => 'unsubscribeto',
232 'value' => $profile->nickname));
233 common_element('input', array('type' => 'submit',
235 'value' => _('Unsubscribe')));
236 common_element_end('form');
239 function show_subscriptions($profile) {
242 $subs = DB_DataObject::factory('subscription');
243 $subs->subscriber = $profile->id;
244 $subs->whereAdd('subscribed != ' . $profile->id);
246 $subs->orderBy('created DESC');
248 # We ask for an extra one to know if we need to do another page
250 $subs->limit(0, SUBSCRIPTIONS + 1);
252 $subs_count = $subs->find();
254 common_element_start('div', array('id' => 'subscriptions'));
256 common_element('h2', NULL, _('Subscriptions'));
258 if ($subs_count > 0) {
260 common_element_start('ul', array('id' => 'subscriptions_avatars'));
262 for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
264 if (!$subs->fetch()) {
265 common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
269 $other = Profile::staticGet($subs->subscribed);
272 common_log_db_error($subs, 'SELECT', __FILE__);
276 common_element_start('li');
277 common_element_start('a', array('title' => ($other->fullname) ?
280 'href' => $other->profileurl,
282 'class' => 'subscription'));
283 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
284 common_element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
285 'width' => AVATAR_MINI_SIZE,
286 'height' => AVATAR_MINI_SIZE,
287 'class' => 'avatar mini',
288 'alt' => ($other->fullname) ?
291 common_element_end('a');
292 common_element_end('li');
295 common_element_end('ul');
298 if ($subs_count > SUBSCRIPTIONS) {
299 common_element_start('p', array('id' => 'subscriptions_viewall'));
301 common_element('a', array('href' => common_local_url('subscriptions',
302 array('nickname' => $profile->nickname)),
303 'class' => 'moresubscriptions'),
304 _('All subscriptions'));
305 common_element_end('p');
308 common_element_end('div');
311 function show_statistics($profile) {
313 // XXX: WORM cache this
314 $subs = DB_DataObject::factory('subscription');
315 $subs->subscriber = $profile->id;
316 $subs_count = (int) $subs->count() - 1;
318 $subbed = DB_DataObject::factory('subscription');
319 $subbed->subscribed = $profile->id;
320 $subbed_count = (int) $subbed->count() - 1;
322 $notices = DB_DataObject::factory('notice');
323 $notices->profile_id = $profile->id;
324 $notice_count = (int) $notices->count();
326 common_element_start('div', 'statistics');
327 common_element('h2', 'statistics', _('Statistics'));
330 common_element_start('dl', 'statistics');
331 common_element('dt', 'membersince', _('Member since'));
332 common_element('dd', 'membersince', date('j M Y',
333 strtotime($profile->created)));
335 common_element_start('dt', 'subscriptions');
336 common_element('a', array('href' => common_local_url('subscriptions',
337 array('nickname' => $profile->nickname))),
339 common_element_end('dt');
340 common_element('dd', 'subscriptions', (is_int($subs_count)) ? $subs_count : '0');
341 common_element_start('dt', 'subscribers');
342 common_element('a', array('href' => common_local_url('subscribers',
343 array('nickname' => $profile->nickname))),
345 common_element_end('dt');
346 common_element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
347 common_element('dt', 'notices', _('Notices'));
348 common_element('dd', 'notices', (is_int($notice_count)) ? $notice_count : '0');
349 common_element_end('dl');
351 common_element_end('div');
354 function show_notices($user) {
356 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
358 $notice = $user->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
364 common_element_start('ul', array('id' => 'notices'));
366 while ($notice->fetch()) {
368 if ($cnt > NOTICES_PER_PAGE) {
371 $this->show_notice($notice);
374 common_element_end('ul');
377 common_pagination($page>1, $cnt>NOTICES_PER_PAGE, $page,
378 'showstream', array('nickname' => $user->nickname));
381 function show_last_notice($profile) {
383 common_element('h2', NULL, _('Currently'));
385 $notice = $profile->getCurrentNotice();
388 # FIXME: URL, image, video, audio
389 common_element_start('p', array('class' => 'notice_current'));
390 if ($notice->rendered) {
391 common_raw($notice->rendered);
393 # XXX: may be some uncooked notices in the DB,
394 # we cook them right now. This can probably disappear in future
395 # versions (>> 0.4.x)
396 common_raw(common_render_content($notice->content, $notice));
398 common_element_end('p');
402 function show_notice($notice) {
403 $profile = $notice->getProfile();
404 $user = common_current_user();
407 common_element_start('li', array('class' => 'notice_single',
408 'id' => 'notice-' . $notice->id));
410 if ($user->hasFave($notice)) {
411 common_disfavor_form($notice);
413 common_favor_form($notice);
416 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
417 # FIXME: URL, image, video, audio
418 common_element_start('p');
419 if ($notice->rendered) {
420 common_raw($notice->rendered);
422 # XXX: may be some uncooked notices in the DB,
423 # we cook them right now. This can probably disappear in future
424 # versions (>> 0.4.x)
425 common_raw(common_render_content($notice->content, $notice));
427 common_element_end('p');
428 common_element_start('p', array('class' => 'time'));
429 common_element('a', array('class' => 'permalink',
430 'href' => $noticeurl,
431 'title' => common_exact_date($notice->created)),
432 common_date_string($notice->created));
433 if ($notice->source) {
434 common_text(_(' from '));
435 $this->source_link($notice->source);
437 if ($notice->reply_to) {
438 $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
440 common_element('a', array('class' => 'inreplyto',
441 'href' => $replyurl),
442 _('in reply to...'));
445 common_element_start('a',
446 array('href' => common_local_url('newnotice',
447 array('replyto' => $profile->nickname)),
448 'onclick' => 'doreply("'.$profile->nickname.'"); return false',
449 'title' => _('reply'),
450 'class' => 'replybutton'));
451 common_raw('→');
452 common_element_end('a');
453 if ($user && $notice->profile_id == $user->id) {
454 $deleteurl = common_local_url('deletenotice', array('notice' => $notice->id));
455 common_element_start('a', array('class' => 'deletenotice',
456 'href' => $deleteurl,
457 'title' => _('delete')));
458 common_raw('×');
459 common_element_end('a');
461 common_element_end('p');
462 common_element_end('li');