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/
49 class ProfileAction extends OwnerDesignAction
55 function prepare($args)
57 parent::prepare($args);
59 $nickname_arg = $this->arg('nickname');
60 $nickname = common_canonical_nickname($nickname_arg);
62 // Permanent redirect on non-canonical nickname
64 if ($nickname_arg != $nickname) {
65 $args = array('nickname' => $nickname);
66 if ($this->arg('page') && $this->arg('page') != 1) {
67 $args['page'] = $this->arg['page'];
69 common_redirect(common_local_url($this->trimmed('action'), $args), 301);
73 $this->user = User::staticGet('nickname', $nickname);
76 // TRANS: Client error displayed when calling a profile action without specifying a user.
77 $this->clientError(_('No such user.'), 404);
81 $this->profile = $this->user->getProfile();
83 if (!$this->profile) {
84 // TRANS: Server error displayed when calling a profile action while the specified user does not have a profile.
85 $this->serverError(_('User has no profile.'));
89 $this->tag = $this->trimmed('tag');
90 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
91 common_set_returnto($this->selfUrl());
95 function showSections()
97 $this->showSubscriptions();
98 $this->showSubscribers();
100 $this->showPeopletagSubs();
101 $this->showPeopletags();
102 $this->showStatistics();
106 * Convenience function for common pattern of links to subscription/groups sections.
108 * @param string $actionClass
109 * @param string $title
110 * @param string $cssClass
112 private function statsSectionLink($actionClass, $title, $cssClass='')
114 $this->element('a', array('href' => common_local_url($actionClass,
115 array('nickname' => $this->profile->nickname)),
116 'class' => $cssClass),
120 function showSubscriptions()
122 $profile = $this->profile->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
124 $this->elementStart('div', array('id' => 'entity_subscriptions',
125 'class' => 'section'));
126 if (Event::handle('StartShowSubscriptionsMiniList', array($this))) {
127 $this->elementStart('h2');
128 // TRANS: H2 text for user subscription statistics.
129 $this->statsSectionLink('subscriptions', _('Subscriptions'));
130 $this->elementEnd('h2');
134 if (!empty($profile)) {
135 $pml = new ProfileMiniList($profile, $this);
138 // TRANS: Text for user subscription statistics if the user has no subscriptions.
139 $this->element('p', null, _('(None)'));
143 if ($cnt > PROFILES_PER_MINILIST) {
144 $this->elementStart('p');
145 // TRANS: Text for user subscription statistics if user has more subscriptions than displayed.
146 $this->statsSectionLink('subscriptions', _('All subscriptions'), 'more');
147 $this->elementEnd('p');
150 Event::handle('EndShowSubscriptionsMiniList', array($this));
152 $this->elementEnd('div');
155 function showSubscribers()
157 $profile = $this->profile->getSubscribers(0, PROFILES_PER_MINILIST + 1);
159 $this->elementStart('div', array('id' => 'entity_subscribers',
160 'class' => 'section'));
162 if (Event::handle('StartShowSubscribersMiniList', array($this))) {
164 $this->elementStart('h2');
165 // TRANS: H2 text for user subscriber statistics.
166 $this->statsSectionLink('subscribers', _('Subscribers'));
167 $this->elementEnd('h2');
171 if (!empty($profile)) {
172 $sml = new SubscribersMiniList($profile, $this);
175 // TRANS: Text for user subscriber statistics if user has no subscribers.
176 $this->element('p', null, _('(None)'));
180 if ($cnt > PROFILES_PER_MINILIST) {
181 $this->elementStart('p');
182 // TRANS: Text for user subscription statistics if user has more subscribers than displayed.
183 $this->statsSectionLink('subscribers', _('All subscribers'), 'more');
184 $this->elementEnd('p');
187 Event::handle('EndShowSubscribersMiniList', array($this));
190 $this->elementEnd('div');
193 function showPeopletagSubs()
195 $user = common_current_user();
196 if (!empty($user) && $this->profile->id == $user->id) {
197 if (Event::handle('StartShowPeopletagSubscriptionsSection', array($this))) {
199 $profile = $user->getProfile();
200 $section = new PeopletagSubscriptionsSection($this, $profile);
203 Event::handle('EndShowPeopletagSubscriptionsSection', array($this));
208 function showPeopletags()
210 if (Event::handle('StartShowPeopletagsSection', array($this))) {
212 $section = new PeopletagsForUserSection($this, $this->profile);
215 Event::handle('EndShowPeopletagsSection', array($this));
219 function showStatistics()
221 $notice_count = $this->profile->noticeCount();
222 $age_days = (time() - strtotime($this->profile->created)) / 86400;
224 // Rather than extrapolating out to a bajillion...
227 $daily_count = round($notice_count / $age_days);
229 $this->elementStart('div', array('id' => 'entity_statistics',
230 'class' => 'section'));
232 // TRANS: H2 text for user statistics.
233 $this->element('h2', null, _('Statistics'));
235 $profile = $this->profile;
236 $actionParams = array('nickname' => $profile->nickname);
240 // TRANS: Label for user statistics.
241 'label' => _('User ID'),
242 'value' => $profile->id,
245 'id' => 'member-since',
246 // TRANS: Label for user statistics.
247 'label' => _('Member since'),
248 'value' => date('j M Y', strtotime($profile->created))
251 'id' => 'subscriptions',
252 // TRANS: Label for user statistics.
253 'label' => _('Subscriptions'),
254 'link' => common_local_url('subscriptions', $actionParams),
255 'value' => $profile->subscriptionCount(),
258 'id' => 'subscribers',
259 // TRANS: Label for user statistics.
260 'label' => _('Subscribers'),
261 'link' => common_local_url('subscribers', $actionParams),
262 'value' => $profile->subscriberCount(),
266 // TRANS: Label for user statistics.
267 'label' => _('Groups'),
268 'link' => common_local_url('usergroups', $actionParams),
269 'value' => $profile->getGroups()->N,
273 // TRANS: Label for user statistics.
274 'label' => _('Notices'),
275 'value' => $notice_count,
278 'id' => 'daily_notices',
279 // TRANS: Label for user statistics.
280 // TRANS: Average count of posts made per day since account registration.
281 'label' => _('Daily average'),
282 'value' => $daily_count
286 // Give plugins a chance to add stats entries
287 Event::handle('ProfileStats', array($profile, &$stats));
289 foreach ($stats as $row) {
290 $this->showStatsRow($row);
292 $this->elementEnd('div');
295 private function showStatsRow($row)
297 $this->elementStart('dl', 'entity_' . $row['id']);
298 $this->elementStart('dt');
299 if (!empty($row['link'])) {
300 $this->element('a', array('href' => $row['link']), $row['label']);
302 $this->text($row['label']);
304 $this->elementEnd('dt');
305 $this->element('dd', null, $row['value']);
306 $this->elementEnd('dl');
309 function showGroups()
311 $groups = $this->profile->getGroups(0, GROUPS_PER_MINILIST + 1);
313 $this->elementStart('div', array('id' => 'entity_groups',
314 'class' => 'section'));
315 if (Event::handle('StartShowGroupsMiniList', array($this))) {
316 $this->elementStart('h2');
317 // TRANS: H2 text for user group membership statistics.
318 $this->statsSectionLink('usergroups', _('Groups'));
319 $this->elementEnd('h2');
322 $gml = new GroupMiniList($groups, $this->profile, $this);
325 // TRANS: Text for user user group membership statistics if user is not a member of any group.
326 $this->element('p', null, _('(None)'));
330 if ($cnt > GROUPS_PER_MINILIST) {
331 $this->elementStart('p');
332 // TRANS: Text for user group membership statistics if user has more subscriptions than displayed.
333 $this->statsSectionLink('usergroups', _('All groups'), 'more');
334 $this->elementEnd('p');
337 Event::handle('EndShowGroupsMiniList', array($this));
339 $this->elementEnd('div');
343 class SubscribersMiniList extends ProfileMiniList
345 function newListItem($profile)
347 return new SubscribersMiniListItem($profile, $this->action);
351 class SubscribersMiniListItem extends ProfileMiniListItem
353 function linkAttributes()
355 $aAttrs = parent::linkAttributes();
356 if (common_config('nofollow', 'subscribers')) {
357 $aAttrs['rel'] .= ' nofollow';