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'));
109 if (Event::handle('StartShowSubscriptionsMiniList', array($this))) {
110 $this->element('h2', null, _('Subscriptions'));
114 if (!empty($profile)) {
115 $pml = new ProfileMiniList($profile, $this);
118 $this->element('p', null, _('(None)'));
122 if ($cnt > PROFILES_PER_MINILIST) {
123 $this->elementStart('p');
124 $this->element('a', array('href' => common_local_url('subscriptions',
125 array('nickname' => $this->profile->nickname)),
127 _('All subscriptions'));
128 $this->elementEnd('p');
131 Event::handle('EndShowSubscriptionsMiniList', array($this));
133 $this->elementEnd('div');
136 function showSubscribers()
138 $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
140 $this->elementStart('div', array('id' => 'entity_subscribers',
141 'class' => 'section'));
143 $this->element('h2', null, _('Subscribers'));
147 if (!empty($profile)) {
148 $pml = new ProfileMiniList($profile, $this);
151 $this->element('p', null, _('(None)'));
155 if ($cnt > PROFILES_PER_MINILIST) {
156 $this->elementStart('p');
157 $this->element('a', array('href' => common_local_url('subscribers',
158 array('nickname' => $this->profile->nickname)),
160 _('All subscribers'));
161 $this->elementEnd('p');
164 $this->elementEnd('div');
167 function showStatistics()
169 $subs_count = $this->profile->subscriptionCount();
170 $subbed_count = $this->profile->subscriberCount();
171 $notice_count = $this->profile->noticeCount();
172 $group_count = $this->user->getGroups()->N;
174 $this->elementStart('div', array('id' => 'entity_statistics',
175 'class' => 'section'));
177 $this->element('h2', null, _('Statistics'));
180 $this->elementStart('dl', 'entity_user-id');
181 $this->element('dt', null, _('User ID'));
182 $this->element('dd', null, $this->profile->id);
183 $this->elementEnd('dl');
185 $this->elementStart('dl', 'entity_member-since');
186 $this->element('dt', null, _('Member since'));
187 $this->element('dd', null, date('j M Y',
188 strtotime($this->profile->created)));
189 $this->elementEnd('dl');
191 $this->elementStart('dl', 'entity_subscriptions');
192 $this->elementStart('dt');
193 $this->element('a', array('href' => common_local_url('subscriptions',
194 array('nickname' => $this->profile->nickname))),
196 $this->elementEnd('dt');
197 $this->element('dd', null, $subs_count);
198 $this->elementEnd('dl');
200 $this->elementStart('dl', 'entity_subscribers');
201 $this->elementStart('dt');
202 $this->element('a', array('href' => common_local_url('subscribers',
203 array('nickname' => $this->profile->nickname))),
205 $this->elementEnd('dt');
206 $this->element('dd', 'subscribers', $subbed_count);
207 $this->elementEnd('dl');
209 $this->elementStart('dl', 'entity_groups');
210 $this->elementStart('dt');
211 $this->element('a', array('href' => common_local_url('usergroups',
212 array('nickname' => $this->profile->nickname))),
214 $this->elementEnd('dt');
215 $this->element('dd', 'groups', $group_count);
216 $this->elementEnd('dl');
218 $this->elementStart('dl', 'entity_notices');
219 $this->element('dt', null, _('Notices'));
220 $this->element('dd', null, $notice_count);
221 $this->elementEnd('dl');
223 $this->elementEnd('div');
226 function showGroups()
228 $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
230 $this->elementStart('div', array('id' => 'entity_groups',
231 'class' => 'section'));
233 $this->element('h2', null, _('Groups'));
236 $gml = new GroupMiniList($groups, $this->user, $this);
239 $this->element('p', null, _('(None)'));
243 if ($cnt > GROUPS_PER_MINILIST) {
244 $this->elementStart('p');
245 $this->element('a', array('href' => common_local_url('usergroups',
246 array('nickname' => $this->profile->nickname)),
249 $this->elementEnd('p');
252 $this->elementEnd('div');