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();
40 $profile = $user->getProfile();
43 common_server_error(_t('User record exists without profile.'));
46 # Looks like we're good; show the header
48 common_show_header($profile->nickname);
50 $cur = common_current_user();
52 if ($cur && $profile->id == $cur->id) {
56 $this->show_profile($profile);
58 $this->show_last_notice($profile);
61 if ($cur->isSubscribed($profile)) {
62 $this->show_unsubscribe_form($profile);
64 $this->show_subscribe_form($profile);
68 $this->show_statistics($profile);
70 $this->show_subscriptions($profile);
72 $this->show_notices($profile);
77 function no_such_user() {
78 common_user_error('No such user');
81 function notice_form() {
82 common_element_start('form', array('id' => 'newnotice', 'method' => 'POST',
83 'action' => common_local_url('newnotice')));
84 common_element('textarea', array('rows' => 4, 'cols' => 80, 'id' => 'content'));
85 common_element('input', array('type' => 'submit'), 'Send');
86 common_element_end('form');
89 function show_profile($profile) {
90 common_element_start('div', 'profile');
91 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
93 common_element('img', array('src' => $avatar->url,
94 'class' => 'avatar profile',
95 'width' => AVATAR_PROFILE_SIZE,
96 'height' => AVATAR_PROFILE_SIZE,
97 'title' => $profile->nickname));
99 common_element('span', 'nickname', $profile->nickname);
100 if ($profile->fullname) {
101 if ($profile->homepage) {
102 common_element('a', array('href' => $profile->homepage,
103 'class' => 'fullname'),
106 common_element('span', 'fullname', $profile->fullname);
109 if ($profile->location) {
110 common_element('span', 'location', $profile->location);
113 common_element('div', 'bio', $profile->bio);
117 function show_subscribe_form($profile) {
118 common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
119 'action' => common_local_url('subscribe')));
120 common_element('input', array('id' => 'subscribeto',
121 'name' => 'subscribeto',
123 'value' => $profile->nickname));
124 common_element('input', array('type' => 'submit'), _t('subscribe'));
125 common_element_end('form');
128 function show_unsubscribe_form($profile) {
129 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
130 'action' => common_local_url('unsubscribe')));
131 common_element('input', array('id' => 'unsubscribeto',
132 'name' => 'unsubscribeto',
134 'value' => $profile->nickname));
135 common_element('input', array('type' => 'submit'), _t('unsubscribe'));
136 common_element_end('form');
139 function show_subscriptions($profile) {
142 $subs = $profile->getLink('id', 'subscription', 'subscriber');
144 common_element_start('div', 'subscriptions');
149 while ($subs->fetch()) {
151 if ($cnt % SUBSCRIPTIONS_PER_ROW == 1) {
152 common_element_start('div', 'row');
155 common_element_start('a', array('title' => $subs->fullname ||
157 'href' => $subs->profileurl,
158 'class' => 'subscription'));
159 $avatar = $subs->getAvatar(AVATAR_MINI_SIZE);
160 common_element('img', array('src' => (($avatar) ? $avatar->url : DEFAULT_MINI_AVATAR),
161 'width' => AVATAR_MINI_SIZE,
162 'height' => AVATAR_MINI_SIZE,
163 'class' => 'avatar mini'));
164 common_element_end('a');
166 if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
167 common_element_end('div');
170 if ($cnt == SUBSCRIPTIONS) {
176 common_element('a', array('href' => common_local_url('subscriptions',
177 array('nickname' => $profile->nickname)),
178 'class' => 'moresubscriptions'),
179 _t('All subscriptions'));
181 common_element_end('div');
184 function show_statistics($profile) {
186 // XXX: WORM cache this
187 $subs = DB_DataObject::factory('subscription');
188 $subs->subscriber = $profile->id;
189 $subs_count = $subs->count();
191 $subbed = DB_DataObject::factory('subscription');
192 $subbed->subscribed = $profile->id;
193 $subbed_count = $subbed->count();
195 $notices = DB_DataObject::factory('notice');
196 $notices->profile_id = $profile->id;
197 $notice_count = $notices->count();
200 common_element_start('dl', 'statistics');
201 common_element('dt', _t('Subscriptions'));
202 common_element('dd', $subs_count);
203 common_element('dt', _t('Subscribers'));
204 common_element('dd', $subbed_count);
205 common_element('dt', _t('Notices'));
206 common_element('dd', $notice_count);
207 common_element_end('dl');
210 function show_notices($profile) {
212 $notice = DB_DataObject::factory('notice');
213 $notice->profile_id = $profile->id;
215 $notice->orderBy('created DESC');
217 $page = $this->arg('page') || 1;
219 $notice->limit((($page-1)*NOTICES_PER_PAGE) + 1, NOTICES_PER_PAGE);
223 common_element_start('div', 'notices');
225 while ($notice->fetch()) {
226 $this->show_notice($notice);
229 common_element_end('div');
232 function show_last_notice($profile) {
233 $notice = DB_DataObject::factory('notice');
234 $notice->profile_id = $profile->id;
235 $notice->orderBy('created DESC');
236 $notice->limit(1, 1);
239 while ($notice->fetch()) {
240 # FIXME: URL, image, video, audio
241 common_element('span', array('class' => 'content'),
243 common_element('span', array('class' => 'date'),
244 common_date_string($notice->created));