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/
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 $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 $this->out->element('dt', null, _('Photo'));
108 $this->out->elementStart('dd');
109 $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
110 'class' => 'photo avatar',
111 'width' => AVATAR_PROFILE_SIZE,
112 'height' => AVATAR_PROFILE_SIZE,
113 'alt' => $this->profile->nickname));
114 $this->out->elementEnd('dd');
116 $cur = common_current_user();
117 if ($cur && $cur->id == $this->profile->id) {
118 $this->out->elementStart('dd');
119 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
120 $this->out->elementEnd('dd');
123 $this->out->elementEnd('dl');
125 Event::handle('EndProfilePageAvatar', array($this->out, $this->profile));
129 function showNickname()
131 if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
133 $this->out->elementStart('dl', 'entity_nickname');
134 $this->out->element('dt', null, _('Nickname'));
135 $this->out->elementStart('dd');
136 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
137 $this->out->element('a', array('href' => $this->profile->profileurl,
138 'rel' => 'me', 'class' => $hasFN),
139 $this->profile->nickname);
140 $this->out->elementEnd('dd');
141 $this->out->elementEnd('dl');
143 Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
147 function showFullName()
149 if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
150 if ($this->profile->fullname) {
151 $this->out->elementStart('dl', 'entity_fn');
152 $this->out->element('dt', null, _('Full name'));
153 $this->out->elementStart('dd');
154 $this->out->element('span', 'fn', $this->profile->fullname);
155 $this->out->elementEnd('dd');
156 $this->out->elementEnd('dl');
158 Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
162 function showLocation()
164 if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
165 if ($this->profile->location) {
166 $this->out->elementStart('dl', 'entity_location');
167 $this->out->element('dt', null, _('Location'));
168 $this->out->element('dd', 'label', $this->profile->location);
169 $this->out->elementEnd('dl');
171 Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
175 function showHomepage()
177 if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
178 if ($this->profile->homepage) {
179 $this->out->elementStart('dl', 'entity_url');
180 $this->out->element('dt', null, _('URL'));
181 $this->out->elementStart('dd');
182 $this->out->element('a', array('href' => $this->profile->homepage,
183 'rel' => 'me', 'class' => 'url'),
184 $this->profile->homepage);
185 $this->out->elementEnd('dd');
186 $this->out->elementEnd('dl');
188 Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
194 if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
195 if ($this->profile->bio) {
196 $this->out->elementStart('dl', 'entity_note');
197 $this->out->element('dt', null, _('Note'));
198 $this->out->element('dd', 'note', $this->profile->bio);
199 $this->out->elementEnd('dl');
201 Event::handle('EndProfilePageBio', array($this->out, $this->profile));
205 function showProfileTags()
207 if (Event::handle('StartProfilePageProfileTags', array($this->out, $this->profile))) {
208 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
210 if (count($tags) > 0) {
211 $this->out->elementStart('dl', 'entity_tags');
212 $this->out->element('dt', null, _('Tags'));
213 $this->out->elementStart('dd');
214 $this->out->elementStart('ul', 'tags xoxo');
215 foreach ($tags as $tag) {
216 $this->out->elementStart('li');
217 // Avoid space by using raw output.
218 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
219 common_local_url('peopletag', array('tag' => $tag)) .
220 '">' . $tag . '</a>';
221 $this->out->raw($pt);
222 $this->out->elementEnd('li');
224 $this->out->elementEnd('ul');
225 $this->out->elementEnd('dd');
226 $this->out->elementEnd('dl');
228 Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
232 function showEntityActions()
234 if ($this->profile->hasRole(Profile_role::DELETED)) {
235 $this->out->elementStart('div', 'entity_actions');
236 $this->out->element('h2', null, _('User actions'));
237 $this->out->elementStart('ul');
238 $this->out->elementStart('p', array('class' => 'profile_deleted'));
239 $this->out->text(_('User deletion in progress...'));
240 $this->out->elementEnd('p');
241 $this->out->elementEnd('ul');
242 $this->out->elementEnd('div');
245 if (Event::handle('StartProfilePageActionsSection', array(&$this->out, $this->profile))) {
247 $cur = common_current_user();
249 $this->out->elementStart('div', 'entity_actions');
250 $this->out->element('h2', null, _('User actions'));
251 $this->out->elementStart('ul');
253 if (Event::handle('StartProfilePageActionsElements', array(&$this->out, $this->profile))) {
254 if (empty($cur)) { // not logged in
255 if (Event::handle('StartProfileRemoteSubscribe', array(&$this->out, $this->profile))) {
256 $this->out->elementStart('li', 'entity_subscribe');
257 $this->showRemoteSubscribeLink();
258 $this->out->elementEnd('li');
259 Event::handle('EndProfileRemoteSubscribe', array(&$this->out, $this->profile));
262 if ($cur->id == $this->profile->id) { // your own page
263 $this->out->elementStart('li', 'entity_edit');
264 $this->out->element('a', array('href' => common_local_url('profilesettings'),
265 'title' => _('Edit profile settings')),
267 $this->out->elementEnd('li');
268 } else { // someone else's page
270 // subscribe/unsubscribe button
272 $this->out->elementStart('li', 'entity_subscribe');
274 if ($cur->isSubscribed($this->profile)) {
275 $usf = new UnsubscribeForm($this->out, $this->profile);
278 $sf = new SubscribeForm($this->out, $this->profile);
281 $this->out->elementEnd('li');
283 if ($cur->mutuallySubscribed($this->profile)) {
287 $this->out->elementStart('li', 'entity_send-a-message');
288 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
289 'title' => _('Send a direct message to this user')),
291 $this->out->elementEnd('li');
295 if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
296 $this->out->elementStart('li', 'entity_nudge');
297 $nf = new NudgeForm($this->out, $this->user);
299 $this->out->elementEnd('li');
303 // return-to args, so we don't have to keep re-writing them
305 list($action, $r2args) = $this->out->returnToArgs();
307 // push the action into the list
309 $r2args['action'] = $action;
313 $blocked = $cur->hasBlocked($this->profile);
314 $this->out->elementStart('li', 'entity_block');
316 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
319 $bf = new BlockForm($this->out, $this->profile, $r2args);
322 $this->out->elementEnd('li');
324 // Some actions won't be applicable to non-local users.
325 $isLocal = !empty($this->user);
327 if ($cur->hasRight(Right::SANDBOXUSER) ||
328 $cur->hasRight(Right::SILENCEUSER) ||
329 $cur->hasRight(Right::DELETEUSER)) {
330 $this->out->elementStart('li', 'entity_moderation');
331 $this->out->element('p', null, _('Moderate'));
332 $this->out->elementStart('ul');
333 if ($cur->hasRight(Right::SANDBOXUSER)) {
334 $this->out->elementStart('li', 'entity_sandbox');
335 if ($this->profile->isSandboxed()) {
336 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
339 $sf = new SandboxForm($this->out, $this->profile, $r2args);
342 $this->out->elementEnd('li');
345 if ($cur->hasRight(Right::SILENCEUSER)) {
346 $this->out->elementStart('li', 'entity_silence');
347 if ($this->profile->isSilenced()) {
348 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
351 $sf = new SilenceForm($this->out, $this->profile, $r2args);
354 $this->out->elementEnd('li');
357 if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
358 $this->out->elementStart('li', 'entity_delete');
359 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
361 $this->out->elementEnd('li');
363 $this->out->elementEnd('ul');
364 $this->out->elementEnd('li');
367 if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
368 $this->out->elementStart('li', 'entity_role');
369 $this->out->element('p', null, _('User role'));
370 $this->out->elementStart('ul');
371 $this->roleButton('administrator', _m('role', 'Administrator'));
372 $this->roleButton('moderator', _m('role', 'Moderator'));
373 $this->out->elementEnd('ul');
374 $this->out->elementEnd('li');
379 Event::handle('EndProfilePageActionsElements', array(&$this->out, $this->profile));
382 $this->out->elementEnd('ul');
383 $this->out->elementEnd('div');
385 Event::handle('EndProfilePageActionsSection', array(&$this->out, $this->profile));
389 function roleButton($role, $label)
391 list($action, $r2args) = $this->out->returnToArgs();
392 $r2args['action'] = $action;
394 $this->out->elementStart('li', "entity_role_$role");
395 if ($this->profile->hasRole($role)) {
396 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
399 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
402 $this->out->elementEnd('li');
405 function showRemoteSubscribeLink()
407 $url = common_local_url('remotesubscribe',
408 array('nickname' => $this->profile->nickname));
409 $this->out->element('a', array('href' => $url,
410 'class' => 'entity_remote_subscribe'),