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', 5);
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; show the header
50 common_show_header($profile->nickname, array($this, 'show_header'), $user);
52 $cur = common_current_user();
54 if ($cur && $profile->id == $cur->id) {
58 $this->show_sidebar($profile);
60 $this->show_notices($profile);
65 function show_header($user) {
66 common_element('link', array('rel' => 'alternate',
67 'href' => common_local_url('userrss', array('nickname' =>
69 'type' => 'application/rss+xml',
70 'title' => _t('Notice feed for ') . $user->nickname));
71 # for remote subscriptions etc.
72 common_element('meta', array('http-equiv' => 'X-XRDS-Location',
73 'content' => common_local_url('xrds', array('nickname' =>
77 function no_such_user() {
78 common_user_error('No such user');
81 function show_sidebar($profile) {
83 common_element_start('div', 'sidebar width33 floatRight greenBg');
85 $this->show_profile($profile);
87 $this->show_last_notice($profile);
89 $cur = common_current_user();
91 if ($cur && $cur->id != $profile->id) {
92 if ($cur->isSubscribed($profile)) {
93 $this->show_unsubscribe_form($profile);
95 $this->show_subscribe_form($profile);
99 $this->show_statistics($profile);
101 $this->show_subscriptions($profile);
103 common_element_end('div');
106 function show_profile($profile) {
107 common_element_start('div', 'profile');
109 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
111 common_element('img', array('src' => $avatar->url,
112 'class' => 'avatar profile',
113 'width' => AVATAR_PROFILE_SIZE,
114 'height' => AVATAR_PROFILE_SIZE,
115 'alt' => $profile->nickname));
117 if ($profile->fullname) {
118 common_element_start('div', 'fullname');
119 if ($profile->homepage) {
120 common_element('a', array('href' => $profile->homepage),
123 common_text($profile->fullname);
125 common_element_end('div');
127 if ($profile->location) {
128 common_element('div', 'location', $profile->location);
131 common_element('div', 'bio', $profile->bio);
133 common_element_end('div');
136 function show_subscribe_form($profile) {
137 common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
138 'action' => common_local_url('subscribe')));
139 common_element('input', array('id' => 'subscribeto',
140 'name' => 'subscribeto',
142 'value' => $profile->nickname));
143 common_element('input', array('type' => 'submit',
145 'value' => _t('Subscribe')));
146 common_element_end('form');
149 function show_unsubscribe_form($profile) {
150 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
151 'action' => common_local_url('unsubscribe')));
152 common_element('input', array('id' => 'unsubscribeto',
153 'name' => 'unsubscribeto',
155 'value' => $profile->nickname));
156 common_element('input', array('type' => 'submit',
158 'value' => _t('Unsubscribe')));
159 common_element_end('form');
162 function show_subscriptions($profile) {
166 $subs = DB_DataObject::factory('subscription');
167 $subs->subscriber = $profile->id;
169 # We ask for an extra one to know if we need to do another page
171 $subs->limit(0, SUBSCRIPTIONS);
173 $subs_count = $subs->find();
175 common_element_start('div', 'subscriptions');
177 common_element('h2', 'subscriptions', _t('Subscriptions'));
181 while ($subs->fetch()) {
183 if ($idx % SUBSCRIPTIONS_PER_ROW == 1) {
184 common_element_start('div', 'row');
187 $other = Profile::staticGet($subs->subscribed);
189 common_element_start('a', array('title' => ($other->fullname) ?
192 'href' => $other->profileurl,
193 'class' => 'subscription'));
194 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
195 common_element('img', array('src' => (($avatar) ? $avatar->url : common_default_avatar(AVATAR_MINI_SIZE)),
196 'width' => AVATAR_MINI_SIZE,
197 'height' => AVATAR_MINI_SIZE,
198 'class' => 'avatar mini',
199 'alt' => ($other->fullname) ?
202 common_element_end('a');
204 if ($idx % SUBSCRIPTIONS_PER_ROW == 0) {
205 common_element_end('div');
208 if ($idx == SUBSCRIPTIONS) {
213 # close any unclosed row
214 if ($idx % SUBSCRIPTIONS_PER_ROW != 0) {
215 common_element_end('div');
218 common_element('a', array('href' => common_local_url('subscriptions',
219 array('nickname' => $profile->nickname)),
220 'class' => 'moresubscriptions'),
221 _t('All subscriptions'));
223 common_element_end('div');
226 function show_statistics($profile) {
228 // XXX: WORM cache this
229 $subs = DB_DataObject::factory('subscription');
230 $subs->subscriber = $profile->id;
231 $subs_count = (int) $subs->count();
233 $subbed = DB_DataObject::factory('subscription');
234 $subbed->subscribed = $profile->id;
235 $subbed_count = (int) $subbed->count();
237 $notices = DB_DataObject::factory('notice');
238 $notices->profile_id = $profile->id;
239 $notice_count = (int) $notices->count();
241 common_element_start('div', 'statistics');
242 common_element('h2', 'statistics', _t('Statistics'));
245 common_element_start('dl', 'statistics');
246 common_element('dt', 'subscriptions', _t('Subscriptions'));
247 common_element('dd', 'subscriptions', $subs_count);
248 common_element('dt', 'subscribers', _t('Subscribers'));
249 common_element('dd', 'subscribers', $subbed_count);
250 common_element('dt', 'notices', _t('Notices'));
251 common_element('dd', 'notices', $notice_count);
252 common_element_end('dl');
254 common_element_end('div');
257 function show_notices($profile) {
259 $notice = DB_DataObject::factory('notice');
260 $notice->profile_id = $profile->id;
262 $notice->orderBy('created DESC');
264 $page = $this->arg('page') || 1;
266 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
268 $cnt = $notice->find();
270 common_element_start('div', 'notices width66 floatLeft');
272 common_element_start('ul', 'bigLinks');
274 for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
275 if ($notice->fetch()) {
276 $this->show_notice($notice);
283 common_element_end('ul');
286 common_element_start('span', 'floatLeft width25');
287 common_element('a', array('href' => common_local_url('showstream',
288 array('nickname' => $profile->nickname,
292 common_element_end('span');
295 if ($cnt > NOTICES_PER_PAGE) {
296 common_element_start('span', 'floatRight width25');
297 common_element('a', array('href' => common_local_url('showstream',
298 array('nickname' => $profile->nickname,
302 common_element_end('span');
305 # XXX: show a link for the next page
306 common_element_end('div');
309 function show_last_notice($profile) {
311 common_element_start('div', 'lastnotice');
312 common_element('h2', 'lastnotice', _t('Currently'));
314 $notice = DB_DataObject::factory('notice');
315 $notice->profile_id = $profile->id;
316 $notice->orderBy('created DESC');
317 $notice->limit(0, 1);
319 if ($notice->find(true)) {
320 # FIXME: URL, image, video, audio
321 common_element('span', array('class' => 'content'),
325 common_element_end('div');
328 function show_notice($notice) {
329 $profile = $notice->getProfile();
331 common_element_start('li', array('class' => 'notice',
332 'id' => 'notice-' . $notice->id));
333 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
334 # FIXME: URL, image, video, audio
335 common_element_start('a', array('class' => 'notice',
336 'href' => $noticeurl));
337 common_element('span', 'title', common_date_string($notice->created));
338 common_element('span', 'desc', $notice->content);
339 common_element_end('a');
340 common_element_end('li');