]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profileaction.php
remove extraneous <dl> and <dt> tags
[quix0rs-gnu-social.git] / lib / profileaction.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Common parent of Personal and Profile actions
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Personal
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008-2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/profileminilist.php';
36 require_once INSTALLDIR.'/lib/groupminilist.php';
37
38 /**
39  * Profile action common superclass
40  *
41  * Abstracts out common code from profile and personal tabs
42  *
43  * @category Personal
44  * @package  StatusNet
45  * @author   Evan Prodromou <evan@status.net>
46  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47  * @link     http://status.net/
48  */
49
50 class ProfileAction extends OwnerDesignAction
51 {
52     var $page    = null;
53     var $profile = null;
54     var $tag     = null;
55
56     function prepare($args)
57     {
58         parent::prepare($args);
59
60         $nickname_arg = $this->arg('nickname');
61         $nickname     = common_canonical_nickname($nickname_arg);
62
63         // Permanent redirect on non-canonical nickname
64
65         if ($nickname_arg != $nickname) {
66             $args = array('nickname' => $nickname);
67             if ($this->arg('page') && $this->arg('page') != 1) {
68                 $args['page'] = $this->arg['page'];
69             }
70             common_redirect(common_local_url($this->trimmed('action'), $args), 301);
71             return false;
72         }
73
74         $this->user = User::staticGet('nickname', $nickname);
75
76         if (!$this->user) {
77             $this->clientError(_('No such user.'), 404);
78             return false;
79         }
80
81         $this->profile = $this->user->getProfile();
82
83         if (!$this->profile) {
84             $this->serverError(_('User has no profile.'));
85             return false;
86         }
87
88         $this->tag = $this->trimmed('tag');
89         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
90         common_set_returnto($this->selfUrl());
91         return true;
92     }
93
94     function showSections()
95     {
96         $this->showSubscriptions();
97         $this->showSubscribers();
98         $this->showGroups();
99         $this->showStatistics();
100     }
101
102     function showSubscriptions()
103     {
104         $profile = $this->profile->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
105
106         $this->elementStart('div', array('id' => 'entity_subscriptions',
107                                          'class' => 'section'));
108         if (Event::handle('StartShowSubscriptionsMiniList', array($this))) {
109             $this->element('h2', null, _('Subscriptions'));
110
111             $cnt = 0;
112
113             if (!empty($profile)) {
114                 $pml = new ProfileMiniList($profile, $this);
115                 $cnt = $pml->show();
116                 if ($cnt == 0) {
117                     $this->element('p', null, _('(None)'));
118                 }
119             }
120
121             if ($cnt > PROFILES_PER_MINILIST) {
122                 $this->elementStart('p');
123                 $this->element('a', array('href' => common_local_url('subscriptions',
124                                                                      array('nickname' => $this->profile->nickname)),
125                                           'class' => 'more'),
126                                _('All subscriptions'));
127                 $this->elementEnd('p');
128             }
129
130             Event::handle('EndShowSubscriptionsMiniList', array($this));
131         }
132         $this->elementEnd('div');
133     }
134
135     function showSubscribers()
136     {
137         $profile = $this->profile->getSubscribers(0, PROFILES_PER_MINILIST + 1);
138
139         $this->elementStart('div', array('id' => 'entity_subscribers',
140                                          'class' => 'section'));
141
142         if (Event::handle('StartShowSubscribersMiniList', array($this))) {
143
144             $this->element('h2', null, _('Subscribers'));
145
146             $cnt = 0;
147
148             if (!empty($profile)) {
149                 $sml = new SubscribersMiniList($profile, $this);
150                 $cnt = $sml->show();
151                 if ($cnt == 0) {
152                     $this->element('p', null, _('(None)'));
153                 }
154             }
155
156             if ($cnt > PROFILES_PER_MINILIST) {
157                 $this->elementStart('p');
158                 $this->element('a', array('href' => common_local_url('subscribers',
159                                                                      array('nickname' => $this->profile->nickname)),
160                                           'class' => 'more'),
161                                _('All subscribers'));
162                 $this->elementEnd('p');
163             }
164
165             Event::handle('EndShowSubscribersMiniList', array($this));
166         }
167
168         $this->elementEnd('div');
169     }
170
171     function showStatistics()
172     {
173         $subs_count   = $this->profile->subscriptionCount();
174         $subbed_count = $this->profile->subscriberCount();
175         $notice_count = $this->profile->noticeCount();
176         $group_count  = $this->profile->getGroups()->N;
177         $age_days     = (time() - strtotime($this->profile->created)) / 86400;
178         if ($age_days < 1) {
179             // Rather than extrapolating out to a bajillion...
180             $age_days = 1;
181         }
182         $daily_count = round($notice_count / $age_days);
183
184         $this->elementStart('div', array('id' => 'entity_statistics',
185                                          'class' => 'section'));
186
187         $this->element('h2', null, _('Statistics'));
188
189         // Other stats...?
190         $this->elementStart('dl');
191         $this->element('dt', null, _('User ID'));
192         $this->element('dd', 'entity_user-id', $this->profile->id);
193
194         $this->element('dt', null, _('Member since'));
195         $this->element('dd', 'entity_member-since', date('j M Y',
196                                         strtotime($this->profile->created)));
197
198         $this->elementStart('dt');
199         $this->element('a', array('href' => common_local_url('subscriptions',
200                                                              array('nickname' => $this->profile->nickname))),
201                        _('Subscriptions'));
202         $this->elementEnd('dt');
203         $this->element('dd', 'entity_subscriptions', $subs_count);
204
205         $this->elementStart('dt');
206         $this->element('a', array('href' => common_local_url('subscribers',
207                                                              array('nickname' => $this->profile->nickname))),
208                        _('Subscribers'));
209         $this->elementEnd('dt');
210         $this->element('dd', 'subscribers entity_subscribers', $subbed_count);
211
212         $this->elementStart('dt');
213         $this->element('a', array('href' => common_local_url('usergroups',
214                                                              array('nickname' => $this->profile->nickname))),
215                        _('Groups'));
216         $this->elementEnd('dt');
217         $this->element('dd', 'groups entity_groups', $group_count);
218
219         $this->element('dt', null, _('Notices'));
220         $this->element('dd', 'entity_notices', $notice_count);
221
222         // TRANS: Average count of posts made per day since account registration
223         $this->element('dt', null, _('Daily average'));
224         $this->element('dd', 'entity_daily_notices', $daily_count);
225
226         $this->elementEnd('dl');
227
228         $this->elementEnd('div');
229     }
230
231     function showGroups()
232     {
233         $groups = $this->profile->getGroups(0, GROUPS_PER_MINILIST + 1);
234
235         $this->elementStart('div', array('id' => 'entity_groups',
236                                          'class' => 'section'));
237         if (Event::handle('StartShowGroupsMiniList', array($this))) {
238             $this->element('h2', null, _('Groups'));
239
240             if ($groups) {
241                 $gml = new GroupMiniList($groups, $this->profile, $this);
242                 $cnt = $gml->show();
243                 if ($cnt == 0) {
244                     $this->element('p', null, _('(None)'));
245                 }
246             }
247
248             if ($cnt > GROUPS_PER_MINILIST) {
249                 $this->elementStart('p');
250                 $this->element('a', array('href' => common_local_url('usergroups',
251                                                                      array('nickname' => $this->profile->nickname)),
252                                           'class' => 'more'),
253                                _('All groups'));
254                 $this->elementEnd('p');
255             }
256
257             Event::handle('EndShowGroupsMiniList', array($this));
258         }
259             $this->elementEnd('div');
260     }
261 }
262
263 class SubscribersMiniList extends ProfileMiniList
264 {
265     function newListItem($profile)
266     {
267         return new SubscribersMiniListItem($profile, $this->action);
268     }
269 }
270
271 class SubscribersMiniListItem extends ProfileMiniListItem
272 {
273     function linkAttributes()
274     {
275         $aAttrs = parent::linkAttributes();
276         if (common_config('nofollow', 'subscribers')) {
277             $aAttrs['rel'] .= ' nofollow';
278         }
279         return $aAttrs;
280     }
281 }
282