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) {
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);
117 common_element_start('div', array('id' => 'profile_avatar'));
118 common_element('img', array('src' => $avatar->url,
119 'class' => 'avatar profile',
120 'width' => AVATAR_PROFILE_SIZE,
121 'height' => AVATAR_PROFILE_SIZE,
122 'alt' => $profile->nickname));
123 $cur = common_current_user();
125 if ($cur->id != $profile->id) {
126 if ($cur->isSubscribed($profile)) {
127 $this->show_unsubscribe_form($profile);
129 $this->show_subscribe_form($profile);
133 $this->show_remote_subscribe_form($profile);
135 common_element_end('div');
137 common_element_start('div', array('id' => 'profile_information'));
139 if ($profile->fullname) {
140 common_element('h1', NULL, $profile->fullname);
142 if ($profile->location) {
143 common_element('p', 'location', $profile->location);
146 common_element('p', 'description', htmlspecialchars($profile->bio));
148 if ($profile->homepage) {
149 common_element_start('p', 'website');
150 common_element('a', array('href' => $profile->homepage),
152 common_element_end('p');
155 $this->show_statistics($profile);
157 common_element_end('div');
160 function show_subscribe_form($profile) {
161 common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
162 'action' => common_local_url('subscribe')));
163 common_element('input', array('id' => 'subscribeto',
164 'name' => 'subscribeto',
166 'value' => $profile->nickname));
167 common_element('input', array('type' => 'submit',
169 'value' => _t('Subscribe')));
170 common_element_end('form');
173 function show_remote_subscribe_form($profile) {
174 common_element_start('form', array('id' => 'remotesubscribe',
176 'action' => common_local_url('remotesubscribe')));
177 common_hidden('nickname', $profile->nickname);
178 common_element('input', array('name' => 'profile_url',
180 'id' => 'profile_url',
182 common_element('input', array('type' => 'submit',
185 'value' => _t('Subscribe'),
186 'class' => 'button'));
187 common_element_end('form');
190 function show_unsubscribe_form($profile) {
191 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
192 'action' => common_local_url('unsubscribe')));
193 common_element('input', array('id' => 'unsubscribeto',
194 'name' => 'unsubscribeto',
196 'value' => $profile->nickname));
197 common_element('input', array('type' => 'submit',
199 'value' => _t('Unsubscribe')));
200 common_element_end('form');
203 function show_subscriptions($profile) {
207 $subs = DB_DataObject::factory('subscription');
208 $subs->subscriber = $profile->id;
210 # We ask for an extra one to know if we need to do another page
212 $subs->limit(0, SUBSCRIPTIONS);
214 $subs_count = $subs->find();
216 common_element_start('div', array('id' => 'subscriptions'));
218 common_element('h2', NULL, _t('Subscriptions'));
220 if ($subs_count > 0) {
222 common_element_start('ul', array('id' => 'subscriptions_avatars'));
224 while ($subs->fetch()) {
226 $other = Profile::staticGet($subs->subscribed);
228 common_element_start('li');
229 common_element_start('a', array('title' => ($other->fullname) ?
232 'href' => $other->profileurl,
233 'class' => 'subscription'));
234 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
235 common_element('img', array('src' => (($avatar) ? $avatar->url : common_default_avatar(AVATAR_MINI_SIZE)),
236 'width' => AVATAR_MINI_SIZE,
237 'height' => AVATAR_MINI_SIZE,
238 'class' => 'avatar mini',
239 'alt' => ($other->fullname) ?
242 common_element_end('a');
243 common_element_end('li');
245 common_element_end('ul');
248 common_element_start('p', array('id' => 'subscriptions_viewall'));
250 common_element('a', array('href' => common_local_url('subscriptions',
251 array('nickname' => $profile->nickname)),
252 'class' => 'moresubscriptions'),
253 _t('All subscriptions'));
255 common_element_end('p');
257 common_element_end('div');
260 function show_statistics($profile) {
262 // XXX: WORM cache this
263 $subs = DB_DataObject::factory('subscription');
264 $subs->subscriber = $profile->id;
265 $subs_count = (int) $subs->count();
267 $subbed = DB_DataObject::factory('subscription');
268 $subbed->subscribed = $profile->id;
269 $subbed_count = (int) $subbed->count();
271 $notices = DB_DataObject::factory('notice');
272 $notices->profile_id = $profile->id;
273 $notice_count = (int) $notices->count();
275 common_element_start('div', 'statistics');
276 common_element('h2', 'statistics', _t('Statistics'));
279 common_element_start('dl', 'statistics');
280 common_element('dt', 'subscriptions', _t('Subscriptions'));
281 common_element('dd', 'subscriptions', $subs_count);
282 common_element('dt', 'subscribers', _t('Subscribers'));
283 common_element('dd', 'subscribers', $subbed_count);
284 common_element('dt', 'notices', _t('Notices'));
285 common_element('dd', 'notices', $notice_count);
286 common_element_end('dl');
288 common_element_end('div');
291 function show_notices($profile) {
293 $notice = DB_DataObject::factory('notice');
294 $notice->profile_id = $profile->id;
296 $notice->orderBy('created DESC');
298 $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
300 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
302 $cnt = $notice->find();
305 common_element_start('ul', array('id' => 'notices'));
307 for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
308 if ($notice->fetch()) {
309 $this->show_notice($notice);
316 common_element_end('ul');
318 common_pagination($page>1, $cnt>NOTICES_PER_PAGE, $page,
319 'showstream', array('nickname' => $profile->nickname));
322 function show_last_notice($profile) {
324 common_element('h2', NULL, _t('Currently'));
326 $notice = DB_DataObject::factory('notice');
327 $notice->profile_id = $profile->id;
328 $notice->orderBy('created DESC');
329 $notice->limit(0, 1);
331 if ($notice->find(true)) {
332 # FIXME: URL, image, video, audio
333 common_element_start('p', array('class' => 'notice_current'));
334 common_raw(common_render_content($notice->content, $notice));
335 common_element_end('p');
339 function show_notice($notice) {
340 $profile = $notice->getProfile();
342 common_element_start('li', array('class' => 'notice_single',
343 'id' => 'notice-' . $notice->id));
344 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
345 # FIXME: URL, image, video, audio
346 common_element_start('p');
347 common_raw(common_render_content($notice->content, $notice));
348 common_element_end('p');
349 common_element_start('p', array('class' => 'time'));
350 common_element('a', array('class' => 'notice',
351 'href' => $noticeurl),
352 common_date_string($notice->created));
353 common_element_end('p');
354 common_element_end('li');