]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
add w3dtf date to rss 1.0 items
[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);
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 no_such_user() {
66                 common_user_error('No such user');
67         }
68
69         function show_sidebar($profile) {
70
71                 common_element_start('div', 'sidebar width33 floatRight greenBg');
72
73                 $this->show_profile($profile);
74
75                 $this->show_last_notice($profile);
76
77                 if ($cur && $cur->id != $profile->id) {
78                         if ($cur->isSubscribed($profile)) {
79                                 $this->show_unsubscribe_form($profile);
80                         } else {
81                                 $this->show_subscribe_form($profile);
82                         }
83                 }
84
85                 $this->show_statistics($profile);
86
87                 $this->show_subscriptions($profile);
88
89                 common_element_end('div');
90         }
91         
92         function show_profile($profile) {
93                 common_element_start('div', 'profile');
94
95                 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
96                 if ($avatar) {
97                         common_element('img', array('src' => $avatar->url,
98                                                                                 'class' => 'avatar profile',
99                                                                                 'width' => AVATAR_PROFILE_SIZE,
100                                                                                 'height' => AVATAR_PROFILE_SIZE,
101                                                                                 'alt' => $profile->nickname));
102                 }
103                 if ($profile->fullname) {
104                         common_element_start('div', 'fullname');
105                         if ($profile->homepage) {
106                                 common_element('a', array('href' => $profile->homepage),
107                                                            $profile->fullname);
108                         } else {
109                                 common_text($profile->fullname);
110                         }
111                         common_element_end('div');
112                 }
113                 if ($profile->location) {
114                         common_element('div', 'location', $profile->location);
115                 }
116                 if ($profile->bio) {
117                         common_element('div', 'bio', $profile->bio);
118                 }
119                 common_element_end('div');
120         }
121
122         function show_subscribe_form($profile) {
123                 common_element_start('form', array('id' => 'subscribe', 'method' => 'POST',
124                                                                                    'action' => common_local_url('subscribe')));
125                 common_element('input', array('id' => 'subscribeto',
126                                                                           'name' => 'subscribeto',
127                                                                           'type' => 'hidden',
128                                                                           'value' => $profile->nickname));
129                 common_element('input', array('type' => 'submit', 'value' => _t('Subscribe')));
130                 common_element_end('form');
131         }
132
133         function show_unsubscribe_form($profile) {
134                 common_element_start('form', array('id' => 'unsubscribe', 'method' => 'POST',
135                                                                                    'action' => common_local_url('unsubscribe')));
136                 common_element('input', array('id' => 'unsubscribeto',
137                                                                           'name' => 'unsubscribeto',
138                                                                           'type' => 'hidden',
139                                                                           'value' => $profile->nickname));
140                 common_element('input', array('type' => 'submit'), _t('Unsubscribe'));
141                 common_element_end('form');
142         }
143
144         function show_subscriptions($profile) {
145                 global $config;
146                 
147                 # XXX: add a limit
148                 $subs = $profile->getLink('id', 'subscription', 'subscriber');
149
150                 common_element_start('div', 'subscriptions');
151
152                 common_element('h2', 'subscriptions', _t('Subscriptions'));
153
154                 $cnt = 0;
155
156                 if ($subs) {
157                         while ($subs->fetch()) {
158                                 $cnt++;
159                                 if ($cnt % SUBSCRIPTIONS_PER_ROW == 1) {
160                                         common_element_start('div', 'row');
161                                 }
162
163                                 common_element_start('a', array('title' => ($subs->fullname) ?
164                                                                                                 $subs->fullname :
165                                                                                                 $subs->nickname,
166                                                                                                 'href' => $subs->profileurl,
167                                                                                                 'class' => 'subscription'));
168                                 $avatar = $subs->getAvatar(AVATAR_MINI_SIZE);
169                                 common_element('img', array('src' => (($avatar) ? $avatar->url : $config['avatar']['default']['mini']),
170                                                                                         'width' => AVATAR_MINI_SIZE,
171                                                                                         'height' => AVATAR_MINI_SIZE,
172                                                                                         'class' => 'avatar mini',
173                                                                                         'alt' =>  ($subs->fullname) ?
174                                                                                                 $subs->fullname :
175                                                                                                 $subs->nickname));
176                                 common_element_end('a');
177
178                                 if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
179                                         common_element_end('div');
180                                 }
181
182                                 if ($cnt == SUBSCRIPTIONS) {
183                                         break;
184                                 }
185                         }
186                 }
187
188                 common_element('a', array('href' => common_local_url('subscriptions',
189                                                                                                                          array('nickname' => $profile->nickname)),
190                                                                   'class' => 'moresubscriptions'),
191                                            _t('All subscriptions'));
192
193                 common_element_end('div');
194         }
195
196         function show_statistics($profile) {
197
198                 // XXX: WORM cache this
199                 $subs = DB_DataObject::factory('subscription');
200                 $subs->subscriber = $profile->id;
201                 $subs_count = $subs->count();
202
203                 if (!$subs_count) {
204                         $subs_count = 0;
205                 }
206
207                 $subbed = DB_DataObject::factory('subscription');
208                 $subbed->subscribed = $profile->id;
209                 $subbed_count = $subbed->count();
210
211                 if (!$subbed_count) {
212                         $subbed_count = 0;
213                 }
214
215                 $notices = DB_DataObject::factory('notice');
216                 $notices->profile_id = $profile->id;
217                 $notice_count = $notices->count();
218
219                 if (!$notice_count) {
220                         $notice_count = 0;
221                 }
222
223                 common_element_start('div', 'statistics');
224                 common_element('h2', 'statistics', _t('Statistics'));
225
226                 # Other stats...?
227                 common_element_start('dl', 'statistics');
228                 common_element('dt', 'subscriptions', _t('Subscriptions'));
229                 common_element('dd', 'subscriptions', $subs_count);
230                 common_element('dt', 'subscribers', _t('Subscribers'));
231                 common_element('dd', 'subscribers', $subbed_count);
232                 common_element('dt', 'notices', _t('Notices'));
233                 common_element('dd', 'notices', $notice_count);
234                 common_element_end('dl');
235
236                 common_element_end('div');
237         }
238
239         function show_notices($profile) {
240
241                 $notice = DB_DataObject::factory('notice');
242                 $notice->profile_id = $profile->id;
243
244                 $notice->orderBy('created DESC');
245
246                 $page = $this->arg('page') || 1;
247
248                 $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE);
249
250                 $notice->find();
251
252                 common_element_start('div', 'notices width66 floatLeft');
253
254                 common_element_start('ul', 'bigLinks');
255                 
256                 while ($notice->fetch()) {
257                         $this->show_notice($notice);
258                 }
259                 
260                 common_element_end('ul');
261                 
262                 # XXX: show a link for the next page
263                 common_element_end('div');
264         }
265
266         function show_last_notice($profile) {
267
268                 common_element_start('div', 'lastnotice');
269                 common_element('h2', 'lastnotice', _t('Currently'));
270
271                 $notice = DB_DataObject::factory('notice');
272                 $notice->profile_id = $profile->id;
273                 $notice->orderBy('created DESC');
274                 $notice->limit(0, 1);
275
276                 if ($notice->find(true)) {
277                         # FIXME: URL, image, video, audio
278                         common_element('span', array('class' => 'content'),
279                                                    $notice->content);
280                 }
281
282                 common_element_end('div');
283         }
284         
285         function show_notice($notice) {
286                 $profile = $notice->getProfile();
287                 # XXX: RDFa
288                 common_element_start('li', array('class' => 'notice',
289                                                                                  'id' => 'notice-' . $notice->id));
290                 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
291                 # FIXME: URL, image, video, audio
292                 common_element_start('a', array('class' => 'notice',
293                                                                   'href' => $noticeurl));
294                 common_element('span', 'title', common_date_string($notice->created));
295                 common_element('span', 'desc', $notice->content);
296                 common_element_end('a');
297                 common_element_end('li');
298         }
299 }