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) {
78 common_element('link', array('rel' => 'alternate',
79 'href' => common_local_url('userrss', array('nickname' =>
81 'type' => 'application/rss+xml',
82 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
83 common_element('link', array('rel' => 'meta',
84 'href' => common_local_url('foaf', array('nickname' =>
86 'type' => 'application/rdf+xml',
88 # for remote subscriptions etc.
89 common_element('meta', array('http-equiv' => 'X-XRDS-Location',
90 'content' => common_local_url('xrds', array('nickname' =>
92 $profile = $user->getProfile();
94 common_element('meta', array('name' => 'description',
95 'content' => $profile->bio));
98 if ($user->emailmicroid && $user->email && $profile->profileurl) {
99 common_element('meta', array('name' => 'microid',
100 'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($profile->profileurl))));
102 if ($user->jabbermicroid && $user->jabber && $profile->profileurl) {
103 common_element('meta', array('name' => 'microid',
104 'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($profile->profileurl))));
109 function no_such_user() {
110 $this->client_error(_('No such user.'), 404);
113 function show_profile($profile) {
115 common_element_start('div', array('id' => 'profile'));
117 $this->show_personal($profile);
119 $this->show_last_notice($profile);
121 $cur = common_current_user();
123 $this->show_subscriptions($profile);
125 common_element_end('div');
128 function show_personal($profile) {
130 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
131 common_element_start('div', array('id' => 'profile_avatar'));
132 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
133 'class' => 'avatar profile',
134 'width' => AVATAR_PROFILE_SIZE,
135 'height' => AVATAR_PROFILE_SIZE,
136 'alt' => $profile->nickname));
137 $cur = common_current_user();
139 if ($cur->id != $profile->id) {
140 if ($cur->isSubscribed($profile)) {
141 $this->show_unsubscribe_form($profile);
143 $this->show_subscribe_form($profile);
147 $this->show_remote_subscribe_link($profile);
150 $user = User::staticGet('id', $profile->id);
152 if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
153 common_element('a', array('href' => common_local_url('newmessage', array('to' => $user->id))),
154 _('Send a message'));
157 common_element_end('div');
159 common_element_start('div', array('id' => 'profile_information'));
161 if ($profile->fullname) {
162 common_element('h1', NULL, $profile->fullname . ' (' . $profile->nickname . ')');
164 common_element('h1', NULL, $profile->nickname);
168 if ($profile->location) {
169 common_element('p', 'location', $profile->location);
172 common_element('p', 'description', $profile->bio);
174 if ($profile->homepage) {
175 common_element_start('p', 'website');
176 common_element('a', array('href' => $profile->homepage,
179 common_element_end('p');
182 $this->show_statistics($profile);
184 common_element_end('div');
187 function show_subscribe_form($profile) {
188 common_element_start('form', array('id' => 'subscribe', 'method' => 'post',
189 'action' => common_local_url('subscribe')));
190 common_hidden('token', common_session_token());
191 common_element('input', array('id' => 'subscribeto',
192 'name' => 'subscribeto',
194 'value' => $profile->nickname));
195 common_element('input', array('type' => 'submit',
197 'value' => _('Subscribe')));
198 common_element_end('form');
201 function show_remote_subscribe_link($profile) {
202 $url = common_local_url('remotesubscribe',
203 array('nickname' => $profile->nickname));
204 common_element('a', array('href' => $url,
205 'id' => 'remotesubscribe'),
209 function show_unsubscribe_form($profile) {
210 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'post',
211 'action' => common_local_url('unsubscribe')));
212 common_hidden('token', common_session_token());
213 common_element('input', array('id' => 'unsubscribeto',
214 'name' => 'unsubscribeto',
216 'value' => $profile->nickname));
217 common_element('input', array('type' => 'submit',
219 'value' => _('Unsubscribe')));
220 common_element_end('form');
223 function show_subscriptions($profile) {
226 $subs = DB_DataObject::factory('subscription');
227 $subs->subscriber = $profile->id;
228 $subs->whereAdd('subscribed != ' . $profile->id);
230 $subs->orderBy('created DESC');
232 # We ask for an extra one to know if we need to do another page
234 $subs->limit(0, SUBSCRIPTIONS + 1);
236 $subs_count = $subs->find();
238 common_element_start('div', array('id' => 'subscriptions'));
240 common_element('h2', NULL, _('Subscriptions'));
242 if ($subs_count > 0) {
244 common_element_start('ul', array('id' => 'subscriptions_avatars'));
246 for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
248 if (!$subs->fetch()) {
249 common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
253 $other = Profile::staticGet($subs->subscribed);
256 common_log_db_error($subs, 'SELECT', __FILE__);
260 common_element_start('li');
261 common_element_start('a', array('title' => ($other->fullname) ?
264 'href' => $other->profileurl,
266 'class' => 'subscription'));
267 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
268 common_element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
269 'width' => AVATAR_MINI_SIZE,
270 'height' => AVATAR_MINI_SIZE,
271 'class' => 'avatar mini',
272 'alt' => ($other->fullname) ?
275 common_element_end('a');
276 common_element_end('li');
279 common_element_end('ul');
282 if ($subs_count > SUBSCRIPTIONS) {
283 common_element_start('p', array('id' => 'subscriptions_viewall'));
285 common_element('a', array('href' => common_local_url('subscriptions',
286 array('nickname' => $profile->nickname)),
287 'class' => 'moresubscriptions'),
288 _('All subscriptions'));
289 common_element_end('p');
292 common_element_end('div');
295 function show_statistics($profile) {
297 // XXX: WORM cache this
298 $subs = DB_DataObject::factory('subscription');
299 $subs->subscriber = $profile->id;
300 $subs_count = (int) $subs->count() - 1;
302 $subbed = DB_DataObject::factory('subscription');
303 $subbed->subscribed = $profile->id;
304 $subbed_count = (int) $subbed->count() - 1;
306 $notices = DB_DataObject::factory('notice');
307 $notices->profile_id = $profile->id;
308 $notice_count = (int) $notices->count();
310 common_element_start('div', 'statistics');
311 common_element('h2', 'statistics', _('Statistics'));
314 common_element_start('dl', 'statistics');
315 common_element('dt', 'membersince', _('Member since'));
316 common_element('dd', 'membersince', date('j M Y',
317 strtotime($profile->created)));
319 common_element_start('dt', 'subscriptions');
320 common_element('a', array('href' => common_local_url('subscriptions',
321 array('nickname' => $profile->nickname))),
323 common_element_end('dt');
324 common_element('dd', 'subscriptions', (is_int($subs_count)) ? $subs_count : '0');
325 common_element_start('dt', 'subscribers');
326 common_element('a', array('href' => common_local_url('subscribers',
327 array('nickname' => $profile->nickname))),
329 common_element_end('dt');
330 common_element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
331 common_element('dt', 'notices', _('Notices'));
332 common_element('dd', 'notices', (is_int($notice_count)) ? $notice_count : '0');
333 common_element_end('dl');
335 common_element_end('div');
338 function show_notices($user) {
340 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
342 $notice = $user->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
348 common_element_start('ul', array('id' => 'notices'));
350 while ($notice->fetch()) {
352 if ($cnt > NOTICES_PER_PAGE) {
355 $this->show_notice($notice);
358 common_element_end('ul');
361 common_pagination($page>1, $cnt>NOTICES_PER_PAGE, $page,
362 'showstream', array('nickname' => $user->nickname));
365 function show_last_notice($profile) {
367 common_element('h2', NULL, _('Currently'));
369 $notice = $profile->getCurrentNotice();
372 # FIXME: URL, image, video, audio
373 common_element_start('p', array('class' => 'notice_current'));
374 if ($notice->rendered) {
375 common_raw($notice->rendered);
377 # XXX: may be some uncooked notices in the DB,
378 # we cook them right now. This can probably disappear in future
379 # versions (>> 0.4.x)
380 common_raw(common_render_content($notice->content, $notice));
382 common_element_end('p');
386 function show_notice($notice) {
387 $profile = $notice->getProfile();
388 $user = common_current_user();
391 common_element_start('li', array('class' => 'notice_single',
392 'id' => 'notice-' . $notice->id));
394 if ($user->hasFave($notice)) {
395 common_disfavor_form($notice);
397 common_favor_form($notice);
400 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
401 # FIXME: URL, image, video, audio
402 common_element_start('p');
403 if ($notice->rendered) {
404 common_raw($notice->rendered);
406 # XXX: may be some uncooked notices in the DB,
407 # we cook them right now. This can probably disappear in future
408 # versions (>> 0.4.x)
409 common_raw(common_render_content($notice->content, $notice));
411 common_element_end('p');
412 common_element_start('p', array('class' => 'time'));
413 common_element('a', array('class' => 'permalink',
414 'href' => $noticeurl,
415 'title' => common_exact_date($notice->created)),
416 common_date_string($notice->created));
417 if ($notice->source) {
418 common_text(_(' from '));
419 $this->source_link($notice->source);
421 if ($notice->reply_to) {
422 $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
424 common_element('a', array('class' => 'inreplyto',
425 'href' => $replyurl),
426 _('in reply to...'));
429 common_element_start('a',
430 array('href' => common_local_url('newnotice',
431 array('replyto' => $profile->nickname)),
432 'onclick' => 'doreply("'.$profile->nickname.'"); return false',
433 'title' => _('reply'),
434 'class' => 'replybutton'));
435 common_raw('→');
436 common_element_end('a');
437 if ($user && $notice->profile_id == $user->id) {
438 $deleteurl = common_local_url('deletenotice', array('notice' => $notice->id));
439 common_element_start('a', array('class' => 'deletenotice',
440 'href' => $deleteurl,
441 'title' => _('delete')));
442 common_raw('×');
443 common_element_end('a');
445 common_element_end('p');
446 common_element_end('li');