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('rss10', array('nickname' =>
69 'type' => 'application/rss+xml',
70 'title' => _t('Notice feed for ') . $user->nickname));
73 function no_such_user() {
74 common_user_error('No such user');
77 function show_sidebar($profile) {
79 common_element_start('div', 'sidebar width33 floatRight greenBg');
81 $this->show_profile($profile);
83 $this->show_last_notice($profile);
85 $cur = common_current_user();
87 if ($cur && $cur->id != $profile->id) {
88 if ($cur->isSubscribed($profile)) {
89 $this->show_unsubscribe_form($profile);
91 $this->show_subscribe_form($profile);
95 $this->show_statistics($profile);
97 $this->show_subscriptions($profile);
99 common_element_end('div');
102 function show_profile($profile) {
103 common_element_start('div', 'profile');
105 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
107 common_element('img', array('src' => $avatar->url,
108 'class' => 'avatar profile',
109 'width' => AVATAR_PROFILE_SIZE,
110 'height' => AVATAR_PROFILE_SIZE,
111 'alt' => $profile->nickname));
113 if ($profile->fullname) {
114 common_element_start('div', 'fullname');
115 if ($profile->homepage) {
116 common_element('a', array('href' => $profile->homepage),
119 common_text($profile->fullname);
121 common_element_end('div');
123 if ($profile->location) {
124 common_element('div', 'location', $profile->location);
127 common_element('div', 'bio', $profile->bio);
129 common_element_end('div');
132 function show_subscribe_form($profile) {
133 common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
134 'action' => common_local_url('subscribe')));
135 common_element('input', array('id' => 'subscribeto',
136 'name' => 'subscribeto',
138 'value' => $profile->nickname));
139 common_element('input', array('type' => 'submit', 'value' => _t('Subscribe')));
140 common_element_end('form');
143 function show_unsubscribe_form($profile) {
144 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
145 'action' => common_local_url('unsubscribe')));
146 common_element('input', array('id' => 'unsubscribeto',
147 'name' => 'unsubscribeto',
149 'value' => $profile->nickname));
150 common_element('input', array('type' => 'submit'), _t('Unsubscribe'));
151 common_element_end('form');
154 function show_subscriptions($profile) {
158 $subs = $profile->getLink('id', 'subscription', 'subscriber');
160 common_element_start('div', 'subscriptions');
162 common_element('h2', 'subscriptions', _t('Subscriptions'));
167 while ($subs->fetch()) {
169 if ($cnt % SUBSCRIPTIONS_PER_ROW == 1) {
170 common_element_start('div', 'row');
173 common_element_start('a', array('title' => ($subs->fullname) ?
176 'href' => $subs->profileurl,
177 'class' => 'subscription'));
178 $avatar = $subs->getAvatar(AVATAR_MINI_SIZE);
179 common_element('img', array('src' => (($avatar) ? $avatar->url : common_default_avatar(AVATAR_MINI_SIZE)),
180 'width' => AVATAR_MINI_SIZE,
181 'height' => AVATAR_MINI_SIZE,
182 'class' => 'avatar mini',
183 'alt' => ($subs->fullname) ?
186 common_element_end('a');
188 if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
189 common_element_end('div');
192 if ($cnt == SUBSCRIPTIONS) {
198 common_element('a', array('href' => common_local_url('subscriptions',
199 array('nickname' => $profile->nickname)),
200 'class' => 'moresubscriptions'),
201 _t('All subscriptions'));
203 common_element_end('div');
206 function show_statistics($profile) {
208 // XXX: WORM cache this
209 $subs = DB_DataObject::factory('subscription');
210 $subs->subscriber = $profile->id;
211 $subs_count = $subs->count();
217 $subbed = DB_DataObject::factory('subscription');
218 $subbed->subscribed = $profile->id;
219 $subbed_count = $subbed->count();
221 if (!$subbed_count) {
225 $notices = DB_DataObject::factory('notice');
226 $notices->profile_id = $profile->id;
227 $notice_count = $notices->count();
229 if (!$notice_count) {
233 common_element_start('div', 'statistics');
234 common_element('h2', 'statistics', _t('Statistics'));
237 common_element_start('dl', 'statistics');
238 common_element('dt', 'subscriptions', _t('Subscriptions'));
239 common_element('dd', 'subscriptions', $subs_count);
240 common_element('dt', 'subscribers', _t('Subscribers'));
241 common_element('dd', 'subscribers', $subbed_count);
242 common_element('dt', 'notices', _t('Notices'));
243 common_element('dd', 'notices', $notice_count);
244 common_element_end('dl');
246 common_element_end('div');
249 function show_notices($profile) {
251 $notice = DB_DataObject::factory('notice');
252 $notice->profile_id = $profile->id;
254 $notice->orderBy('created DESC');
256 $page = $this->arg('page') || 1;
258 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE);
262 common_element_start('div', 'notices width66 floatLeft');
264 common_element_start('ul', 'bigLinks');
266 while ($notice->fetch()) {
267 $this->show_notice($notice);
270 common_element_end('ul');
272 # XXX: show a link for the next page
273 common_element_end('div');
276 function show_last_notice($profile) {
278 common_element_start('div', 'lastnotice');
279 common_element('h2', 'lastnotice', _t('Currently'));
281 $notice = DB_DataObject::factory('notice');
282 $notice->profile_id = $profile->id;
283 $notice->orderBy('created DESC');
284 $notice->limit(0, 1);
286 if ($notice->find(true)) {
287 # FIXME: URL, image, video, audio
288 common_element('span', array('class' => 'content'),
292 common_element_end('div');
295 function show_notice($notice) {
296 $profile = $notice->getProfile();
298 common_element_start('li', array('class' => 'notice',
299 'id' => 'notice-' . $notice->id));
300 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
301 # FIXME: URL, image, video, audio
302 common_element_start('a', array('class' => 'notice',
303 'href' => $noticeurl));
304 common_element('span', 'title', common_date_string($notice->created));
305 common_element('span', 'desc', $notice->content);
306 common_element_end('a');
307 common_element_end('li');