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($profile);
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));
99 function no_such_user() {
100 common_user_error(_('No such user.'));
103 function show_profile($profile) {
105 common_element_start('div', array('id' => 'profile'));
107 $this->show_personal($profile);
109 $this->show_last_notice($profile);
111 $cur = common_current_user();
113 $this->show_subscriptions($profile);
115 common_element_end('div');
118 function show_personal($profile) {
120 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
121 common_element_start('div', array('id' => 'profile_avatar'));
122 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
123 'class' => 'avatar profile',
124 'width' => AVATAR_PROFILE_SIZE,
125 'height' => AVATAR_PROFILE_SIZE,
126 'alt' => $profile->nickname));
127 $cur = common_current_user();
129 if ($cur->id != $profile->id) {
130 if ($cur->isSubscribed($profile)) {
131 $this->show_unsubscribe_form($profile);
133 $this->show_subscribe_form($profile);
137 $this->show_remote_subscribe_link($profile);
139 common_element_end('div');
141 common_element_start('div', array('id' => 'profile_information'));
143 if ($profile->fullname) {
144 common_element('h1', NULL, $profile->fullname . ' (' . $profile->nickname . ')');
146 common_element('h1', NULL, $profile->nickname);
150 if ($profile->location) {
151 common_element('p', 'location', $profile->location);
154 common_element('p', 'description', $profile->bio);
156 if ($profile->homepage) {
157 common_element_start('p', 'website');
158 common_element('a', array('href' => $profile->homepage,
161 common_element_end('p');
164 $this->show_statistics($profile);
166 common_element_end('div');
169 function show_subscribe_form($profile) {
170 common_element_start('form', array('id' => 'subscribe', 'method' => 'post',
171 'action' => common_local_url('subscribe')));
172 common_element('input', array('id' => 'subscribeto',
173 'name' => 'subscribeto',
175 'value' => $profile->nickname));
176 common_element('input', array('type' => 'submit',
178 'value' => _('Subscribe')));
179 common_element_end('form');
182 function show_remote_subscribe_link($profile) {
183 $url = common_local_url('remotesubscribe',
184 array('nickname' => $profile->nickname));
185 common_element('a', array('href' => $url,
186 'id' => 'remotesubscribe'),
190 function show_unsubscribe_form($profile) {
191 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'post',
192 'action' => common_local_url('unsubscribe')));
193 common_element('input', array('id' => 'unsubscribeto',
194 'name' => 'unsubscribeto',
196 'value' => $profile->nickname));
197 common_element('input', array('type' => 'submit',
199 'value' => _('Unsubscribe')));
200 common_element_end('form');
203 function show_subscriptions($profile) {
206 $subs = DB_DataObject::factory('subscription');
207 $subs->subscriber = $profile->id;
208 $subs->whereAdd('subscribed != ' . $profile->id);
210 $subs->orderBy('created DESC');
212 # We ask for an extra one to know if we need to do another page
214 $subs->limit(0, SUBSCRIPTIONS + 1);
216 $subs_count = $subs->find();
218 common_element_start('div', array('id' => 'subscriptions'));
220 common_element('h2', NULL, _('Subscriptions'));
222 if ($subs_count > 0) {
224 common_element_start('ul', array('id' => 'subscriptions_avatars'));
226 for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
228 if (!$subs->fetch()) {
229 common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
233 $other = Profile::staticGet($subs->subscribed);
235 common_element_start('li');
236 common_element_start('a', array('title' => ($other->fullname) ?
239 'href' => $other->profileurl,
241 'class' => 'subscription'));
242 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
243 common_element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
244 'width' => AVATAR_MINI_SIZE,
245 'height' => AVATAR_MINI_SIZE,
246 'class' => 'avatar mini',
247 'alt' => ($other->fullname) ?
250 common_element_end('a');
251 common_element_end('li');
254 common_element_end('ul');
257 if ($subs_count > SUBSCRIPTIONS) {
258 common_element_start('p', array('id' => 'subscriptions_viewall'));
260 common_element('a', array('href' => common_local_url('subscriptions',
261 array('nickname' => $profile->nickname)),
262 'class' => 'moresubscriptions'),
263 _('All subscriptions'));
264 common_element_end('p');
267 common_element_end('div');
270 function show_statistics($profile) {
272 // XXX: WORM cache this
273 $subs = DB_DataObject::factory('subscription');
274 $subs->subscriber = $profile->id;
275 $subs_count = (int) $subs->count() - 1;
277 $subbed = DB_DataObject::factory('subscription');
278 $subbed->subscribed = $profile->id;
279 $subbed_count = (int) $subbed->count() - 1;
281 $notices = DB_DataObject::factory('notice');
282 $notices->profile_id = $profile->id;
283 $notice_count = (int) $notices->count();
285 common_element_start('div', 'statistics');
286 common_element('h2', 'statistics', _('Statistics'));
289 common_element_start('dl', 'statistics');
290 common_element('dt', 'membersince', _('Member since'));
291 common_element('dd', 'membersince', date('j M Y',
292 strtotime($profile->created)));
294 common_element_start('dt', 'subscriptions');
295 common_element('a', array('href' => common_local_url('subscriptions',
296 array('nickname' => $profile->nickname))),
298 common_element_end('dt');
299 common_element('dd', 'subscriptions', (is_int($subs_count)) ? $subs_count : '0');
300 common_element_start('dt', 'subscribers');
301 common_element('a', array('href' => common_local_url('subscribers',
302 array('nickname' => $profile->nickname))),
304 common_element_end('dt');
305 common_element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
306 common_element('dt', 'notices', _('Notices'));
307 common_element('dd', 'notices', (is_int($notice_count)) ? $notice_count : '0');
308 common_element_end('dl');
310 common_element_end('div');
313 function show_notices($profile) {
315 $notice = DB_DataObject::factory('notice');
316 $notice->profile_id = $profile->id;
318 $notice->orderBy('created DESC, notice.id DESC');
320 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
322 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
324 $cnt = $notice->find();
327 common_element_start('ul', array('id' => 'notices'));
329 for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
330 if ($notice->fetch()) {
331 $this->show_notice($notice);
338 common_element_end('ul');
340 common_pagination($page>1, $cnt>NOTICES_PER_PAGE, $page,
341 'showstream', array('nickname' => $profile->nickname));
344 function show_last_notice($profile) {
346 common_element('h2', NULL, _('Currently'));
348 $notice = $profile->getCurrentNotice();
351 # FIXME: URL, image, video, audio
352 common_element_start('p', array('class' => 'notice_current'));
353 if ($notice->rendered) {
354 common_raw($notice->rendered);
356 # XXX: may be some uncooked notices in the DB,
357 # we cook them right now. This can probably disappear in future
358 # versions (>> 0.4.x)
359 common_raw(common_render_content($notice->content, $notice));
361 common_element_end('p');
365 function show_notice($notice) {
366 $profile = $notice->getProfile();
367 if (common_logged_in()) {
368 $user = common_current_user();
369 $user_profile = $user->getProfile();
372 common_element_start('li', array('class' => 'notice_single',
373 'id' => 'notice-' . $notice->id));
374 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
375 # FIXME: URL, image, video, audio
376 common_element_start('p');
377 if ($notice->rendered) {
378 common_raw($notice->rendered);
380 # XXX: may be some uncooked notices in the DB,
381 # we cook them right now. This can probably disappear in future
382 # versions (>> 0.4.x)
383 common_raw(common_render_content($notice->content, $notice));
385 common_element_end('p');
386 common_element_start('p', array('class' => 'time'));
387 common_element('a', array('class' => 'permalink',
388 'href' => $noticeurl,
389 'title' => common_exact_date($notice->created)),
390 common_date_string($notice->created));
391 if ($notice->reply_to) {
392 $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
394 common_element('a', array('class' => 'inreplyto',
395 'href' => $replyurl),
396 _('in reply to...'));
399 common_element_start('a',
400 array('href' => common_local_url('newnotice',
401 array('replyto' => $profile->nickname)),
402 'onclick' => 'doreply("'.$profile->nickname.'"); return false',
403 'title' => _('reply'),
404 'class' => 'replybutton'));
405 common_raw('→');
406 common_element_end('a');
407 common_element_end('p');
408 if ($notice->profile_id == $user_profile->id) {
409 $deleteurl = common_local_url('deletenotice', array('notice' => $notice->id));
410 common_element('a', array('class' => 'deletenotice',
411 'href' => $deleteurl),
414 common_element_end('li');