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', 'entity_profile vcard author');
75 $this->out->element('h2', null, _('User profile'));
77 if (Event::handle('StartProfilePageProfileElements', array(&$this->out, $this->profile))) {
80 $this->showNickname();
81 $this->showFullName();
82 $this->showLocation();
83 $this->showHomepage();
85 $this->showProfileTags();
87 Event::handle('EndProfilePageProfileElements', array(&$this->out, $this->profile));
90 $this->out->elementEnd('div');
91 Event::handle('EndProfilePageProfileSection', array(&$this->out, $this->profile));
97 if (Event::handle('StartProfilePageAvatar', array($this->out, $this->profile))) {
99 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
101 $this->out->elementStart('dl', 'entity_depiction');
102 $this->out->element('dt', null, _('Photo'));
103 $this->out->elementStart('dd');
104 $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
105 'class' => 'photo avatar',
106 'width' => AVATAR_PROFILE_SIZE,
107 'height' => AVATAR_PROFILE_SIZE,
108 'alt' => $this->profile->nickname));
109 $this->out->elementEnd('dd');
111 $user = User::staticGet('id', $this->profile->id);
113 $cur = common_current_user();
114 if ($cur && $cur->id == $user->id) {
115 $this->out->elementStart('dd');
116 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
117 $this->out->elementEnd('dd');
120 $this->out->elementEnd('dl');
122 Event::handle('EndProfilePageAvatar', array($this->out, $this->profile));
126 function showNickname()
128 if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
130 $this->out->elementStart('dl', 'entity_nickname');
131 $this->out->element('dt', null, _('Nickname'));
132 $this->out->elementStart('dd');
133 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
134 $this->out->element('a', array('href' => $this->profile->profileurl,
135 'rel' => 'me', 'class' => $hasFN),
136 $this->profile->nickname);
137 $this->out->elementEnd('dd');
138 $this->out->elementEnd('dl');
140 Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
144 function showFullName()
146 if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
147 if ($this->profile->fullname) {
148 $this->out->elementStart('dl', 'entity_fn');
149 $this->out->element('dt', null, _('Full name'));
150 $this->out->elementStart('dd');
151 $this->out->element('span', 'fn', $this->profile->fullname);
152 $this->out->elementEnd('dd');
153 $this->out->elementEnd('dl');
155 Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
159 function showLocation()
161 if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
162 if ($this->profile->location) {
163 $this->out->elementStart('dl', 'entity_location');
164 $this->out->element('dt', null, _('Location'));
165 $this->out->element('dd', 'label', $this->profile->location);
166 $this->out->elementEnd('dl');
168 Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
172 function showHomepage()
174 if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
175 if ($this->profile->homepage) {
176 $this->out->elementStart('dl', 'entity_url');
177 $this->out->element('dt', null, _('URL'));
178 $this->out->elementStart('dd');
179 $this->out->element('a', array('href' => $this->profile->homepage,
180 'rel' => 'me', 'class' => 'url'),
181 $this->profile->homepage);
182 $this->out->elementEnd('dd');
183 $this->out->elementEnd('dl');
185 Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
191 if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
192 if ($this->profile->bio) {
193 $this->out->elementStart('dl', 'entity_note');
194 $this->out->element('dt', null, _('Note'));
195 $this->out->element('dd', 'note', $this->profile->bio);
196 $this->out->elementEnd('dl');
198 Event::handle('EndProfilePageBio', array($this->out, $this->profile));
202 function showProfileTags()
204 if (Event::handle('StartProfilePageProfileTags', array($this->out, $this->profile))) {
205 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
207 if (count($tags) > 0) {
208 $this->out->elementStart('dl', 'entity_tags');
209 $this->out->element('dt', null, _('Tags'));
210 $this->out->elementStart('dd');
211 $this->out->elementStart('ul', 'tags xoxo');
212 foreach ($tags as $tag) {
213 $this->out->elementStart('li');
214 // Avoid space by using raw output.
215 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
216 common_local_url('peopletag', array('tag' => $tag)) .
217 '">' . $tag . '</a>';
218 $this->out->raw($pt);
219 $this->out->elementEnd('li');
221 $this->out->elementEnd('ul');
222 $this->out->elementEnd('dd');
223 $this->out->elementEnd('dl');
225 Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
229 function showEntityActions()
231 if ($this->profile->hasRole(Profile_role::DELETED)) {
232 $this->out->elementStart('div', 'entity_actions');
233 $this->out->element('h2', null, _('User actions'));
234 $this->out->elementStart('ul');
235 $this->out->elementStart('p', array('class' => 'profile_deleted'));
236 $this->out->text(_('User deletion in progress...'));
237 $this->out->elementEnd('p');
238 $this->out->elementEnd('ul');
239 $this->out->elementEnd('div');
242 if (Event::handle('StartProfilePageActionsSection', array(&$this->out, $this->profile))) {
244 $cur = common_current_user();
246 $this->out->elementStart('div', 'entity_actions');
247 $this->out->element('h2', null, _('User actions'));
248 $this->out->elementStart('ul');
250 if (Event::handle('StartProfilePageActionsElements', array(&$this->out, $this->profile))) {
251 if (empty($cur)) { // not logged in
252 if (Event::handle('StartProfileRemoteSubscribe', array(&$this->out, $this->profile))) {
253 $this->out->elementStart('li', 'entity_subscribe');
254 $this->showRemoteSubscribeLink();
255 $this->out->elementEnd('li');
256 Event::handle('EndProfileRemoteSubscribe', array(&$this->out, $this->profile));
259 if ($cur->id == $this->profile->id) { // your own page
260 $this->out->elementStart('li', 'entity_edit');
261 $this->out->element('a', array('href' => common_local_url('profilesettings'),
262 'title' => _('Edit profile settings')),
264 $this->out->elementEnd('li');
265 } else { // someone else's page
267 // subscribe/unsubscribe button
269 $this->out->elementStart('li', 'entity_subscribe');
271 if ($cur->isSubscribed($this->profile)) {
272 $usf = new UnsubscribeForm($this->out, $this->profile);
275 $sf = new SubscribeForm($this->out, $this->profile);
278 $this->out->elementEnd('li');
280 if ($cur->mutuallySubscribed($this->user)) {
284 $this->out->elementStart('li', 'entity_send-a-message');
285 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
286 'title' => _('Send a direct message to this user')),
288 $this->out->elementEnd('li');
292 if ($this->user->email && $this->user->emailnotifynudge) {
293 $this->out->elementStart('li', 'entity_nudge');
294 $nf = new NudgeForm($this->out, $this->user);
296 $this->out->elementEnd('li');
300 // return-to args, so we don't have to keep re-writing them
302 list($action, $r2args) = $this->out->returnToArgs();
304 // push the action into the list
306 $r2args['action'] = $action;
310 $blocked = $cur->hasBlocked($this->profile);
311 $this->out->elementStart('li', 'entity_block');
313 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
316 $bf = new BlockForm($this->out, $this->profile, $r2args);
319 $this->out->elementEnd('li');
321 if ($cur->hasRight(Right::SANDBOXUSER) ||
322 $cur->hasRight(Right::SILENCEUSER) ||
323 $cur->hasRight(Right::DELETEUSER)) {
324 $this->out->elementStart('li', 'entity_moderation');
325 $this->out->element('p', null, _('Moderate'));
326 $this->out->elementStart('ul');
327 if ($cur->hasRight(Right::SANDBOXUSER)) {
328 $this->out->elementStart('li', 'entity_sandbox');
329 if ($this->user->isSandboxed()) {
330 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
333 $sf = new SandboxForm($this->out, $this->profile, $r2args);
336 $this->out->elementEnd('li');
339 if ($cur->hasRight(Right::SILENCEUSER)) {
340 $this->out->elementStart('li', 'entity_silence');
341 if ($this->user->isSilenced()) {
342 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
345 $sf = new SilenceForm($this->out, $this->profile, $r2args);
348 $this->out->elementEnd('li');
351 if ($cur->hasRight(Right::DELETEUSER)) {
352 $this->out->elementStart('li', 'entity_delete');
353 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
355 $this->out->elementEnd('li');
357 $this->out->elementEnd('ul');
358 $this->out->elementEnd('li');
361 if ($cur->hasRight(Right::GRANTROLE)) {
362 $this->out->elementStart('li', 'entity_role');
363 $this->out->element('p', null, _('User role'));
364 $this->out->elementStart('ul');
365 $this->roleButton('administrator', _m('role', 'Administrator'));
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->user->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'),