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 if ($this->profile->fullname) {
243 $this->elementStart('dl', 'user_fn');
244 $this->element('dt', null, _('Full name'));
245 $this->elementStart('dd');
246 $this->element('span', 'fn', $this->profile->fullname);
247 $this->elementEnd('dd');
248 $this->elementEnd('dl');
250 $this->elementStart('dl', 'user_nickname');
251 $this->element('dt', null, _('Nickname'));
252 $this->elementStart('dd');
253 $this->element('a', array('href' => $this->profile->profileurl,
254 'rel' => 'me', 'class' => 'fn nickname url uid'),
255 $this->profile->nickname);
256 $this->elementEnd('dd');
257 $this->elementEnd('dl');
259 if ($this->profile->location) {
260 $this->elementStart('dl', 'user_location');
261 $this->element('dt', null, _('Location'));
262 $this->element('dd', 'location', $this->profile->location);
263 $this->elementEnd('dl');
266 if ($this->profile->homepage) {
267 $this->elementStart('dl', 'user_url');
268 $this->element('dt', null, _('URL'));
269 $this->elementStart('dd');
270 $this->element('a', array('href' => $this->profile->homepage,
271 'rel' => 'me', 'class' => 'url'),
272 $this->profile->homepage);
273 $this->elementEnd('dd');
274 $this->elementEnd('dl');
277 if ($this->profile->bio) {
278 $this->elementStart('dl', 'user_note');
279 $this->element('dt', null, _('Note'));
280 $this->element('dd', 'note', $this->profile->bio);
281 $this->elementEnd('dl');
284 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
285 if (count($tags) > 0) {
286 $this->elementStart('dl', 'user_tags');
287 $this->element('dt', null, _('Tags'));
288 $this->elementStart('dd', 'tags');
289 $this->elementStart('ul', 'tags xoxo');
290 foreach ($tags as $tag) {
291 $this->elementStart('li');
292 $this->element('a', array('rel' => 'tag',
293 'href' => common_local_url('peopletag',
294 array('tag' => $tag))),
296 $this->elementEnd('li');
298 $this->elementEnd('ul');
299 $this->elementEnd('dd');
300 $this->elementEnd('dl');
302 $this->elementEnd('div');
305 $this->elementStart('div', array('id' => 'user_actions'));
306 $this->element('h2', null, _('User actions'));
307 $this->elementStart('ul');
308 $this->elementStart('li', array('id' => 'user_subscribe'));
309 $cur = common_current_user();
311 if ($cur->id != $this->profile->id) {
312 if ($cur->isSubscribed($this->profile)) {
313 $sf = new SubscribeForm($this, $this->profile);
316 $usf = new UnsubscribeForm($this, $this->profile);
321 $this->showRemoteSubscribeLink();
323 $this->elementEnd('li');
325 common_profile_new_message_nudge($cur, $this->user, $this->profile);
327 if ($cur && $cur->id != $this->profile->id) {
328 $blocked = $cur->hasBlocked($this->profile);
329 $this->elementStart('li', array('id' => 'user_block'));
331 $bf = new BlockForm($this, $this->profile);
334 $ubf = new UnblockForm($this, $this->profile);
337 $this->elementEnd('li');
339 $this->elementEnd('ul');
340 $this->elementEnd('div');
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' => 'subscriptions',
386 'class' => 'section'));
388 $this->element('h2', null, _('Subscriptions'));
390 if ($subs_count > 0) {
392 $this->elementStart('ul', array('id' => 'subscriptions_avatars'));
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,
414 'class' => 'subscription fn url'));
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 mini photo',
420 'alt' => ($other->fullname) ?
423 $this->elementEnd('a');
424 $this->elementEnd('li');
427 $this->elementEnd('ul');
430 if ($subs_count > SUBSCRIPTIONS) {
431 $this->elementStart('p', array('id' => 'subscriptions_viewall'));
433 $this->element('a', array('href' => common_local_url('subscriptions',
434 array('nickname' => $this->profile->nickname)),
435 'class' => 'moresubscriptions'),
436 _('All subscriptions'));
437 $this->elementEnd('p');
440 $this->elementEnd('div');
443 function showStatistics()
445 // XXX: WORM cache this
446 $subs = new Subscription();
447 $subs->subscriber = $this->profile->id;
448 $subs_count = (int) $subs->count() - 1;
450 $subbed = new Subscription();
451 $subbed->subscribed = $this->profile->id;
452 $subbed_count = (int) $subbed->count() - 1;
454 $notices = new Notice();
455 $notices->profile_id = $this->profile->id;
456 $notice_count = (int) $notices->count();
458 $this->elementStart('div', array('id' => 'statistics',
459 'class' => 'section'));
461 $this->element('h2', 'statistics', _('Statistics'));
464 $this->elementStart('dl', 'statistics');
465 $this->element('dt', 'membersince', _('Member since'));
466 $this->element('dd', 'membersince', date('j M Y',
467 strtotime($this->profile->created)));
469 $this->elementStart('dt', 'subscriptions');
470 $this->element('a', array('href' => common_local_url('subscriptions',
471 array('nickname' => $this->profile->nickname))),
473 $this->elementEnd('dt');
474 $this->element('dd', 'subscriptions', (is_int($subs_count)) ? $subs_count : '0');
475 $this->elementStart('dt', 'subscribers');
476 $this->element('a', array('href' => common_local_url('subscribers',
477 array('nickname' => $this->profile->nickname))),
479 $this->elementEnd('dt');
480 $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
481 $this->element('dt', 'notices', _('Notices'));
482 $this->element('dd', 'notices', (is_int($notice_count)) ? $notice_count : '0');
483 $this->elementEnd('dl');
485 $this->elementEnd('div');
490 // We don't show the author for a profile, since we already know who it is!
492 class ProfileNoticeList extends NoticeList
494 function newListItem($notice)
496 return new ProfileNoticeListItem($notice, $this->out);
500 class ProfileNoticeListItem extends NoticeListItem
502 function showAuthor()