3 * Laconica, the distributed open-source microblogging tool
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@controlyourself.ca>
25 * @copyright 2008-2009 Control Yourself, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://laconi.ca/
30 if (!defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/personalgroupnav.php';
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
41 * When I created this page, "show stream" seemed like the best name for it.
42 * Now, it seems like a really bad name.
44 * It shows a stream of the user's posts, plus lots of profile info, links
45 * to subscriptions and stuff, etc.
49 * @author Evan Prodromou <evan@controlyourself.ca>
50 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
51 * @link http://laconi.ca/
54 class ShowstreamAction extends Action
62 if ($this->page == 1) {
63 return $this->user->nickname;
65 return sprintf(_("%s, page %d"),
66 $this->user->nickname,
71 function prepare($args)
73 parent::prepare($args);
75 $nickname_arg = $this->arg('nickname');
76 $nickname = common_canonical_nickname($nickname_arg);
78 // Permanent redirect on non-canonical nickname
80 if ($nickname_arg != $nickname) {
81 $args = array('nickname' => $nickname);
82 if ($this->arg('page') && $this->arg('page') != 1) {
83 $args['page'] = $this->arg['page'];
85 common_redirect(common_local_url('showstream', $args), 301);
89 $this->user = User::staticGet('nickname', $nickname);
92 $this->clientError(_('No such user.'), 404);
96 $this->profile = $this->user->getProfile();
98 if (!$this->profile) {
99 $this->serverError(_('User has no profile.'));
103 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
108 function handle($args)
111 // Looks like we're good; start output
113 // For YADIS discovery, we also have a <meta> tag
115 header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
116 $this->user->nickname)));
121 function showContent()
123 $this->showProfile();
124 $this->showNotices();
127 function showLocalNav()
129 $nav = new PersonalGroupNav($this);
133 function showPageTitle()
135 $this->element('h1', NULL, $this->profile->nickname._("'s profile"));
138 function showPageNoticeBlock()
143 function showExportData()
145 $fl = new FeedList($this);
146 $fl->show(array(0=>array('href'=>common_local_url('userrss',
147 array('nickname' => $this->user->nickname)),
149 'version' => 'RSS 1.0',
150 'item' => 'notices'),
151 1=>array('href'=>common_local_url('usertimeline',
152 array('nickname' => $this->user->nickname)),
154 'version' => 'Atom 1.0',
155 'item' => 'usertimeline'),
156 2=>array('href'=>common_local_url('foaf',
157 array('nickname' => $this->user->nickname)),
166 $this->element('link', array('rel' => 'alternate',
167 'href' => common_local_url('api',
168 array('apiaction' => 'statuses',
169 'method' => 'user_timeline.rss',
170 'argument' => $this->user->nickname)),
171 'type' => 'application/rss+xml',
172 'title' => sprintf(_('Notice feed for %s'), $this->user->nickname)));
173 $this->element('link', array('rel' => 'alternate feed',
174 'href' => common_local_url('api',
175 array('apiaction' => 'statuses',
176 'method' => 'user_timeline.atom',
177 'argument' => $this->user->nickname)),
178 'type' => 'application/atom+xml',
179 'title' => sprintf(_('Notice feed for %s'), $this->user->nickname)));
180 $this->element('link', array('rel' => 'alternate',
181 'href' => common_local_url('userrss', array('nickname' =>
182 $this->user->nickname)),
183 'type' => 'application/rdf+xml',
184 'title' => sprintf(_('Notice feed for %s'), $this->user->nickname)));
190 $this->element('link', array('rel' => 'meta',
191 'href' => common_local_url('foaf', array('nickname' =>
192 $this->user->nickname)),
193 'type' => 'application/rdf+xml',
195 // for remote subscriptions etc.
196 $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
197 'content' => common_local_url('xrds', array('nickname' =>
198 $this->user->nickname))));
200 if ($this->profile->bio) {
201 $this->element('meta', array('name' => 'description',
202 'content' => $this->profile->bio));
205 if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
206 $id = new Microid('mailto:'.$this->user->email,
208 $this->element('meta', array('name' => 'microid',
209 'content' => $id->toString()));
211 if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
212 $id = new Microid('xmpp:'.$this->user->jabber,
214 $this->element('meta', array('name' => 'microid',
215 'content' => $id->toString()));
218 // See https://wiki.mozilla.org/Microsummaries
220 $this->element('link', array('rel' => 'microsummary',
221 'href' => common_local_url('microsummary',
222 array('nickname' => $this->profile->nickname))));
225 function showProfile()
227 $this->elementStart('div', array('id' => 'user_profile', 'class' => 'vcard author'));
228 $this->element('h2', null, _('User profile'));
230 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
231 $this->elementStart('dl', 'user_depiction');
232 $this->element('dt', null, _('Photo'));
233 $this->elementStart('dd');
234 $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
235 'class' => 'photo avatar',
236 'width' => AVATAR_PROFILE_SIZE,
237 'height' => AVATAR_PROFILE_SIZE,
238 'alt' => $this->profile->nickname));
239 $this->elementEnd('dd');
240 $this->elementEnd('dl');
242 $this->elementStart('dl', 'user_nickname');
243 $this->element('dt', null, _('Nickname'));
244 $this->elementStart('dd');
245 $this->element('a', array('href' => $this->profile->profileurl,
246 'rel' => 'me', 'class' => 'nickname url uid'),
247 $this->profile->nickname);
248 $this->elementEnd('dd');
249 $this->elementEnd('dl');
251 if ($this->profile->fullname) {
252 $this->elementStart('dl', 'user_fn');
253 $this->element('dt', null, _('Full name'));
254 $this->elementStart('dd');
255 $this->element('span', 'fn', $this->profile->fullname);
256 $this->elementEnd('dd');
257 $this->elementEnd('dl');
260 if ($this->profile->location) {
261 $this->elementStart('dl', 'user_location');
262 $this->element('dt', null, _('Location'));
263 $this->element('dd', 'location', $this->profile->location);
264 $this->elementEnd('dl');
267 if ($this->profile->homepage) {
268 $this->elementStart('dl', 'user_url');
269 $this->element('dt', null, _('URL'));
270 $this->elementStart('dd');
271 $this->element('a', array('href' => $this->profile->homepage,
272 'rel' => 'me', 'class' => 'url'),
273 $this->profile->homepage);
274 $this->elementEnd('dd');
275 $this->elementEnd('dl');
278 if ($this->profile->bio) {
279 $this->elementStart('dl', 'user_note');
280 $this->element('dt', null, _('Note'));
281 $this->element('dd', 'note', $this->profile->bio);
282 $this->elementEnd('dl');
285 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
286 if (count($tags) > 0) {
287 $this->elementStart('dl', 'user_tags');
288 $this->element('dt', null, _('Tags'));
289 $this->elementStart('dd', 'tags');
290 $this->elementStart('ul', 'tags xoxo');
291 foreach ($tags as $tag) {
292 $this->elementStart('li');
293 $this->element('span', 'mark_hash', '#');
294 $this->element('a', array('rel' => 'tag',
295 'href' => common_local_url('peopletag',
296 array('tag' => $tag))),
298 $this->elementEnd('li');
300 $this->elementEnd('ul');
301 $this->elementEnd('dd');
302 $this->elementEnd('dl');
304 $this->elementEnd('div');
307 $this->elementStart('div', array('id' => 'user_actions'));
308 $this->element('h2', null, _('User actions'));
309 $this->elementStart('ul');
310 $this->elementStart('li', array('id' => 'user_subscribe'));
311 $cur = common_current_user();
313 if ($cur->id != $this->profile->id) {
314 if ($cur->isSubscribed($this->profile)) {
315 $sf = new SubscribeForm($this, $this->profile);
318 $usf = new UnsubscribeForm($this, $this->profile);
323 $this->showRemoteSubscribeLink();
325 $this->elementEnd('li');
327 common_profile_new_message_nudge($cur, $this->user, $this->profile);
329 if ($cur && $cur->id != $this->profile->id) {
330 $blocked = $cur->hasBlocked($this->profile);
331 $this->elementStart('li', array('id' => 'user_block'));
333 $bf = new BlockForm($this, $this->profile);
336 $ubf = new UnblockForm($this, $this->profile);
339 $this->elementEnd('li');
341 $this->elementEnd('ul');
342 $this->elementEnd('div');
345 function showRemoteSubscribeLink()
347 $url = common_local_url('remotesubscribe',
348 array('nickname' => $this->profile->nickname));
349 $this->element('a', array('href' => $url,
350 'id' => 'remotesubscribe'),
354 function showNotices()
356 $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
358 $pnl = new ProfileNoticeList($notice, $this);
361 $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
362 'showstream', array('nickname' => $this->user->nickname));
365 function showSections()
367 $this->showStatistics();
368 $this->showSubscriptions();
371 function showSubscriptions()
373 $subs = new Subscription();
374 $subs->subscriber = $this->profile->id;
375 $subs->whereAdd('subscribed != ' . $this->profile->id);
377 $subs->orderBy('created DESC');
379 // We ask for an extra one to know if we need to do another page
381 $subs->limit(0, SUBSCRIPTIONS + 1);
383 $subs_count = $subs->find();
385 $this->elementStart('div', array('id' => 'user_subscriptions',
386 'class' => 'section'));
388 $this->element('h2', null, _('Subscriptions'));
390 if ($subs_count > 0) {
392 $this->elementStart('ul', 'users');
394 for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
396 if (!$subs->fetch()) {
397 common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
401 $other = Profile::staticGet($subs->subscribed);
404 common_log_db_error($subs, 'SELECT', __FILE__);
408 $this->elementStart('li', 'vcard');
409 $this->elementStart('a', array('title' => ($other->fullname) ?
412 'href' => $other->profileurl,
415 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
416 $this->element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
417 'width' => AVATAR_MINI_SIZE,
418 'height' => AVATAR_MINI_SIZE,
419 'class' => 'avatar photo',
420 'alt' => ($other->fullname) ?
423 $this->element('span', 'fn nickname', $other->nickname);
424 $this->elementEnd('a');
425 $this->elementEnd('li');
428 $this->elementEnd('ul');
431 if ($subs_count > SUBSCRIPTIONS) {
432 $this->elementStart('p');
434 $this->element('a', array('href' => common_local_url('subscriptions',
435 array('nickname' => $this->profile->nickname)),
437 _('All subscriptions'));
438 $this->elementEnd('p');
441 $this->elementEnd('div');
444 function showStatistics()
446 // XXX: WORM cache this
447 $subs = new Subscription();
448 $subs->subscriber = $this->profile->id;
449 $subs_count = (int) $subs->count() - 1;
451 $subbed = new Subscription();
452 $subbed->subscribed = $this->profile->id;
453 $subbed_count = (int) $subbed->count() - 1;
455 $notices = new Notice();
456 $notices->profile_id = $this->profile->id;
457 $notice_count = (int) $notices->count();
459 $this->elementStart('div', array('id' => 'user_statistics',
460 'class' => 'section'));
462 $this->element('h2', null, _('Statistics'));
465 $this->elementStart('dl', 'user_member-since');
466 $this->element('dt', null, _('Member since'));
467 $this->element('dd', null, date('j M Y',
468 strtotime($this->profile->created)));
469 $this->elementEnd('dl');
471 $this->elementStart('dl', 'user_subscriptions');
472 $this->elementStart('dt');
473 $this->element('a', array('href' => common_local_url('subscriptions',
474 array('nickname' => $this->profile->nickname))),
476 $this->elementEnd('dt');
477 $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
478 $this->elementEnd('dl');
480 $this->elementStart('dl', 'user_subscribers');
481 $this->elementStart('dt');
482 $this->element('a', array('href' => common_local_url('subscribers',
483 array('nickname' => $this->profile->nickname))),
485 $this->elementEnd('dt');
486 $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
487 $this->elementEnd('dl');
489 $this->elementStart('dl', 'user_notices');
490 $this->element('dt', null, _('Notices'));
491 $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
492 $this->elementEnd('dl');
494 $this->elementEnd('div');
499 // We don't show the author for a profile, since we already know who it is!
501 class ProfileNoticeList extends NoticeList
503 function newListItem($notice)
505 return new ProfileNoticeListItem($notice, $this->out);
509 class ProfileNoticeListItem extends NoticeListItem
511 function showAuthor()