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';
40 * Shows profile information about a particular user
44 * @author Evan Prodromou <evan@status.net>
45 * @author Sarven Capadisli <csarven@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/
51 class UserProfile extends Widget
56 function __construct($action=null, $user=null, $profile=null)
58 parent::__construct($action);
60 $this->profile = $profile;
65 $this->showProfileData();
66 $this->showEntityActions();
69 function showProfileData()
71 if (Event::handle('StartProfilePageProfileSection', array(&$this->out, $this->profile))) {
73 $this->out->elementStart('div', array('id' => 'i',
74 'class' => 'entity_profile vcard author'));
75 // TRANS: H2 for user profile information.
76 $this->out->element('h2', null, _('User profile'));
78 if (Event::handle('StartProfilePageProfileElements', array(&$this->out, $this->profile))) {
81 $this->showNickname();
82 $this->showFullName();
83 $this->showLocation();
84 $this->showHomepage();
86 $this->showProfileTags();
88 Event::handle('EndProfilePageProfileElements', array(&$this->out, $this->profile));
91 $this->out->elementEnd('div');
92 Event::handle('EndProfilePageProfileSection', array(&$this->out, $this->profile));
98 if (Event::handle('StartProfilePageAvatar', array($this->out, $this->profile))) {
100 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
102 // hack for remote Twitter users: no 96px, but large Twitter size is 73px
103 $avatar = $this->profile->getAvatar(73);
106 $this->out->elementStart('dl', 'entity_depiction');
107 // TRANS: DT element in area for user avatar.
108 $this->out->element('dt', null, _('Photo'));
109 $this->out->elementStart('dd');
110 $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
111 'class' => 'photo avatar',
112 'width' => AVATAR_PROFILE_SIZE,
113 'height' => AVATAR_PROFILE_SIZE,
114 'alt' => $this->profile->nickname));
115 $this->out->elementEnd('dd');
117 $cur = common_current_user();
118 if ($cur && $cur->id == $this->profile->id) {
119 $this->out->elementStart('dd');
120 // TRANS: Link text for changeing the avatar of the logged in user.
121 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
122 $this->out->elementEnd('dd');
125 $this->out->elementEnd('dl');
127 Event::handle('EndProfilePageAvatar', array($this->out, $this->profile));
131 function showNickname()
133 if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
135 $this->out->elementStart('dl', 'entity_nickname');
136 // TRANS: DT for nick name in a profile.
137 $this->out->element('dt', null, _('Nickname'));
138 $this->out->elementStart('dd');
139 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
140 $this->out->element('a', array('href' => $this->profile->profileurl,
141 'rel' => 'me', 'class' => $hasFN),
142 $this->profile->nickname);
143 $this->out->elementEnd('dd');
144 $this->out->elementEnd('dl');
146 Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
150 function showFullName()
152 if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
153 if ($this->profile->fullname) {
154 $this->out->elementStart('dl', 'entity_fn');
155 // TRANS: DT for full name in a profile.
156 $this->out->element('dt', null, _('Full name'));
157 $this->out->elementStart('dd');
158 $this->out->element('span', 'fn', $this->profile->fullname);
159 $this->out->elementEnd('dd');
160 $this->out->elementEnd('dl');
162 Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
166 function showLocation()
168 if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
169 if ($this->profile->location) {
170 $this->out->elementStart('dl', 'entity_location');
171 // TRANS: DT for location in a profile.
172 $this->out->element('dt', null, _('Location'));
173 $this->out->element('dd', 'label', $this->profile->location);
174 $this->out->elementEnd('dl');
176 Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
180 function showHomepage()
182 if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
183 if ($this->profile->homepage) {
184 $this->out->elementStart('dl', 'entity_url');
185 // TRANS: DT for URL in a profile.
186 $this->out->element('dt', null, _('URL'));
187 $this->out->elementStart('dd');
188 $this->out->element('a', array('href' => $this->profile->homepage,
189 'rel' => 'me', 'class' => 'url'),
190 $this->profile->homepage);
191 $this->out->elementEnd('dd');
192 $this->out->elementEnd('dl');
194 Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
200 if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
201 if ($this->profile->bio) {
202 $this->out->elementStart('dl', 'entity_note');
203 // TRANS: DT for note in a profile.
204 $this->out->element('dt', null, _('Note'));
205 $this->out->element('dd', 'note', $this->profile->bio);
206 $this->out->elementEnd('dl');
208 Event::handle('EndProfilePageBio', array($this->out, $this->profile));
212 function showProfileTags()
214 if (Event::handle('StartProfilePageProfileTags', array($this->out, $this->profile))) {
215 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
217 if (count($tags) > 0) {
218 $this->out->elementStart('dl', 'entity_tags');
219 // TRANS: DT for tags in a profile.
220 $this->out->element('dt', null, _('Tags'));
221 $this->out->elementStart('dd');
222 $this->out->elementStart('ul', 'tags xoxo');
223 foreach ($tags as $tag) {
224 $this->out->elementStart('li');
225 // Avoid space by using raw output.
226 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
227 common_local_url('peopletag', array('tag' => $tag)) .
228 '">' . $tag . '</a>';
229 $this->out->raw($pt);
230 $this->out->elementEnd('li');
232 $this->out->elementEnd('ul');
233 $this->out->elementEnd('dd');
234 $this->out->elementEnd('dl');
236 Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
240 function showEntityActions()
242 if ($this->profile->hasRole(Profile_role::DELETED)) {
243 $this->out->elementStart('div', 'entity_actions');
244 // TRANS: H2 for user actions in a profile.
245 $this->out->element('h2', null, _('User actions'));
246 $this->out->elementStart('ul');
247 $this->out->elementStart('p', array('class' => 'profile_deleted'));
248 // TRANS: Text shown in user profile of not yet compeltely deleted users.
249 $this->out->text(_('User deletion in progress...'));
250 $this->out->elementEnd('p');
251 $this->out->elementEnd('ul');
252 $this->out->elementEnd('div');
255 if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
257 $cur = common_current_user();
259 $this->out->elementStart('div', 'entity_actions');
260 // TRANS: H2 for entity actions in a profile.
261 $this->out->element('h2', null, _('User actions'));
262 $this->out->elementStart('ul');
264 if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
265 if (empty($cur)) { // not logged in
266 if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
267 $this->out->elementStart('li', 'entity_subscribe');
268 $this->showRemoteSubscribeLink();
269 $this->out->elementEnd('li');
270 Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
273 if ($cur->id == $this->profile->id) { // your own page
274 $this->out->elementStart('li', 'entity_edit');
275 $this->out->element('a', array('href' => common_local_url('profilesettings'),
276 // TRANS: Link title for link on user profile.
277 'title' => _('Edit profile settings')),
278 // TRANS: Link text for link on user profile.
280 $this->out->elementEnd('li');
281 } else { // someone else's page
283 // subscribe/unsubscribe button
285 $this->out->elementStart('li', 'entity_subscribe');
287 if ($cur->isSubscribed($this->profile)) {
288 $usf = new UnsubscribeForm($this->out, $this->profile);
291 $sf = new SubscribeForm($this->out, $this->profile);
294 $this->out->elementEnd('li');
296 if ($cur->mutuallySubscribed($this->profile)) {
300 $this->out->elementStart('li', 'entity_send-a-message');
301 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
302 // TRANS: Link title for link on user profile.
303 'title' => _('Send a direct message to this user')),
304 // TRANS: Link text for link on user profile.
306 $this->out->elementEnd('li');
310 if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
311 $this->out->elementStart('li', 'entity_nudge');
312 $nf = new NudgeForm($this->out, $this->user);
314 $this->out->elementEnd('li');
318 // return-to args, so we don't have to keep re-writing them
320 list($action, $r2args) = $this->out->returnToArgs();
322 // push the action into the list
324 $r2args['action'] = $action;
328 $blocked = $cur->hasBlocked($this->profile);
329 $this->out->elementStart('li', 'entity_block');
331 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
334 $bf = new BlockForm($this->out, $this->profile, $r2args);
337 $this->out->elementEnd('li');
339 // Some actions won't be applicable to non-local users.
340 $isLocal = !empty($this->user);
342 if ($cur->hasRight(Right::SANDBOXUSER) ||
343 $cur->hasRight(Right::SILENCEUSER) ||
344 $cur->hasRight(Right::DELETEUSER)) {
345 $this->out->elementStart('li', 'entity_moderation');
346 // TRANS: Label text on user profile to select a user role.
347 $this->out->element('p', null, _('Moderate'));
348 $this->out->elementStart('ul');
349 if ($cur->hasRight(Right::SANDBOXUSER)) {
350 $this->out->elementStart('li', 'entity_sandbox');
351 if ($this->profile->isSandboxed()) {
352 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
355 $sf = new SandboxForm($this->out, $this->profile, $r2args);
358 $this->out->elementEnd('li');
361 if ($cur->hasRight(Right::SILENCEUSER)) {
362 $this->out->elementStart('li', 'entity_silence');
363 if ($this->profile->isSilenced()) {
364 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
367 $sf = new SilenceForm($this->out, $this->profile, $r2args);
370 $this->out->elementEnd('li');
373 if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
374 $this->out->elementStart('li', 'entity_delete');
375 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
377 $this->out->elementEnd('li');
379 $this->out->elementEnd('ul');
380 $this->out->elementEnd('li');
383 if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
384 $this->out->elementStart('li', 'entity_role');
385 // TRANS: Label text on user profile to select a user role.
386 $this->out->element('p', null, _('User role'));
387 $this->out->elementStart('ul');
388 // TRANS: Role that can be set for a user profile.
389 $this->roleButton('administrator', _m('role', 'Administrator'));
390 // TRANS: Role that can be set for a user profile.
391 $this->roleButton('moderator', _m('role', 'Moderator'));
392 $this->out->elementEnd('ul');
393 $this->out->elementEnd('li');
398 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
401 $this->out->elementEnd('ul');
402 $this->out->elementEnd('div');
404 Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
408 function roleButton($role, $label)
410 list($action, $r2args) = $this->out->returnToArgs();
411 $r2args['action'] = $action;
413 $this->out->elementStart('li', "entity_role_$role");
414 if ($this->profile->hasRole($role)) {
415 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
418 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
421 $this->out->elementEnd('li');
424 function showRemoteSubscribeLink()
426 $url = common_local_url('remotesubscribe',
427 array('nickname' => $this->profile->nickname));
428 $this->out->element('a', array('href' => $url,
429 'class' => 'entity_remote_subscribe'),
430 // TRANS: Link text for link that will subscribe to a remote profile.