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 $this->out->elementStart('dl', 'entity_depiction');
103 $this->out->element('dt', null, _('Photo'));
104 $this->out->elementStart('dd');
105 $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
106 'class' => 'photo avatar',
107 'width' => AVATAR_PROFILE_SIZE,
108 'height' => AVATAR_PROFILE_SIZE,
109 'alt' => $this->profile->nickname));
110 $this->out->elementEnd('dd');
112 $user = User::staticGet('id', $this->profile->id);
114 $cur = common_current_user();
115 if ($cur && $cur->id == $user->id) {
116 $this->out->elementStart('dd');
117 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
118 $this->out->elementEnd('dd');
121 $this->out->elementEnd('dl');
123 Event::handle('EndProfilePageAvatar', array($this->out, $this->profile));
127 function showNickname()
129 if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
131 $this->out->elementStart('dl', 'entity_nickname');
132 $this->out->element('dt', null, _('Nickname'));
133 $this->out->elementStart('dd');
134 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
135 $this->out->element('a', array('href' => $this->profile->profileurl,
136 'rel' => 'me', 'class' => $hasFN),
137 $this->profile->nickname);
138 $this->out->elementEnd('dd');
139 $this->out->elementEnd('dl');
141 Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
145 function showFullName()
147 if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
148 if ($this->profile->fullname) {
149 $this->out->elementStart('dl', 'entity_fn');
150 $this->out->element('dt', null, _('Full name'));
151 $this->out->elementStart('dd');
152 $this->out->element('span', 'fn', $this->profile->fullname);
153 $this->out->elementEnd('dd');
154 $this->out->elementEnd('dl');
156 Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
160 function showLocation()
162 if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
163 if ($this->profile->location) {
164 $this->out->elementStart('dl', 'entity_location');
165 $this->out->element('dt', null, _('Location'));
166 $this->out->element('dd', 'label', $this->profile->location);
167 $this->out->elementEnd('dl');
169 Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
173 function showHomepage()
175 if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
176 if ($this->profile->homepage) {
177 $this->out->elementStart('dl', 'entity_url');
178 $this->out->element('dt', null, _('URL'));
179 $this->out->elementStart('dd');
180 $this->out->element('a', array('href' => $this->profile->homepage,
181 'rel' => 'me', 'class' => 'url'),
182 $this->profile->homepage);
183 $this->out->elementEnd('dd');
184 $this->out->elementEnd('dl');
186 Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
192 if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
193 if ($this->profile->bio) {
194 $this->out->elementStart('dl', 'entity_note');
195 $this->out->element('dt', null, _('Note'));
196 $this->out->element('dd', 'note', $this->profile->bio);
197 $this->out->elementEnd('dl');
199 Event::handle('EndProfilePageBio', array($this->out, $this->profile));
203 function showProfileTags()
205 if (Event::handle('StartProfilePageProfileTags', array($this->out, $this->profile))) {
206 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
208 if (count($tags) > 0) {
209 $this->out->elementStart('dl', 'entity_tags');
210 $this->out->element('dt', null, _('Tags'));
211 $this->out->elementStart('dd');
212 $this->out->elementStart('ul', 'tags xoxo');
213 foreach ($tags as $tag) {
214 $this->out->elementStart('li');
215 // Avoid space by using raw output.
216 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
217 common_local_url('peopletag', array('tag' => $tag)) .
218 '">' . $tag . '</a>';
219 $this->out->raw($pt);
220 $this->out->elementEnd('li');
222 $this->out->elementEnd('ul');
223 $this->out->elementEnd('dd');
224 $this->out->elementEnd('dl');
226 Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
230 function showEntityActions()
232 if ($this->profile->hasRole(Profile_role::DELETED)) {
233 $this->out->elementStart('div', 'entity_actions');
234 $this->out->element('h2', null, _('User actions'));
235 $this->out->elementStart('ul');
236 $this->out->elementStart('p', array('class' => 'profile_deleted'));
237 $this->out->text(_('User deletion in progress...'));
238 $this->out->elementEnd('p');
239 $this->out->elementEnd('ul');
240 $this->out->elementEnd('div');
243 if (Event::handle('StartProfilePageActionsSection', array(&$this->out, $this->profile))) {
245 $cur = common_current_user();
247 $this->out->elementStart('div', 'entity_actions');
248 $this->out->element('h2', null, _('User actions'));
249 $this->out->elementStart('ul');
251 if (Event::handle('StartProfilePageActionsElements', array(&$this->out, $this->profile))) {
252 if (empty($cur)) { // not logged in
253 if (Event::handle('StartProfileRemoteSubscribe', array(&$this->out, $this->profile))) {
254 $this->out->elementStart('li', 'entity_subscribe');
255 $this->showRemoteSubscribeLink();
256 $this->out->elementEnd('li');
257 Event::handle('EndProfileRemoteSubscribe', array(&$this->out, $this->profile));
260 if ($cur->id == $this->profile->id) { // your own page
261 $this->out->elementStart('li', 'entity_edit');
262 $this->out->element('a', array('href' => common_local_url('profilesettings'),
263 'title' => _('Edit profile settings')),
265 $this->out->elementEnd('li');
266 } else { // someone else's page
268 // subscribe/unsubscribe button
270 $this->out->elementStart('li', 'entity_subscribe');
272 if ($cur->isSubscribed($this->profile)) {
273 $usf = new UnsubscribeForm($this->out, $this->profile);
276 $sf = new SubscribeForm($this->out, $this->profile);
279 $this->out->elementEnd('li');
281 if ($cur->mutuallySubscribed($this->user)) {
285 $this->out->elementStart('li', 'entity_send-a-message');
286 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
287 'title' => _('Send a direct message to this user')),
289 $this->out->elementEnd('li');
293 if ($this->user->email && $this->user->emailnotifynudge) {
294 $this->out->elementStart('li', 'entity_nudge');
295 $nf = new NudgeForm($this->out, $this->user);
297 $this->out->elementEnd('li');
301 // return-to args, so we don't have to keep re-writing them
303 list($action, $r2args) = $this->out->returnToArgs();
305 // push the action into the list
307 $r2args['action'] = $action;
311 $blocked = $cur->hasBlocked($this->profile);
312 $this->out->elementStart('li', 'entity_block');
314 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
317 $bf = new BlockForm($this->out, $this->profile, $r2args);
320 $this->out->elementEnd('li');
322 if ($cur->hasRight(Right::SANDBOXUSER) ||
323 $cur->hasRight(Right::SILENCEUSER) ||
324 $cur->hasRight(Right::DELETEUSER)) {
325 $this->out->elementStart('li', 'entity_moderation');
326 $this->out->element('p', null, _('Moderate'));
327 $this->out->elementStart('ul');
328 if ($cur->hasRight(Right::SANDBOXUSER)) {
329 $this->out->elementStart('li', 'entity_sandbox');
330 if ($this->user->isSandboxed()) {
331 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
334 $sf = new SandboxForm($this->out, $this->profile, $r2args);
337 $this->out->elementEnd('li');
340 if ($cur->hasRight(Right::SILENCEUSER)) {
341 $this->out->elementStart('li', 'entity_silence');
342 if ($this->user->isSilenced()) {
343 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
346 $sf = new SilenceForm($this->out, $this->profile, $r2args);
349 $this->out->elementEnd('li');
352 if ($cur->hasRight(Right::DELETEUSER)) {
353 $this->out->elementStart('li', 'entity_delete');
354 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
356 $this->out->elementEnd('li');
358 $this->out->elementEnd('ul');
359 $this->out->elementEnd('li');
362 if ($cur->hasRight(Right::GRANTROLE)) {
363 $this->out->elementStart('li', 'entity_role');
364 $this->out->element('p', null, _('User role'));
365 $this->out->elementStart('ul');
366 $this->roleButton('administrator', _m('role', 'Administrator'));
367 $this->roleButton('moderator', _m('role', 'Moderator'));
368 $this->out->elementEnd('ul');
369 $this->out->elementEnd('li');
374 Event::handle('EndProfilePageActionsElements', array(&$this->out, $this->profile));
377 $this->out->elementEnd('ul');
378 $this->out->elementEnd('div');
380 Event::handle('EndProfilePageActionsSection', array(&$this->out, $this->profile));
384 function roleButton($role, $label)
386 list($action, $r2args) = $this->out->returnToArgs();
387 $r2args['action'] = $action;
389 $this->out->elementStart('li', "entity_role_$role");
390 if ($this->user->hasRole($role)) {
391 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
394 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
397 $this->out->elementEnd('li');
400 function showRemoteSubscribeLink()
402 $url = common_local_url('remotesubscribe',
403 array('nickname' => $this->profile->nickname));
404 $this->out->element('a', array('href' => $url,
405 'class' => 'entity_remote_subscribe'),