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();
103 * Convenience function for common pattern of links to subscription/groups sections.
105 * @param string $actionClass
106 * @param string $title
107 * @param string $cssClass
109 private function statsSectionLink($actionClass, $title, $cssClass='')
111 $this->element('a', array('href' => common_local_url($actionClass,
112 array('nickname' => $this->profile->nickname)),
113 'class' => $cssClass),
117 function showSubscriptions()
119 $profile = $this->profile->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
121 $this->elementStart('div', array('id' => 'entity_subscriptions',
122 'class' => 'section'));
123 if (Event::handle('StartShowSubscriptionsMiniList', array($this))) {
124 $this->elementStart('h2');
125 $this->statsSectionLink('subscriptions', _('Subscriptions'));
126 $this->elementEnd('h2');
130 if (!empty($profile)) {
131 $pml = new ProfileMiniList($profile, $this);
134 $this->element('p', null, _('(None)'));
138 if ($cnt > PROFILES_PER_MINILIST) {
139 $this->elementStart('p');
140 $this->statsSectionLink('subscriptions', _('All subscriptions'), 'more');
141 $this->elementEnd('p');
144 Event::handle('EndShowSubscriptionsMiniList', array($this));
146 $this->elementEnd('div');
149 function showSubscribers()
151 $profile = $this->profile->getSubscribers(0, PROFILES_PER_MINILIST + 1);
153 $this->elementStart('div', array('id' => 'entity_subscribers',
154 'class' => 'section'));
156 if (Event::handle('StartShowSubscribersMiniList', array($this))) {
158 $this->elementStart('h2');
159 $this->statsSectionLink('subscribers', _('Subscribers'));
160 $this->elementEnd('h2');
164 if (!empty($profile)) {
165 $sml = new SubscribersMiniList($profile, $this);
168 $this->element('p', null, _('(None)'));
172 if ($cnt > PROFILES_PER_MINILIST) {
173 $this->elementStart('p');
174 $this->statsSectionLink('subscribers', _('All subscribers'), 'more');
175 $this->elementEnd('p');
178 Event::handle('EndShowSubscribersMiniList', array($this));
181 $this->elementEnd('div');
184 function showStatistics()
186 $notice_count = $this->profile->noticeCount();
187 $age_days = (time() - strtotime($this->profile->created)) / 86400;
189 // Rather than extrapolating out to a bajillion...
192 $daily_count = round($notice_count / $age_days);
194 $this->elementStart('div', array('id' => 'entity_statistics',
195 'class' => 'section'));
197 $this->element('h2', null, _('Statistics'));
199 $profile = $this->profile;
200 $actionParams = array('nickname' => $profile->nickname);
204 'label' => _('User ID'),
205 'value' => $profile->id,
208 'id' => 'member-since',
209 'label' => _('Member since'),
210 'value' => date('j M Y', strtotime($profile->created))
213 'id' => 'subscriptions',
214 'label' => _('Subscriptions'),
215 'link' => common_local_url('subscriptions', $actionParams),
216 'value' => $profile->subscriptionCount(),
219 'id' => 'subscribers',
220 'label' => _('Subscribers'),
221 'link' => common_local_url('subscribers', $actionParams),
222 'value' => $profile->subscriberCount(),
226 'label' => _('Groups'),
227 'link' => common_local_url('usergroups', $actionParams),
228 'value' => $profile->getGroups()->N,
232 'label' => _('Notices'),
233 'value' => $notice_count,
236 'id' => 'daily_notices',
237 // TRANS: Average count of posts made per day since account registration
238 'label' => _('Daily average'),
239 'value' => $daily_count
243 // Give plugins a chance to add stats entries
244 Event::handle('ProfileStats', array($profile, &$stats));
246 foreach ($stats as $row) {
247 $this->showStatsRow($row);
249 $this->elementEnd('div');
252 private function showStatsRow($row)
254 $this->elementStart('dl', 'entity_' . $row['id']);
255 $this->elementStart('dt');
256 if (!empty($row['link'])) {
257 $this->element('a', array('href' => $row['link']), $row['label']);
259 $this->text($row['label']);
261 $this->elementEnd('dt');
262 $this->element('dd', null, $row['value']);
263 $this->elementEnd('dl');
266 function showGroups()
268 $groups = $this->profile->getGroups(0, GROUPS_PER_MINILIST + 1);
270 $this->elementStart('div', array('id' => 'entity_groups',
271 'class' => 'section'));
272 if (Event::handle('StartShowGroupsMiniList', array($this))) {
273 $this->elementStart('h2');
274 $this->statsSectionLink('usergroups', _('Groups'));
275 $this->elementEnd('h2');
278 $gml = new GroupMiniList($groups, $this->profile, $this);
281 $this->element('p', null, _('(None)'));
285 if ($cnt > GROUPS_PER_MINILIST) {
286 $this->elementStart('p');
287 $this->statsSectionLink('usergroups', _('All groups'), 'more');
288 $this->elementEnd('p');
291 Event::handle('EndShowGroupsMiniList', array($this));
293 $this->elementEnd('div');
297 class SubscribersMiniList extends ProfileMiniList
299 function newListItem($profile)
301 return new SubscribersMiniListItem($profile, $this->action);
305 class SubscribersMiniListItem extends ProfileMiniListItem
307 function linkAttributes()
309 $aAttrs = parent::linkAttributes();
310 if (common_config('nofollow', 'subscribers')) {
311 $aAttrs['rel'] .= ' nofollow';