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 # for remote subscriptions etc.
77 common_element('meta', array('http-equiv' => 'X-XRDS-Location',
78 'content' => common_local_url('xrds', array('nickname' =>
82 function no_such_user() {
83 common_user_error('No such user');
86 function show_sidebar($profile) {
88 common_element_start('div', 'sidebar width33 floatRight greenBg');
90 $this->show_profile($profile);
92 $this->show_last_notice($profile);
94 $cur = common_current_user();
97 if ($cur->id != $profile->id) {
98 if ($cur->isSubscribed($profile)) {
99 $this->show_unsubscribe_form($profile);
101 $this->show_subscribe_form($profile);
105 $this->show_remote_subscribe_form($profile);
108 $this->show_statistics($profile);
110 $this->show_subscriptions($profile);
112 common_element_end('div');
115 function show_profile($profile) {
116 common_element_start('div', 'profile');
118 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
120 common_element('img', array('src' => $avatar->url,
121 'class' => 'avatar profile',
122 'width' => AVATAR_PROFILE_SIZE,
123 'height' => AVATAR_PROFILE_SIZE,
124 'alt' => $profile->nickname));
126 if ($profile->fullname) {
127 common_element_start('div', 'fullname');
128 if ($profile->homepage) {
129 common_element('a', array('href' => $profile->homepage),
132 common_text($profile->fullname);
134 common_element_end('div');
136 if ($profile->location) {
137 common_element('div', 'location', $profile->location);
140 common_element('div', 'bio', $profile->bio);
142 common_element_end('div');
145 function show_subscribe_form($profile) {
146 common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
147 'action' => common_local_url('subscribe')));
148 common_element('input', array('id' => 'subscribeto',
149 'name' => 'subscribeto',
151 'value' => $profile->nickname));
152 common_element('input', array('type' => 'submit',
154 'value' => _t('Subscribe')));
155 common_element_end('form');
158 function show_remote_subscribe_form($profile) {
159 common_element_start('form', array('id' => 'remotesubscribe',
161 'action' => common_local_url('remotesubscribe')));
162 common_hidden('nickname', $profile->nickname);
163 common_element('input', array('name' => 'profile',
167 common_element('input', array('type' => 'submit',
170 'value' => _t('Subscribe'),
171 'class' => 'button'));
172 common_element_end('form');
175 function show_unsubscribe_form($profile) {
176 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
177 'action' => common_local_url('unsubscribe')));
178 common_element('input', array('id' => 'unsubscribeto',
179 'name' => 'unsubscribeto',
181 'value' => $profile->nickname));
182 common_element('input', array('type' => 'submit',
184 'value' => _t('Unsubscribe')));
185 common_element_end('form');
188 function show_subscriptions($profile) {
192 $subs = DB_DataObject::factory('subscription');
193 $subs->subscriber = $profile->id;
195 # We ask for an extra one to know if we need to do another page
197 $subs->limit(0, SUBSCRIPTIONS);
199 $subs_count = $subs->find();
201 common_element_start('div', 'subscriptions');
203 common_element('h2', 'subscriptions', _t('Subscriptions'));
207 while ($subs->fetch()) {
209 if ($idx % SUBSCRIPTIONS_PER_ROW == 1) {
210 common_element_start('div', 'row');
213 $other = Profile::staticGet($subs->subscribed);
215 common_element_start('a', array('title' => ($other->fullname) ?
218 'href' => $other->profileurl,
219 'class' => 'subscription'));
220 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
221 common_element('img', array('src' => (($avatar) ? $avatar->url : common_default_avatar(AVATAR_MINI_SIZE)),
222 'width' => AVATAR_MINI_SIZE,
223 'height' => AVATAR_MINI_SIZE,
224 'class' => 'avatar mini',
225 'alt' => ($other->fullname) ?
228 common_element_end('a');
230 if ($idx % SUBSCRIPTIONS_PER_ROW == 0) {
231 common_element_end('div');
234 if ($idx == SUBSCRIPTIONS) {
239 # close any unclosed row
240 if ($idx % SUBSCRIPTIONS_PER_ROW != 0) {
241 common_element_end('div');
244 common_element('a', array('href' => common_local_url('subscriptions',
245 array('nickname' => $profile->nickname)),
246 'class' => 'moresubscriptions'),
247 _t('All subscriptions'));
249 common_element_end('div');
252 function show_statistics($profile) {
254 // XXX: WORM cache this
255 $subs = DB_DataObject::factory('subscription');
256 $subs->subscriber = $profile->id;
257 $subs_count = (int) $subs->count();
259 $subbed = DB_DataObject::factory('subscription');
260 $subbed->subscribed = $profile->id;
261 $subbed_count = (int) $subbed->count();
263 $notices = DB_DataObject::factory('notice');
264 $notices->profile_id = $profile->id;
265 $notice_count = (int) $notices->count();
267 common_element_start('div', 'statistics');
268 common_element('h2', 'statistics', _t('Statistics'));
271 common_element_start('dl', 'statistics');
272 common_element('dt', 'subscriptions', _t('Subscriptions'));
273 common_element('dd', 'subscriptions', $subs_count);
274 common_element('dt', 'subscribers', _t('Subscribers'));
275 common_element('dd', 'subscribers', $subbed_count);
276 common_element('dt', 'notices', _t('Notices'));
277 common_element('dd', 'notices', $notice_count);
278 common_element_end('dl');
280 common_element_end('div');
283 function show_notices($profile) {
285 $notice = DB_DataObject::factory('notice');
286 $notice->profile_id = $profile->id;
288 $notice->orderBy('created DESC');
290 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
292 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
294 $cnt = $notice->find();
296 common_element_start('div', 'notices width66 floatLeft');
298 for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
299 if ($notice->fetch()) {
300 $this->show_notice($notice);
308 common_element_start('span', 'floatLeft width25');
309 common_element('a', array('href' => common_local_url('showstream',
310 array('nickname' => $profile->nickname,
314 common_element_end('span');
317 if ($cnt > NOTICES_PER_PAGE) {
318 common_element_start('span', 'floatRight width25');
319 common_element('a', array('href' => common_local_url('showstream',
320 array('nickname' => $profile->nickname,
324 common_element_end('span');
327 # XXX: show a link for the next page
328 common_element_end('div');
331 function show_last_notice($profile) {
333 common_element_start('div', 'lastnotice');
334 common_element('h2', 'lastnotice', _t('Currently'));
336 $notice = DB_DataObject::factory('notice');
337 $notice->profile_id = $profile->id;
338 $notice->orderBy('created DESC');
339 $notice->limit(0, 1);
341 if ($notice->find(true)) {
342 # FIXME: URL, image, video, audio
343 common_element_start('span', array('class' => 'content'));
344 common_raw(common_render_content($notice->content, $notice));
345 common_element_end('span');
348 common_element_end('div');
351 function show_notice($notice) {
352 $profile = $notice->getProfile();
354 common_element_start('div', array('class' => 'notice',
355 'id' => 'notice-' . $notice->id));
356 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
357 # FIXME: URL, image, video, audio
358 common_element_start('span', array('class' => 'content'));
359 common_raw(common_render_content($notice->content, $notice));
360 common_element_end('span');
361 common_element('a', array('class' => 'notice',
362 'href' => $noticeurl),
363 common_date_string($notice->created));
364 common_element_end('div');