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 $this->out->elementStart('div', 'ur_face');
100 if (Event::handle('StartProfilePageAvatar', array($this->out, $this->profile))) {
102 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
104 // hack for remote Twitter users: no 96px, but large Twitter size is 73px
105 $avatar = $this->profile->getAvatar(73);
108 $this->out->element('img',
109 array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
110 'class' => 'photo avatar entity_depiction',
111 'width' => AVATAR_PROFILE_SIZE,
112 'height' => AVATAR_PROFILE_SIZE,
113 'alt' => $this->profile->nickname));
115 $cur = common_current_user();
117 if ($cur && $cur->id == $this->profile->id) {
118 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
121 Event::handle('EndProfilePageAvatar',
122 array($this->out, $this->profile));
125 $this->out->elementEnd('div');
128 function showNickname()
130 if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
132 $hasFN = ($this->profile->fullname) ? 'entity_nickname nickname url uid' : 'entity_nickname fn nickname url uid';
133 $this->out->element('a',
134 array('href' => $this->profile->profileurl,
137 $this->profile->nickname);
139 Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
143 function showFullName()
145 if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
146 if ($this->profile->fullname) {
147 $this->out->element('span',
149 $this->profile->fullname);
151 Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
155 function showLocation()
157 if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
158 if ($this->profile->location) {
159 $this->out->element('span',
160 'entity_location label',
161 $this->profile->location);
163 Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
167 function showHomepage()
169 if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
170 if ($this->profile->homepage) {
171 $this->out->element('a',
172 array('href' => $this->profile->homepage,
174 'class' => 'url entity_url'),
175 $this->profile->homepage);
177 Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
183 if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
184 if ($this->profile->bio) {
185 $this->out->element('div',
187 $this->profile->bio);
189 Event::handle('EndProfilePageBio', array($this->out, $this->profile));
193 function showProfileTags()
195 if (Event::handle('StartProfilePageProfileTags', array($this->out, $this->profile))) {
196 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
198 if (count($tags) > 0) {
199 $this->out->elementStart('ul', 'tags xoxo entity_tags');
200 foreach ($tags as $tag) {
201 $this->out->elementStart('li');
202 // Avoid space by using raw output.
203 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
204 common_local_url('peopletag', array('tag' => $tag)) .
205 '">' . $tag . '</a>';
206 $this->out->raw($pt);
207 $this->out->elementEnd('li');
209 $this->out->elementEnd('ul');
211 Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
215 function showEntityActions()
217 if ($this->profile->hasRole(Profile_role::DELETED)) {
218 $this->out->elementStart('div', 'entity_actions');
219 // TRANS: H2 for user actions in a profile.
220 $this->out->element('h2', null, _('User actions'));
221 $this->out->elementStart('ul');
222 $this->out->elementStart('p', array('class' => 'profile_deleted'));
223 // TRANS: Text shown in user profile of not yet compeltely deleted users.
224 $this->out->text(_('User deletion in progress...'));
225 $this->out->elementEnd('p');
226 $this->out->elementEnd('ul');
227 $this->out->elementEnd('div');
230 if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
232 $cur = common_current_user();
234 $this->out->elementStart('div', 'entity_actions');
235 // TRANS: H2 for entity actions in a profile.
236 $this->out->element('h2', null, _('User actions'));
237 $this->out->elementStart('ul');
239 if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
240 if (empty($cur)) { // not logged in
241 if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
242 $this->out->elementStart('li', 'entity_subscribe');
243 $this->showRemoteSubscribeLink();
244 $this->out->elementEnd('li');
245 Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
248 if ($cur->id == $this->profile->id) { // your own page
249 $this->out->elementStart('li', 'entity_edit');
250 $this->out->element('a', array('href' => common_local_url('profilesettings'),
251 // TRANS: Link title for link on user profile.
252 'title' => _('Edit profile settings')),
253 // TRANS: Link text for link on user profile.
255 $this->out->elementEnd('li');
256 } else { // someone else's page
258 // subscribe/unsubscribe button
260 $this->out->elementStart('li', 'entity_subscribe');
262 if ($cur->isSubscribed($this->profile)) {
263 $usf = new UnsubscribeForm($this->out, $this->profile);
266 $sf = new SubscribeForm($this->out, $this->profile);
269 $this->out->elementEnd('li');
271 if ($cur->mutuallySubscribed($this->profile)) {
275 $this->out->elementStart('li', 'entity_send-a-message');
276 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
277 // TRANS: Link title for link on user profile.
278 'title' => _('Send a direct message to this user')),
279 // TRANS: Link text for link on user profile.
281 $this->out->elementEnd('li');
285 if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
286 $this->out->elementStart('li', 'entity_nudge');
287 $nf = new NudgeForm($this->out, $this->user);
289 $this->out->elementEnd('li');
293 // return-to args, so we don't have to keep re-writing them
295 list($action, $r2args) = $this->out->returnToArgs();
297 // push the action into the list
299 $r2args['action'] = $action;
303 $blocked = $cur->hasBlocked($this->profile);
304 $this->out->elementStart('li', 'entity_block');
306 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
309 $bf = new BlockForm($this->out, $this->profile, $r2args);
312 $this->out->elementEnd('li');
314 // Some actions won't be applicable to non-local users.
315 $isLocal = !empty($this->user);
317 if ($cur->hasRight(Right::SANDBOXUSER) ||
318 $cur->hasRight(Right::SILENCEUSER) ||
319 $cur->hasRight(Right::DELETEUSER)) {
320 $this->out->elementStart('li', 'entity_moderation');
321 // TRANS: Label text on user profile to select a user role.
322 $this->out->element('p', null, _('Moderate'));
323 $this->out->elementStart('ul');
324 if ($cur->hasRight(Right::SANDBOXUSER)) {
325 $this->out->elementStart('li', 'entity_sandbox');
326 if ($this->profile->isSandboxed()) {
327 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
330 $sf = new SandboxForm($this->out, $this->profile, $r2args);
333 $this->out->elementEnd('li');
336 if ($cur->hasRight(Right::SILENCEUSER)) {
337 $this->out->elementStart('li', 'entity_silence');
338 if ($this->profile->isSilenced()) {
339 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
342 $sf = new SilenceForm($this->out, $this->profile, $r2args);
345 $this->out->elementEnd('li');
348 if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
349 $this->out->elementStart('li', 'entity_delete');
350 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
352 $this->out->elementEnd('li');
354 $this->out->elementEnd('ul');
355 $this->out->elementEnd('li');
358 if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
359 $this->out->elementStart('li', 'entity_role');
360 // TRANS: Label text on user profile to select a user role.
361 $this->out->element('p', null, _('User role'));
362 $this->out->elementStart('ul');
363 // TRANS: Role that can be set for a user profile.
364 $this->roleButton('administrator', _m('role', 'Administrator'));
365 // TRANS: Role that can be set for a user profile.
366 $this->roleButton('moderator', _m('role', 'Moderator'));
367 $this->out->elementEnd('ul');
368 $this->out->elementEnd('li');
373 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
376 $this->out->elementEnd('ul');
377 $this->out->elementEnd('div');
379 Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
383 function roleButton($role, $label)
385 list($action, $r2args) = $this->out->returnToArgs();
386 $r2args['action'] = $action;
388 $this->out->elementStart('li', "entity_role_$role");
389 if ($this->profile->hasRole($role)) {
390 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
393 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
396 $this->out->elementEnd('li');
399 function showRemoteSubscribeLink()
401 $url = common_local_url('remotesubscribe',
402 array('nickname' => $this->profile->nickname));
403 $this->out->element('a', array('href' => $url,
404 'class' => 'entity_remote_subscribe'),
405 // TRANS: Link text for link that will subscribe to a remote profile.