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(_t('User record exists without 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' => _t('Notice feed for ') . $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' =>
94 function no_such_user() {
95 common_user_error('No such user');
98 function show_profile($profile) {
100 common_element_start('div', array('id' => 'profile'));
102 $this->show_personal($profile);
104 $this->show_last_notice($profile);
106 $cur = common_current_user();
108 $this->show_subscriptions($profile);
110 common_element_end('div');
113 function show_personal($profile) {
115 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
116 common_element_start('div', array('id' => 'profile_avatar'));
117 common_element('img', array('src' => ($avatar) ? $avatar->url : common_default_avatar(AVATAR_PROFILE_SIZE),
118 'class' => 'avatar profile',
119 'width' => AVATAR_PROFILE_SIZE,
120 'height' => AVATAR_PROFILE_SIZE,
121 'alt' => $profile->nickname));
122 $cur = common_current_user();
124 if ($cur->id != $profile->id) {
125 if ($cur->isSubscribed($profile)) {
126 $this->show_unsubscribe_form($profile);
128 $this->show_subscribe_form($profile);
132 $this->show_remote_subscribe_link($profile);
134 common_element_end('div');
136 common_element_start('div', array('id' => 'profile_information'));
138 if ($profile->fullname) {
139 common_element('h1', NULL, $profile->fullname);
141 if ($profile->location) {
142 common_element('p', 'location', $profile->location);
145 common_element('p', 'description', htmlspecialchars($profile->bio));
147 if ($profile->homepage) {
148 common_element_start('p', 'website');
149 common_element('a', array('href' => $profile->homepage),
151 common_element_end('p');
154 $this->show_statistics($profile);
156 common_element_end('div');
159 function show_subscribe_form($profile) {
160 common_element_start('form', array('id' => 'subscribe', 'method' => 'post',
161 'action' => common_local_url('subscribe')));
162 common_element('input', array('id' => 'subscribeto',
163 'name' => 'subscribeto',
165 'value' => $profile->nickname));
166 common_element('input', array('type' => 'submit',
168 'value' => _t('Subscribe')));
169 common_element_end('form');
172 function show_remote_subscribe_link($profile) {
173 $url = common_local_url('remotesubscribe',
174 array('nickname' => $profile->nickname));
175 common_element('a', array('href' => $url,
176 'id' => 'remotesubscribe'),
180 function show_unsubscribe_form($profile) {
181 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'post',
182 'action' => common_local_url('unsubscribe')));
183 common_element('input', array('id' => 'unsubscribeto',
184 'name' => 'unsubscribeto',
186 'value' => $profile->nickname));
187 common_element('input', array('type' => 'submit',
189 'value' => _t('Unsubscribe')));
190 common_element_end('form');
193 function show_subscriptions($profile) {
196 $subs = DB_DataObject::factory('subscription');
197 $subs->subscriber = $profile->id;
198 $subs->orderBy('created DESC');
200 # We ask for an extra one to know if we need to do another page
202 $subs->limit(0, SUBSCRIPTIONS + 1);
204 $subs_count = $subs->find();
206 common_element_start('div', array('id' => 'subscriptions'));
208 common_element('h2', NULL, _t('Subscriptions'));
210 if ($subs_count > 0) {
212 common_element_start('ul', array('id' => 'subscriptions_avatars'));
214 for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
216 if (!$subs->fetch()) {
217 common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
221 $other = Profile::staticGet($subs->subscribed);
223 common_element_start('li');
224 common_element_start('a', array('title' => ($other->fullname) ?
227 'href' => $other->profileurl,
228 'class' => 'subscription'));
229 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
230 common_element('img', array('src' => (($avatar) ? $avatar->url : common_default_avatar(AVATAR_MINI_SIZE)),
231 'width' => AVATAR_MINI_SIZE,
232 'height' => AVATAR_MINI_SIZE,
233 'class' => 'avatar mini',
234 'alt' => ($other->fullname) ?
237 common_element_end('a');
238 common_element_end('li');
241 common_element_end('ul');
244 if ($subs_count > SUBSCRIPTIONS) {
245 common_element_start('p', array('id' => 'subscriptions_viewall'));
247 common_element('a', array('href' => common_local_url('subscriptions',
248 array('nickname' => $profile->nickname)),
249 'class' => 'moresubscriptions'),
250 _t('All subscriptions'));
251 common_element_end('p');
254 common_element_end('div');
257 function show_statistics($profile) {
259 // XXX: WORM cache this
260 $subs = DB_DataObject::factory('subscription');
261 $subs->subscriber = $profile->id;
262 $subs_count = (int) $subs->count();
264 $subbed = DB_DataObject::factory('subscription');
265 $subbed->subscribed = $profile->id;
266 $subbed_count = (int) $subbed->count();
268 $notices = DB_DataObject::factory('notice');
269 $notices->profile_id = $profile->id;
270 $notice_count = (int) $notices->count();
272 common_element_start('div', 'statistics');
273 common_element('h2', 'statistics', _t('Statistics'));
276 common_element_start('dl', 'statistics');
277 common_element_start('dt', 'subscriptions');
278 common_element('a', array('href' => common_local_url('subscriptions',
279 array('nickname' => $profile->nickname))),
280 _t('Subscriptions'));
281 common_element_end('dt');
282 common_element('dd', 'subscriptions', $subs_count);
283 common_element_start('dt', 'subscribers');
284 common_element('a', array('href' => common_local_url('subscribers',
285 array('nickname' => $profile->nickname))),
287 common_element_end('dt');
288 common_element('dd', 'subscribers', $subbed_count);
289 common_element('dt', 'notices', _t('Notices'));
290 common_element('dd', 'notices', $notice_count);
291 common_element_end('dl');
293 common_element_end('div');
296 function show_notices($profile) {
298 $notice = DB_DataObject::factory('notice');
299 $notice->profile_id = $profile->id;
301 $notice->orderBy('created DESC');
303 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
305 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
307 $cnt = $notice->find();
310 common_element_start('ul', array('id' => 'notices'));
312 for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
313 if ($notice->fetch()) {
314 $this->show_notice($notice);
321 common_element_end('ul');
323 common_pagination($page>1, $cnt>NOTICES_PER_PAGE, $page,
324 'showstream', array('nickname' => $profile->nickname));
327 function show_last_notice($profile) {
329 common_element('h2', NULL, _t('Currently'));
331 $notice = DB_DataObject::factory('notice');
332 $notice->profile_id = $profile->id;
333 $notice->orderBy('created DESC');
334 $notice->limit(0, 1);
336 if ($notice->find(true)) {
337 # FIXME: URL, image, video, audio
338 common_element_start('p', array('class' => 'notice_current'));
339 common_raw(common_render_content($notice->content, $notice));
340 common_element_end('p');
344 function show_notice($notice) {
345 $profile = $notice->getProfile();
347 common_element_start('li', array('class' => 'notice_single',
348 'id' => 'notice-' . $notice->id));
349 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
350 # FIXME: URL, image, video, audio
351 common_element_start('p');
352 common_raw(common_render_content($notice->content, $notice));
353 common_element_end('p');
354 common_element_start('p', array('class' => 'time'));
355 common_element('a', array('class' => 'notice',
356 'href' => $noticeurl),
357 common_date_string($notice->created));
358 common_element_end('p');
359 common_element_end('li');