]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
c98c8b6be1049fcf9cd6768ef94831dc90a33072
[quix0rs-gnu-social.git] / actions / showstream.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/stream.php');
23
24 define('SUBSCRIPTIONS_PER_ROW', 5);
25 define('SUBSCRIPTIONS', 80);
26
27 class ShowstreamAction extends StreamAction {
28
29         function handle($args) {
30
31                 parent::handle($args);
32
33                 $nickname = common_canonical_nickname($this->arg('nickname'));
34                 $user = User::staticGet('nickname', $nickname);
35
36                 if (!$user) {
37                         $this->no_such_user();
38                         return;
39                 }
40
41                 $profile = $user->getProfile();
42
43                 if (!$profile) {
44                         common_server_error(_t('User record exists without profile.'));
45                         return;
46                 }
47
48                 # Looks like we're good; show the header
49
50                 common_show_header($profile->nickname, array($this, 'show_header'), $user);
51
52                 $cur = common_current_user();
53
54                 if ($cur && $profile->id == $cur->id) {
55                         common_notice_form();
56                 }
57
58                 $this->show_sidebar($profile);
59                 
60                 $this->show_notices($profile);
61                 
62                 common_show_footer();
63         }
64
65         function show_header($user) {
66                 common_element('link', array('rel' => 'alternate',
67                                                                          'href' => common_local_url('rss10', array('nickname' =>
68                                                                                                                                                            $user->nickname)),
69                                                                          'type' => 'application/rdf+xml',
70                                                                          'title' => _t('Notice feed for ') . $user->nickname));
71         }
72         
73         function no_such_user() {
74                 common_user_error('No such user');
75         }
76
77         function show_sidebar($profile) {
78
79                 common_element_start('div', 'sidebar width33 floatRight greenBg');
80
81                 $this->show_profile($profile);
82
83                 $this->show_last_notice($profile);
84
85                 if ($cur && $cur->id != $profile->id) {
86                         if ($cur->isSubscribed($profile)) {
87                                 $this->show_unsubscribe_form($profile);
88                         } else {
89                                 $this->show_subscribe_form($profile);
90                         }
91                 }
92
93                 $this->show_statistics($profile);
94
95                 $this->show_subscriptions($profile);
96
97                 common_element_end('div');
98         }
99         
100         function show_profile($profile) {
101                 common_element_start('div', 'profile');
102
103                 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
104                 if ($avatar) {
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));
110                 }
111                 if ($profile->fullname) {
112                         common_element_start('div', 'fullname');
113                         if ($profile->homepage) {
114                                 common_element('a', array('href' => $profile->homepage),
115                                                            $profile->fullname);
116                         } else {
117                                 common_text($profile->fullname);
118                         }
119                         common_element_end('div');
120                 }
121                 if ($profile->location) {
122                         common_element('div', 'location', $profile->location);
123                 }
124                 if ($profile->bio) {
125                         common_element('div', 'bio', $profile->bio);
126                 }
127                 common_element_end('div');
128         }
129
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',
135                                                                           'type' => 'hidden',
136                                                                           'value' => $profile->nickname));
137                 common_element('input', array('type' => 'submit', 'value' => _t('Subscribe')));
138                 common_element_end('form');
139         }
140
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',
146                                                                           'type' => 'hidden',
147                                                                           'value' => $profile->nickname));
148                 common_element('input', array('type' => 'submit'), _t('Unsubscribe'));
149                 common_element_end('form');
150         }
151
152         function show_subscriptions($profile) {
153                 global $config;
154                 
155                 # XXX: add a limit
156                 $subs = $profile->getLink('id', 'subscription', 'subscriber');
157
158                 common_element_start('div', 'subscriptions');
159
160                 common_element('h2', 'subscriptions', _t('Subscriptions'));
161
162                 $cnt = 0;
163
164                 if ($subs) {
165                         while ($subs->fetch()) {
166                                 $cnt++;
167                                 if ($cnt % SUBSCRIPTIONS_PER_ROW == 1) {
168                                         common_element_start('div', 'row');
169                                 }
170
171                                 common_element_start('a', array('title' => ($subs->fullname) ?
172                                                                                                 $subs->fullname :
173                                                                                                 $subs->nickname,
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) ?
182                                                                                                 $subs->fullname :
183                                                                                                 $subs->nickname));
184                                 common_element_end('a');
185
186                                 if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
187                                         common_element_end('div');
188                                 }
189
190                                 if ($cnt == SUBSCRIPTIONS) {
191                                         break;
192                                 }
193                         }
194                 }
195
196                 common_element('a', array('href' => common_local_url('subscriptions',
197                                                                                                                          array('nickname' => $profile->nickname)),
198                                                                   'class' => 'moresubscriptions'),
199                                            _t('All subscriptions'));
200
201                 common_element_end('div');
202         }
203
204         function show_statistics($profile) {
205
206                 // XXX: WORM cache this
207                 $subs = DB_DataObject::factory('subscription');
208                 $subs->subscriber = $profile->id;
209                 $subs_count = $subs->count();
210
211                 if (!$subs_count) {
212                         $subs_count = 0;
213                 }
214
215                 $subbed = DB_DataObject::factory('subscription');
216                 $subbed->subscribed = $profile->id;
217                 $subbed_count = $subbed->count();
218
219                 if (!$subbed_count) {
220                         $subbed_count = 0;
221                 }
222
223                 $notices = DB_DataObject::factory('notice');
224                 $notices->profile_id = $profile->id;
225                 $notice_count = $notices->count();
226
227                 if (!$notice_count) {
228                         $notice_count = 0;
229                 }
230
231                 common_element_start('div', 'statistics');
232                 common_element('h2', 'statistics', _t('Statistics'));
233
234                 # Other stats...?
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');
243
244                 common_element_end('div');
245         }
246
247         function show_notices($profile) {
248
249                 $notice = DB_DataObject::factory('notice');
250                 $notice->profile_id = $profile->id;
251
252                 $notice->orderBy('created DESC');
253
254                 $page = $this->arg('page') || 1;
255
256                 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE);
257
258                 $notice->find();
259
260                 common_element_start('div', 'notices width66 floatLeft');
261
262                 common_element_start('ul', 'bigLinks');
263                 
264                 while ($notice->fetch()) {
265                         $this->show_notice($notice);
266                 }
267                 
268                 common_element_end('ul');
269                 
270                 # XXX: show a link for the next page
271                 common_element_end('div');
272         }
273
274         function show_last_notice($profile) {
275
276                 common_element_start('div', 'lastnotice');
277                 common_element('h2', 'lastnotice', _t('Currently'));
278
279                 $notice = DB_DataObject::factory('notice');
280                 $notice->profile_id = $profile->id;
281                 $notice->orderBy('created DESC');
282                 $notice->limit(0, 1);
283
284                 if ($notice->find(true)) {
285                         # FIXME: URL, image, video, audio
286                         common_element('span', array('class' => 'content'),
287                                                    $notice->content);
288                 }
289
290                 common_element_end('div');
291         }
292         
293         function show_notice($notice) {
294                 $profile = $notice->getProfile();
295                 # XXX: RDFa
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');
306         }
307 }