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 if ($cur && $cur->id != $profile->id) {
86 if ($cur->isSubscribed($profile)) {
87 $this->show_unsubscribe_form($profile);
89 $this->show_subscribe_form($profile);
93 $this->show_statistics($profile);
95 $this->show_subscriptions($profile);
97 common_element_end('div');
100 function show_profile($profile) {
101 common_element_start('div', 'profile');
103 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
105 common_element('img', array('src' => $avatar->url,
106 'class' => 'avatar profile',
107 'width' => AVATAR_PROFILE_SIZE,
108 'height' => AVATAR_PROFILE_SIZE,
109 'alt' => $profile->nickname));
111 if ($profile->fullname) {
112 common_element_start('div', 'fullname');
113 if ($profile->homepage) {
114 common_element('a', array('href' => $profile->homepage),
117 common_text($profile->fullname);
119 common_element_end('div');
121 if ($profile->location) {
122 common_element('div', 'location', $profile->location);
125 common_element('div', 'bio', $profile->bio);
127 common_element_end('div');
130 function show_subscribe_form($profile) {
131 common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
132 'action' => common_local_url('subscribe')));
133 common_element('input', array('id' => 'subscribeto',
134 'name' => 'subscribeto',
136 'value' => $profile->nickname));
137 common_element('input', array('type' => 'submit', 'value' => _t('Subscribe')));
138 common_element_end('form');
141 function show_unsubscribe_form($profile) {
142 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
143 'action' => common_local_url('unsubscribe')));
144 common_element('input', array('id' => 'unsubscribeto',
145 'name' => 'unsubscribeto',
147 'value' => $profile->nickname));
148 common_element('input', array('type' => 'submit'), _t('Unsubscribe'));
149 common_element_end('form');
152 function show_subscriptions($profile) {
156 $subs = $profile->getLink('id', 'subscription', 'subscriber');
158 common_element_start('div', 'subscriptions');
160 common_element('h2', 'subscriptions', _t('Subscriptions'));
165 while ($subs->fetch()) {
167 if ($cnt % SUBSCRIPTIONS_PER_ROW == 1) {
168 common_element_start('div', 'row');
171 common_element_start('a', array('title' => ($subs->fullname) ?
174 'href' => $subs->profileurl,
175 'class' => 'subscription'));
176 $avatar = $subs->getAvatar(AVATAR_MINI_SIZE);
177 common_element('img', array('src' => (($avatar) ? $avatar->url : $config['avatar']['default']['mini']),
178 'width' => AVATAR_MINI_SIZE,
179 'height' => AVATAR_MINI_SIZE,
180 'class' => 'avatar mini',
181 'alt' => ($subs->fullname) ?
184 common_element_end('a');
186 if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
187 common_element_end('div');
190 if ($cnt == SUBSCRIPTIONS) {
196 common_element('a', array('href' => common_local_url('subscriptions',
197 array('nickname' => $profile->nickname)),
198 'class' => 'moresubscriptions'),
199 _t('All subscriptions'));
201 common_element_end('div');
204 function show_statistics($profile) {
206 // XXX: WORM cache this
207 $subs = DB_DataObject::factory('subscription');
208 $subs->subscriber = $profile->id;
209 $subs_count = $subs->count();
215 $subbed = DB_DataObject::factory('subscription');
216 $subbed->subscribed = $profile->id;
217 $subbed_count = $subbed->count();
219 if (!$subbed_count) {
223 $notices = DB_DataObject::factory('notice');
224 $notices->profile_id = $profile->id;
225 $notice_count = $notices->count();
227 if (!$notice_count) {
231 common_element_start('div', 'statistics');
232 common_element('h2', 'statistics', _t('Statistics'));
235 common_element_start('dl', 'statistics');
236 common_element('dt', 'subscriptions', _t('Subscriptions'));
237 common_element('dd', 'subscriptions', $subs_count);
238 common_element('dt', 'subscribers', _t('Subscribers'));
239 common_element('dd', 'subscribers', $subbed_count);
240 common_element('dt', 'notices', _t('Notices'));
241 common_element('dd', 'notices', $notice_count);
242 common_element_end('dl');
244 common_element_end('div');
247 function show_notices($profile) {
249 $notice = DB_DataObject::factory('notice');
250 $notice->profile_id = $profile->id;
252 $notice->orderBy('created DESC');
254 $page = $this->arg('page') || 1;
256 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE);
260 common_element_start('div', 'notices width66 floatLeft');
262 common_element_start('ul', 'bigLinks');
264 while ($notice->fetch()) {
265 $this->show_notice($notice);
268 common_element_end('ul');
270 # XXX: show a link for the next page
271 common_element_end('div');
274 function show_last_notice($profile) {
276 common_element_start('div', 'lastnotice');
277 common_element('h2', 'lastnotice', _t('Currently'));
279 $notice = DB_DataObject::factory('notice');
280 $notice->profile_id = $profile->id;
281 $notice->orderBy('created DESC');
282 $notice->limit(0, 1);
284 if ($notice->find(true)) {
285 # FIXME: URL, image, video, audio
286 common_element('span', array('class' => 'content'),
290 common_element_end('div');
293 function show_notice($notice) {
294 $profile = $notice->getProfile();
296 common_element_start('li', array('class' => 'notice',
297 'id' => 'notice-' . $notice->id));
298 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
299 # FIXME: URL, image, video, audio
300 common_element_start('a', array('class' => 'notice',
301 'href' => $noticeurl));
302 common_element('span', 'title', common_date_string($notice->created));
303 common_element('span', 'desc', $notice->content);
304 common_element_end('a');
305 common_element_end('li');