3 * StatusNet, the distributed open-source microblogging tool
5 * Common parent of Personal and Profile actions
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.
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.
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/>.
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/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/profileminilist.php';
36 require_once INSTALLDIR.'/lib/groupminilist.php';
39 * Profile action common superclass
41 * Abstracts out common code from profile and personal tabs
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/
50 class ProfileAction extends OwnerDesignAction
56 function prepare($args)
58 parent::prepare($args);
60 $nickname_arg = $this->arg('nickname');
61 $nickname = common_canonical_nickname($nickname_arg);
63 // Permanent redirect on non-canonical nickname
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'];
70 common_redirect(common_local_url($this->trimmed('action'), $args), 301);
74 $this->user = User::staticGet('nickname', $nickname);
77 $this->clientError(_('No such user.'), 404);
81 $this->profile = $this->user->getProfile();
83 if (!$this->profile) {
84 $this->serverError(_('User has no profile.'));
88 $this->tag = $this->trimmed('tag');
89 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
90 common_set_returnto($this->selfUrl());
94 function showSections()
96 $this->showSubscriptions();
97 $this->showSubscribers();
99 $this->showStatistics();
102 function showSubscriptions()
104 $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
106 $this->elementStart('div', array('id' => 'entity_subscriptions',
107 'class' => 'section'));
108 if (Event::handle('StartShowSubscriptionsMiniList', array($this))) {
109 $this->element('h2', null, _('Subscriptions'));
113 if (!empty($profile)) {
114 $pml = new ProfileMiniList($profile, $this);
117 $this->element('p', null, _('(None)'));
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)),
126 _('All subscriptions'));
127 $this->elementEnd('p');
130 Event::handle('EndShowSubscriptionsMiniList', array($this));
132 $this->elementEnd('div');
135 function showSubscribers()
137 $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
139 $this->elementStart('div', array('id' => 'entity_subscribers',
140 'class' => 'section'));
142 if (Event::handle('StartShowSubscribersMiniList', array($this))) {
144 $this->element('h2', null, _('Subscribers'));
148 if (!empty($profile)) {
149 $sml = new SubscribersMiniList($profile, $this);
152 $this->element('p', null, _('(None)'));
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)),
161 _('All subscribers'));
162 $this->elementEnd('p');
165 Event::handle('EndShowSubscribersMiniList', array($this));
168 $this->elementEnd('div');
171 function showStatistics()
173 $subs_count = $this->profile->subscriptionCount();
174 $subbed_count = $this->profile->subscriberCount();
175 $notice_count = $this->profile->noticeCount();
176 $group_count = $this->user->getGroups()->N;
177 $age_days = (time() - strtotime($this->profile->created)) / 86400;
179 // Rather than extrapolating out to a bajillion...
182 $daily_count = round($notice_count / $age_days);
184 $this->elementStart('div', array('id' => 'entity_statistics',
185 'class' => 'section'));
187 $this->element('h2', null, _('Statistics'));
190 $this->elementStart('dl', 'entity_user-id');
191 $this->element('dt', null, _('User ID'));
192 $this->element('dd', null, $this->profile->id);
193 $this->elementEnd('dl');
195 $this->elementStart('dl', 'entity_member-since');
196 $this->element('dt', null, _('Member since'));
197 $this->element('dd', null, date('j M Y',
198 strtotime($this->profile->created)));
199 $this->elementEnd('dl');
201 $this->elementStart('dl', 'entity_subscriptions');
202 $this->elementStart('dt');
203 $this->element('a', array('href' => common_local_url('subscriptions',
204 array('nickname' => $this->profile->nickname))),
206 $this->elementEnd('dt');
207 $this->element('dd', null, $subs_count);
208 $this->elementEnd('dl');
210 $this->elementStart('dl', 'entity_subscribers');
211 $this->elementStart('dt');
212 $this->element('a', array('href' => common_local_url('subscribers',
213 array('nickname' => $this->profile->nickname))),
215 $this->elementEnd('dt');
216 $this->element('dd', 'subscribers', $subbed_count);
217 $this->elementEnd('dl');
219 $this->elementStart('dl', 'entity_groups');
220 $this->elementStart('dt');
221 $this->element('a', array('href' => common_local_url('usergroups',
222 array('nickname' => $this->profile->nickname))),
224 $this->elementEnd('dt');
225 $this->element('dd', 'groups', $group_count);
226 $this->elementEnd('dl');
228 $this->elementStart('dl', 'entity_notices');
229 $this->element('dt', null, _('Notices'));
230 $this->element('dd', null, $notice_count);
231 $this->elementEnd('dl');
233 $this->elementStart('dl', 'entity_daily_notices');
234 // TRANS: Average count of posts made per day since account registration
235 $this->element('dt', null, _('Daily average'));
236 $this->element('dd', null, $daily_count);
237 $this->elementEnd('dl');
239 $this->elementEnd('div');
242 function showGroups()
244 $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
246 $this->elementStart('div', array('id' => 'entity_groups',
247 'class' => 'section'));
248 if (Event::handle('StartShowGroupsMiniList', array($this))) {
249 $this->element('h2', null, _('Groups'));
252 $gml = new GroupMiniList($groups, $this->user, $this);
255 $this->element('p', null, _('(None)'));
259 if ($cnt > GROUPS_PER_MINILIST) {
260 $this->elementStart('p');
261 $this->element('a', array('href' => common_local_url('usergroups',
262 array('nickname' => $this->profile->nickname)),
265 $this->elementEnd('p');
268 Event::handle('EndShowGroupsMiniList', array($this));
270 $this->elementEnd('div');
274 class SubscribersMiniList extends ProfileMiniList
276 function newListItem($profile)
278 return new SubscribersMiniListItem($profile, $this->action);
282 class SubscribersMiniListItem extends ProfileMiniListItem
284 function linkAttributes()
286 $aAttrs = parent::linkAttributes();
287 if (common_config('nofollow', 'subscribers')) {
288 $aAttrs['rel'] .= ' nofollow';