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, array($this, 'show_header'), $user);
57 $cur = common_current_user();
59 if ($cur && $profile->id == $cur->id) {
63 $this->show_sidebar($profile);
65 $this->show_notices($profile);
70 function show_header($user) {
71 common_element('link', array('rel' => 'alternate',
72 'href' => common_local_url('userrss', array('nickname' =>
74 'type' => 'application/rss+xml',
75 'title' => _t('Notice feed for ') . $user->nickname));
76 common_element('link', array('rel' => 'meta',
77 'href' => common_local_url('foaf', array('nickname' =>
79 'type' => 'application/rdf+xml',
81 # for remote subscriptions etc.
82 common_element('meta', array('http-equiv' => 'X-XRDS-Location',
83 'content' => common_local_url('xrds', array('nickname' =>
87 function no_such_user() {
88 common_user_error('No such user');
91 function show_sidebar($profile) {
93 common_element_start('div', 'sidebar width33 floatRight greenBg');
95 $this->show_profile($profile);
97 $this->show_last_notice($profile);
99 $cur = common_current_user();
102 if ($cur->id != $profile->id) {
103 if ($cur->isSubscribed($profile)) {
104 $this->show_unsubscribe_form($profile);
106 $this->show_subscribe_form($profile);
110 $this->show_remote_subscribe_form($profile);
113 $this->show_statistics($profile);
115 $this->show_subscriptions($profile);
117 common_element_end('div');
120 function show_profile($profile) {
121 common_element_start('div', 'profile');
123 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
125 common_element('img', array('src' => $avatar->url,
126 'class' => 'avatar profile',
127 'width' => AVATAR_PROFILE_SIZE,
128 'height' => AVATAR_PROFILE_SIZE,
129 'alt' => $profile->nickname));
131 if ($profile->fullname) {
132 common_element_start('div', 'fullname');
133 if ($profile->homepage) {
134 common_element('a', array('href' => $profile->homepage),
137 common_text($profile->fullname);
139 common_element_end('div');
141 if ($profile->location) {
142 common_element('div', 'location', $profile->location);
145 common_element('div', 'bio', $profile->bio);
147 common_element_end('div');
150 function show_subscribe_form($profile) {
151 common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
152 'action' => common_local_url('subscribe')));
153 common_element('input', array('id' => 'subscribeto',
154 'name' => 'subscribeto',
156 'value' => $profile->nickname));
157 common_element('input', array('type' => 'submit',
159 'value' => _t('Subscribe')));
160 common_element_end('form');
163 function show_remote_subscribe_form($profile) {
164 common_element_start('form', array('id' => 'remotesubscribe',
166 'action' => common_local_url('remotesubscribe')));
167 common_hidden('nickname', $profile->nickname);
168 common_element('input', array('name' => 'profile',
172 common_element('input', array('type' => 'submit',
175 'value' => _t('Subscribe'),
176 'class' => 'button'));
177 common_element_end('form');
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) {
197 $subs = DB_DataObject::factory('subscription');
198 $subs->subscriber = $profile->id;
200 # We ask for an extra one to know if we need to do another page
202 $subs->limit(0, SUBSCRIPTIONS);
204 $subs_count = $subs->find();
206 common_element_start('div', 'subscriptions');
208 common_element('h2', 'subscriptions', _t('Subscriptions'));
212 while ($subs->fetch()) {
214 if ($idx % SUBSCRIPTIONS_PER_ROW == 1) {
215 common_element_start('div', 'row');
218 $other = Profile::staticGet($subs->subscribed);
220 common_element_start('a', array('title' => ($other->fullname) ?
223 'href' => $other->profileurl,
224 'class' => 'subscription'));
225 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
226 common_element('img', array('src' => (($avatar) ? $avatar->url : common_default_avatar(AVATAR_MINI_SIZE)),
227 'width' => AVATAR_MINI_SIZE,
228 'height' => AVATAR_MINI_SIZE,
229 'class' => 'avatar mini',
230 'alt' => ($other->fullname) ?
233 common_element_end('a');
235 if ($idx % SUBSCRIPTIONS_PER_ROW == 0) {
236 common_element_end('div');
239 if ($idx == SUBSCRIPTIONS) {
244 # close any unclosed row
245 if ($idx % SUBSCRIPTIONS_PER_ROW != 0) {
246 common_element_end('div');
249 common_element('a', array('href' => common_local_url('subscriptions',
250 array('nickname' => $profile->nickname)),
251 'class' => 'moresubscriptions'),
252 _t('All subscriptions'));
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('dt', 'subscriptions', _t('Subscriptions'));
278 common_element('dd', 'subscriptions', $subs_count);
279 common_element('dt', 'subscribers', _t('Subscribers'));
280 common_element('dd', 'subscribers', $subbed_count);
281 common_element('dt', 'notices', _t('Notices'));
282 common_element('dd', 'notices', $notice_count);
283 common_element_end('dl');
285 common_element_end('div');
288 function show_notices($profile) {
290 $notice = DB_DataObject::factory('notice');
291 $notice->profile_id = $profile->id;
293 $notice->orderBy('created DESC');
295 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
297 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
299 $cnt = $notice->find();
301 common_element_start('div', 'notices width66 floatLeft');
303 for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
304 if ($notice->fetch()) {
305 $this->show_notice($notice);
313 common_element_start('span', 'floatLeft width25');
314 common_element('a', array('href' => common_local_url('showstream',
315 array('nickname' => $profile->nickname,
319 common_element_end('span');
322 if ($cnt > NOTICES_PER_PAGE) {
323 common_element_start('span', 'floatRight width25');
324 common_element('a', array('href' => common_local_url('showstream',
325 array('nickname' => $profile->nickname,
329 common_element_end('span');
332 # XXX: show a link for the next page
333 common_element_end('div');
336 function show_last_notice($profile) {
338 common_element_start('div', 'lastnotice');
339 common_element('h2', 'lastnotice', _t('Currently'));
341 $notice = DB_DataObject::factory('notice');
342 $notice->profile_id = $profile->id;
343 $notice->orderBy('created DESC');
344 $notice->limit(0, 1);
346 if ($notice->find(true)) {
347 # FIXME: URL, image, video, audio
348 common_element_start('span', array('class' => 'content'));
349 common_raw(common_render_content($notice->content, $notice));
350 common_element_end('span');
353 common_element_end('div');
356 function show_notice($notice) {
357 $profile = $notice->getProfile();
359 common_element_start('div', array('class' => 'notice',
360 'id' => 'notice-' . $notice->id));
361 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
362 # FIXME: URL, image, video, audio
363 common_element_start('span', array('class' => 'content'));
364 common_raw(common_render_content($notice->content, $notice));
365 common_element_end('span');
366 common_element('a', array('class' => 'notice',
367 'href' => $noticeurl),
368 common_date_string($notice->created));
369 common_element_end('div');