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', 'method' => 'POST',
160 'action' => common_local_url('remotesubscribe')));
161 common_hidden('nickname', $profile->nickname);
162 common_input('profile', _t('Profile'));
163 common_submit('submit',_t('Subscribe'));
164 common_element_end('form');
167 function show_unsubscribe_form($profile) {
168 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
169 'action' => common_local_url('unsubscribe')));
170 common_element('input', array('id' => 'unsubscribeto',
171 'name' => 'unsubscribeto',
173 'value' => $profile->nickname));
174 common_element('input', array('type' => 'submit',
176 'value' => _t('Unsubscribe')));
177 common_element_end('form');
180 function show_subscriptions($profile) {
184 $subs = DB_DataObject::factory('subscription');
185 $subs->subscriber = $profile->id;
187 # We ask for an extra one to know if we need to do another page
189 $subs->limit(0, SUBSCRIPTIONS);
191 $subs_count = $subs->find();
193 common_element_start('div', 'subscriptions');
195 common_element('h2', 'subscriptions', _t('Subscriptions'));
199 while ($subs->fetch()) {
201 if ($idx % SUBSCRIPTIONS_PER_ROW == 1) {
202 common_element_start('div', 'row');
205 $other = Profile::staticGet($subs->subscribed);
207 common_element_start('a', array('title' => ($other->fullname) ?
210 'href' => $other->profileurl,
211 'class' => 'subscription'));
212 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
213 common_element('img', array('src' => (($avatar) ? $avatar->url : common_default_avatar(AVATAR_MINI_SIZE)),
214 'width' => AVATAR_MINI_SIZE,
215 'height' => AVATAR_MINI_SIZE,
216 'class' => 'avatar mini',
217 'alt' => ($other->fullname) ?
220 common_element_end('a');
222 if ($idx % SUBSCRIPTIONS_PER_ROW == 0) {
223 common_element_end('div');
226 if ($idx == SUBSCRIPTIONS) {
231 # close any unclosed row
232 if ($idx % SUBSCRIPTIONS_PER_ROW != 0) {
233 common_element_end('div');
236 common_element('a', array('href' => common_local_url('subscriptions',
237 array('nickname' => $profile->nickname)),
238 'class' => 'moresubscriptions'),
239 _t('All subscriptions'));
241 common_element_end('div');
244 function show_statistics($profile) {
246 // XXX: WORM cache this
247 $subs = DB_DataObject::factory('subscription');
248 $subs->subscriber = $profile->id;
249 $subs_count = (int) $subs->count();
251 $subbed = DB_DataObject::factory('subscription');
252 $subbed->subscribed = $profile->id;
253 $subbed_count = (int) $subbed->count();
255 $notices = DB_DataObject::factory('notice');
256 $notices->profile_id = $profile->id;
257 $notice_count = (int) $notices->count();
259 common_element_start('div', 'statistics');
260 common_element('h2', 'statistics', _t('Statistics'));
263 common_element_start('dl', 'statistics');
264 common_element('dt', 'subscriptions', _t('Subscriptions'));
265 common_element('dd', 'subscriptions', $subs_count);
266 common_element('dt', 'subscribers', _t('Subscribers'));
267 common_element('dd', 'subscribers', $subbed_count);
268 common_element('dt', 'notices', _t('Notices'));
269 common_element('dd', 'notices', $notice_count);
270 common_element_end('dl');
272 common_element_end('div');
275 function show_notices($profile) {
277 $notice = DB_DataObject::factory('notice');
278 $notice->profile_id = $profile->id;
280 $notice->orderBy('created DESC');
282 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
284 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
286 $cnt = $notice->find();
288 common_element_start('div', 'notices width66 floatLeft');
290 for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
291 if ($notice->fetch()) {
292 $this->show_notice($notice);
300 common_element_start('span', 'floatLeft width25');
301 common_element('a', array('href' => common_local_url('showstream',
302 array('nickname' => $profile->nickname,
306 common_element_end('span');
309 if ($cnt > NOTICES_PER_PAGE) {
310 common_element_start('span', 'floatRight width25');
311 common_element('a', array('href' => common_local_url('showstream',
312 array('nickname' => $profile->nickname,
316 common_element_end('span');
319 # XXX: show a link for the next page
320 common_element_end('div');
323 function show_last_notice($profile) {
325 common_element_start('div', 'lastnotice');
326 common_element('h2', 'lastnotice', _t('Currently'));
328 $notice = DB_DataObject::factory('notice');
329 $notice->profile_id = $profile->id;
330 $notice->orderBy('created DESC');
331 $notice->limit(0, 1);
333 if ($notice->find(true)) {
334 # FIXME: URL, image, video, audio
335 common_element_start('span', array('class' => 'content'));
336 common_raw(common_render_content($notice->content, $notice));
337 common_element_end('span');
340 common_element_end('div');
343 function show_notice($notice) {
344 $profile = $notice->getProfile();
346 common_element_start('div', array('class' => 'notice',
347 'id' => 'notice-' . $notice->id));
348 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
349 # FIXME: URL, image, video, audio
350 common_element_start('span', array('class' => 'content'));
351 common_raw(common_render_content($notice->content, $notice));
352 common_element_end('span');
353 common_element('a', array('class' => 'notice',
354 'href' => $noticeurl),
355 common_date_string($notice->created));
356 common_element_end('div');