3 * StatusNet, the distributed open-source microblogging tool
5 * Profile for a particular user
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 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/widget.php';
36 require_once INSTALLDIR.'/lib/peopletags.php';
41 * Shows profile information about a particular user
45 * @author Evan Prodromou <evan@status.net>
46 * @author Sarven Capadisli <csarven@status.net>
47 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48 * @link http://status.net/
52 class UserProfile extends Widget
57 function __construct($action=null, $user=null, $profile=null)
59 parent::__construct($action);
61 $this->profile = $profile;
66 $this->showProfileData();
67 $this->showEntityActions();
70 function showProfileData()
72 if (Event::handle('StartProfilePageProfileSection', array(&$this->out, $this->profile))) {
74 $this->out->elementStart('div', array('id' => 'i',
75 'class' => 'entity_profile vcard author'));
76 // TRANS: H2 for user profile information.
77 $this->out->element('h2', null, _('User profile'));
79 if (Event::handle('StartProfilePageProfileElements', array(&$this->out, $this->profile))) {
82 $this->showNickname();
83 $this->showFullName();
84 $this->showLocation();
85 $this->showHomepage();
87 $this->showProfileTags();
89 Event::handle('EndProfilePageProfileElements', array(&$this->out, $this->profile));
92 $this->out->elementEnd('div');
93 Event::handle('EndProfilePageProfileSection', array(&$this->out, $this->profile));
99 if (Event::handle('StartProfilePageAvatar', array($this->out, $this->profile))) {
101 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
103 // hack for remote Twitter users: no 96px, but large Twitter size is 73px
104 $avatar = $this->profile->getAvatar(73);
107 $this->out->element('img',
108 array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
109 'class' => 'photo avatar entity_depiction',
110 'width' => AVATAR_PROFILE_SIZE,
111 'height' => AVATAR_PROFILE_SIZE,
112 'alt' => $this->profile->nickname));
114 $cur = common_current_user();
116 if ($cur && $cur->id == $this->profile->id) {
117 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
120 Event::handle('EndProfilePageAvatar',
121 array($this->out, $this->profile));
125 function showNickname()
127 if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
129 $hasFN = ($this->profile->fullname) ? 'entity_nickname nickname url uid' : 'entity_nickname fn nickname url uid';
130 $this->out->element('a',
131 array('href' => $this->profile->profileurl,
134 $this->profile->nickname);
136 Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
140 function showFullName()
142 if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
143 if ($this->profile->fullname) {
144 $this->out->element('span',
146 $this->profile->fullname);
148 Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
152 function showLocation()
154 if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
155 if ($this->profile->location) {
156 $this->out->element('span',
157 'entity_location label',
158 $this->profile->location);
160 Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
164 function showHomepage()
166 if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
167 if ($this->profile->homepage) {
168 $this->out->element('a',
169 array('href' => $this->profile->homepage,
171 'class' => 'url entity_url'),
172 $this->profile->homepage);
174 Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
180 if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
181 if ($this->profile->bio) {
182 $this->out->element('div',
184 $this->profile->bio);
186 Event::handle('EndProfilePageBio', array($this->out, $this->profile));
190 function showProfileTags()
192 $cur = common_current_user();
194 $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
198 // don't show self-tags again
199 if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
200 $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
206 function showEntityActions()
208 if ($this->profile->hasRole(Profile_role::DELETED)) {
209 $this->out->elementStart('div', 'entity_actions');
210 // TRANS: H2 for user actions in a profile.
211 $this->out->element('h2', null, _('User actions'));
212 $this->out->elementStart('ul');
213 $this->out->elementStart('p', array('class' => 'profile_deleted'));
214 // TRANS: Text shown in user profile of not yet compeltely deleted users.
215 $this->out->text(_('User deletion in progress...'));
216 $this->out->elementEnd('p');
217 $this->out->elementEnd('ul');
218 $this->out->elementEnd('div');
221 if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
223 $cur = common_current_user();
225 $this->out->elementStart('div', 'entity_actions');
226 // TRANS: H2 for entity actions in a profile.
227 $this->out->element('h2', null, _('User actions'));
228 $this->out->elementStart('ul');
230 if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
231 if (empty($cur)) { // not logged in
232 if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
233 $this->out->elementStart('li', 'entity_subscribe');
234 $this->showRemoteSubscribeLink();
235 $this->out->elementEnd('li');
236 Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
239 if ($cur->id == $this->profile->id) { // your own page
240 $this->out->elementStart('li', 'entity_edit');
241 $this->out->element('a', array('href' => common_local_url('profilesettings'),
242 // TRANS: Link title for link on user profile.
243 'title' => _('Edit profile settings')),
244 // TRANS: Link text for link on user profile.
246 $this->out->elementEnd('li');
247 } else { // someone else's page
249 // subscribe/unsubscribe button
251 $this->out->elementStart('li', 'entity_subscribe');
253 if ($cur->isSubscribed($this->profile)) {
254 $usf = new UnsubscribeForm($this->out, $this->profile);
257 $sf = new SubscribeForm($this->out, $this->profile);
260 $this->out->elementEnd('li');
262 if ($cur->mutuallySubscribed($this->profile)) {
266 $this->out->elementStart('li', 'entity_send-a-message');
267 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
268 // TRANS: Link title for link on user profile.
269 'title' => _('Send a direct message to this user')),
270 // TRANS: Link text for link on user profile.
272 $this->out->elementEnd('li');
276 if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
277 $this->out->elementStart('li', 'entity_nudge');
278 $nf = new NudgeForm($this->out, $this->user);
280 $this->out->elementEnd('li');
284 // return-to args, so we don't have to keep re-writing them
286 list($action, $r2args) = $this->out->returnToArgs();
288 // push the action into the list
290 $r2args['action'] = $action;
294 $blocked = $cur->hasBlocked($this->profile);
295 $this->out->elementStart('li', 'entity_block');
297 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
300 $bf = new BlockForm($this->out, $this->profile, $r2args);
303 $this->out->elementEnd('li');
305 // Some actions won't be applicable to non-local users.
306 $isLocal = !empty($this->user);
308 if ($cur->hasRight(Right::SANDBOXUSER) ||
309 $cur->hasRight(Right::SILENCEUSER) ||
310 $cur->hasRight(Right::DELETEUSER)) {
311 $this->out->elementStart('li', 'entity_moderation');
312 // TRANS: Label text on user profile to select a user role.
313 $this->out->element('p', null, _('Moderate'));
314 $this->out->elementStart('ul');
315 if ($cur->hasRight(Right::SANDBOXUSER)) {
316 $this->out->elementStart('li', 'entity_sandbox');
317 if ($this->profile->isSandboxed()) {
318 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
321 $sf = new SandboxForm($this->out, $this->profile, $r2args);
324 $this->out->elementEnd('li');
327 if ($cur->hasRight(Right::SILENCEUSER)) {
328 $this->out->elementStart('li', 'entity_silence');
329 if ($this->profile->isSilenced()) {
330 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
333 $sf = new SilenceForm($this->out, $this->profile, $r2args);
336 $this->out->elementEnd('li');
339 if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
340 $this->out->elementStart('li', 'entity_delete');
341 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
343 $this->out->elementEnd('li');
345 $this->out->elementEnd('ul');
346 $this->out->elementEnd('li');
349 if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
350 $this->out->elementStart('li', 'entity_role');
351 // TRANS: Label text on user profile to select a user role.
352 $this->out->element('p', null, _('User role'));
353 $this->out->elementStart('ul');
354 // TRANS: Role that can be set for a user profile.
355 $this->roleButton('administrator', _m('role', 'Administrator'));
356 // TRANS: Role that can be set for a user profile.
357 $this->roleButton('moderator', _m('role', 'Moderator'));
358 $this->out->elementEnd('ul');
359 $this->out->elementEnd('li');
364 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
367 $this->out->elementEnd('ul');
368 $this->out->elementEnd('div');
370 Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
374 function roleButton($role, $label)
376 list($action, $r2args) = $this->out->returnToArgs();
377 $r2args['action'] = $action;
379 $this->out->elementStart('li', "entity_role_$role");
380 if ($this->profile->hasRole($role)) {
381 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
384 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
387 $this->out->elementEnd('li');
390 function showRemoteSubscribeLink()
392 $url = common_local_url('remotesubscribe',
393 array('nickname' => $this->profile->nickname));
394 $this->out->element('a', array('href' => $url,
395 'class' => 'entity_remote_subscribe'),
396 // TRANS: Link text for link that will subscribe to a remote profile.