3 * Laconica, 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@controlyourself.ca>
25 * @author Sarven Capadisli <csarven@controlyourself.ca>
26 * @copyright 2008-2009 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!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@controlyourself.ca>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://laconi.ca/
50 class ProfileAction extends Action
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->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
90 common_set_returnto($this->selfUrl());
95 function showSections()
97 $this->showSubscriptions();
98 $this->showSubscribers();
100 $this->showStatistics();
103 function showSubscriptions()
105 $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
107 $this->elementStart('div', array('id' => 'entity_subscriptions',
108 'class' => 'section'));
110 $this->element('h2', null, _('Subscriptions'));
113 $pml = new ProfileMiniList($profile, $this->user, $this);
116 $this->element('p', null, _('(None)'));
120 if ($cnt > PROFILES_PER_MINILIST) {
121 $this->elementStart('p');
122 $this->element('a', array('href' => common_local_url('subscriptions',
123 array('nickname' => $this->profile->nickname)),
125 _('All subscriptions'));
126 $this->elementEnd('p');
129 $this->elementEnd('div');
132 function showSubscribers()
134 $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
136 $this->elementStart('div', array('id' => 'entity_subscribers',
137 'class' => 'section'));
139 $this->element('h2', null, _('Subscribers'));
142 $pml = new ProfileMiniList($profile, $this->user, $this);
145 $this->element('p', null, _('(None)'));
149 if ($cnt > PROFILES_PER_MINILIST) {
150 $this->elementStart('p');
151 $this->element('a', array('href' => common_local_url('subscribers',
152 array('nickname' => $this->profile->nickname)),
154 _('All subscribers'));
155 $this->elementEnd('p');
158 $this->elementEnd('div');
161 function showStatistics()
163 // XXX: WORM cache this
164 $subs = new Subscription();
165 $subs->subscriber = $this->profile->id;
166 $subs_count = (int) $subs->count() - 1;
168 $subbed = new Subscription();
169 $subbed->subscribed = $this->profile->id;
170 $subbed_count = (int) $subbed->count() - 1;
172 $notices = new Notice();
173 $notices->profile_id = $this->profile->id;
174 $notice_count = (int) $notices->count();
176 $this->elementStart('div', array('id' => 'entity_statistics',
177 'class' => 'section'));
179 $this->element('h2', null, _('Statistics'));
182 $this->elementStart('dl', 'entity_user-id');
183 $this->element('dt', null, _('User ID'));
184 $this->element('dd', null, $this->profile->id);
185 $this->elementEnd('dl');
187 $this->elementStart('dl', 'entity_member-since');
188 $this->element('dt', null, _('Member since'));
189 $this->element('dd', null, date('j M Y',
190 strtotime($this->profile->created)));
191 $this->elementEnd('dl');
193 $this->elementStart('dl', 'entity_subscriptions');
194 $this->elementStart('dt');
195 $this->element('a', array('href' => common_local_url('subscriptions',
196 array('nickname' => $this->profile->nickname))),
198 $this->elementEnd('dt');
199 $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
200 $this->elementEnd('dl');
202 $this->elementStart('dl', 'entity_subscribers');
203 $this->elementStart('dt');
204 $this->element('a', array('href' => common_local_url('subscribers',
205 array('nickname' => $this->profile->nickname))),
207 $this->elementEnd('dt');
208 $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
209 $this->elementEnd('dl');
211 $this->elementStart('dl', 'entity_notices');
212 $this->element('dt', null, _('Notices'));
213 $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
214 $this->elementEnd('dl');
216 $this->elementEnd('div');
219 function showGroups()
221 $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
223 $this->elementStart('div', array('id' => 'entity_groups',
224 'class' => 'section'));
226 $this->element('h2', null, _('Groups'));
229 $gml = new GroupMiniList($groups, $this->user, $this);
232 $this->element('p', null, _('(None)'));
236 if ($cnt > GROUPS_PER_MINILIST) {
237 $this->elementStart('p');
238 $this->element('a', array('href' => common_local_url('usergroups',
239 array('nickname' => $this->profile->nickname)),
242 $this->elementEnd('p');
245 $this->elementEnd('div');