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);
52 $cur = common_current_user();
54 if ($cur && $profile->id == $cur->id) {
58 $this->show_profile($profile);
60 $this->show_last_notice($profile);
62 if ($cur && $cur->id != $profile->id) {
63 if ($cur->isSubscribed($profile)) {
64 $this->show_unsubscribe_form($profile);
66 $this->show_subscribe_form($profile);
70 $this->show_statistics($profile);
72 $this->show_subscriptions($profile);
74 $this->show_notices($profile);
79 function no_such_user() {
80 common_user_error('No such user');
83 function notice_form() {
84 common_element_start('form', array('id' => 'newnotice', 'method' => 'POST',
85 'action' => common_local_url('newnotice')));
86 common_element_start('textarea', array('rows' => 4, 'cols' => 80,
89 common_element_end('textarea');
90 common_element('input', array('type' => 'submit', 'value' => 'Send'));
91 common_element_end('form');
94 function show_profile($profile) {
95 common_element_start('div', 'profile');
97 common_element('h2', 'nickname', $profile->nickname);
99 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
101 common_element('img', array('src' => $avatar->url,
102 'class' => 'avatar profile',
103 'width' => AVATAR_PROFILE_SIZE,
104 'height' => AVATAR_PROFILE_SIZE,
105 'title' => $profile->nickname));
107 if ($profile->fullname) {
108 if ($profile->homepage) {
109 common_element('a', array('href' => $profile->homepage,
110 'class' => 'fullname'),
113 common_element('span', 'fullname', $profile->fullname);
116 if ($profile->location) {
117 common_element('span', 'location', $profile->location);
120 common_element('div', 'bio', $profile->bio);
124 function show_subscribe_form($profile) {
125 common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
126 'action' => common_local_url('subscribe')));
127 common_element('input', array('id' => 'subscribeto',
128 'name' => 'subscribeto',
130 'value' => $profile->nickname));
131 common_element('input', array('type' => 'submit', 'value' => _t('Subscribe')));
132 common_element_end('form');
135 function show_unsubscribe_form($profile) {
136 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
137 'action' => common_local_url('unsubscribe')));
138 common_element('input', array('id' => 'unsubscribeto',
139 'name' => 'unsubscribeto',
141 'value' => $profile->nickname));
142 common_element('input', array('type' => 'submit'), _t('Unsubscribe'));
143 common_element_end('form');
146 function show_subscriptions($profile) {
149 $subs = $profile->getLink('id', 'subscription', 'subscriber');
151 common_element_start('div', 'subscriptions');
153 common_element('h2', 'subscriptions', _t('Subscriptions'));
158 while ($subs->fetch()) {
160 if ($cnt % SUBSCRIPTIONS_PER_ROW == 1) {
161 common_element_start('div', 'row');
164 common_element_start('a', array('title' => $subs->fullname ||
166 'href' => $subs->profileurl,
167 'class' => 'subscription'));
168 $avatar = $subs->getAvatar(AVATAR_MINI_SIZE);
169 common_element('img', array('src' => (($avatar) ? $avatar->url : DEFAULT_MINI_AVATAR),
170 'width' => AVATAR_MINI_SIZE,
171 'height' => AVATAR_MINI_SIZE,
172 'class' => 'avatar mini'));
173 common_element_end('a');
175 if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
176 common_element_end('div');
179 if ($cnt == SUBSCRIPTIONS) {
185 common_element('a', array('href' => common_local_url('subscriptions',
186 array('nickname' => $profile->nickname)),
187 'class' => 'moresubscriptions'),
188 _t('All subscriptions'));
190 common_element_end('div');
193 function show_statistics($profile) {
195 // XXX: WORM cache this
196 $subs = DB_DataObject::factory('subscription');
197 $subs->subscriber = $profile->id;
198 $subs_count = $subs->count();
204 $subbed = DB_DataObject::factory('subscription');
205 $subbed->subscribed = $profile->id;
206 $subbed_count = $subbed->count();
208 if (!$subbed_count) {
212 $notices = DB_DataObject::factory('notice');
213 $notices->profile_id = $profile->id;
214 $notice_count = $notices->count();
216 if (!$notice_count) {
220 common_element_start('div', 'statistics');
221 common_element('h2', 'statistics', _t('Statistics'));
224 common_element_start('dl', 'statistics');
225 common_element('dt', 'subscriptions', _t('Subscriptions'));
226 common_element('dd', 'subscriptions', $subs_count);
227 common_element('dt', 'subscribers', _t('Subscribers'));
228 common_element('dd', 'subscribers', $subbed_count);
229 common_element('dt', 'notices', _t('Notices'));
230 common_element('dd', 'notices', $notice_count);
231 common_element_end('dl');
233 common_element_end('div');
236 function show_notices($profile) {
238 $notice = DB_DataObject::factory('notice');
239 $notice->profile_id = $profile->id;
241 $notice->orderBy('created DESC');
243 $page = $this->arg('page') || 1;
245 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE);
249 common_element_start('div', 'notices');
250 common_element('h2', 'notices', _t('Notices'));
252 while ($notice->fetch()) {
253 $this->show_notice($notice);
255 # XXX: show a link for the next page
256 common_element_end('div');
259 function show_last_notice($profile) {
261 common_element_start('div', 'lastnotice');
262 common_element('h2', 'lastnotice', _t('Currently'));
264 $notice = DB_DataObject::factory('notice');
265 $notice->profile_id = $profile->id;
266 $notice->orderBy('created DESC');
267 $notice->limit(0, 1);
269 if ($notice->find(true)) {
270 # FIXME: URL, image, video, audio
271 common_element('span', array('class' => 'content'),
273 common_element('span', array('class' => 'date'),
274 common_date_string($notice->created));
277 common_element_end('div');