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 (Event::handle('StartProfilePageActionsSection', array(&$this->out, $this->profile))) {
234 $cur = common_current_user();
236 $this->out->elementStart('div', 'entity_actions');
237 $this->out->element('h2', null, _('User actions'));
238 $this->out->elementStart('ul');
240 if (Event::handle('StartProfilePageActionsElements', array(&$this->out, $this->profile))) {
241 if (empty($cur)) { // not logged in
242 if (Event::handle('StartProfileRemoteSubscribe', array(&$this->out, $this->profile))) {
243 $this->out->elementStart('li', 'entity_subscribe');
244 $this->showRemoteSubscribeLink();
245 $this->out->elementEnd('li');
246 Event::handle('EndProfileRemoteSubscribe', array(&$this->out, $this->profile));
249 if ($cur->id == $this->profile->id) { // your own page
250 $this->out->elementStart('li', 'entity_edit');
251 $this->out->element('a', array('href' => common_local_url('profilesettings'),
252 'title' => _('Edit profile settings')),
254 $this->out->elementEnd('li');
255 } else { // someone else's page
257 // subscribe/unsubscribe button
259 $this->out->elementStart('li', 'entity_subscribe');
261 if ($cur->isSubscribed($this->profile)) {
262 $usf = new UnsubscribeForm($this->out, $this->profile);
265 $sf = new SubscribeForm($this->out, $this->profile);
268 $this->out->elementEnd('li');
270 if ($cur->mutuallySubscribed($this->user)) {
274 $this->out->elementStart('li', 'entity_send-a-message');
275 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
276 'title' => _('Send a direct message to this user')),
278 $this->out->elementEnd('li');
282 if ($this->user->email && $this->user->emailnotifynudge) {
283 $this->out->elementStart('li', 'entity_nudge');
284 $nf = new NudgeForm($this->out, $this->user);
286 $this->out->elementEnd('li');
290 // return-to args, so we don't have to keep re-writing them
292 list($action, $r2args) = $this->out->returnToArgs();
294 // push the action into the list
296 $r2args['action'] = $action;
300 $blocked = $cur->hasBlocked($this->profile);
301 $this->out->elementStart('li', 'entity_block');
303 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
306 $bf = new BlockForm($this->out, $this->profile, $r2args);
309 $this->out->elementEnd('li');
311 if ($cur->hasRight(Right::SANDBOXUSER) ||
312 $cur->hasRight(Right::SILENCEUSER) ||
313 $cur->hasRight(Right::DELETEUSER)) {
314 $this->out->elementStart('li', 'entity_moderation');
315 $this->out->element('p', null, _('Moderate'));
316 $this->out->elementStart('ul');
317 if ($cur->hasRight(Right::SANDBOXUSER)) {
318 $this->out->elementStart('li', 'entity_sandbox');
319 if ($this->user->isSandboxed()) {
320 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
323 $sf = new SandboxForm($this->out, $this->profile, $r2args);
326 $this->out->elementEnd('li');
329 if ($cur->hasRight(Right::SILENCEUSER)) {
330 $this->out->elementStart('li', 'entity_silence');
331 if ($this->user->isSilenced()) {
332 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
335 $sf = new SilenceForm($this->out, $this->profile, $r2args);
338 $this->out->elementEnd('li');
341 if ($cur->hasRight(Right::DELETEUSER)) {
342 $this->out->elementStart('li', 'entity_delete');
343 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
345 $this->out->elementEnd('li');
347 $this->out->elementEnd('ul');
348 $this->out->elementEnd('li');
351 if ($cur->hasRight(Right::GRANTROLE)) {
352 $this->out->elementStart('li', 'entity_role');
353 $this->out->element('p', null, _('User role'));
354 $this->out->elementStart('ul');
355 $this->roleButton('administrator', _m('role', 'Administrator'));
356 $this->roleButton('moderator', _m('role', 'Moderator'));
357 $this->out->elementEnd('ul');
358 $this->out->elementEnd('li');
363 Event::handle('EndProfilePageActionsElements', array(&$this->out, $this->profile));
366 $this->out->elementEnd('ul');
367 $this->out->elementEnd('div');
369 Event::handle('EndProfilePageActionsSection', array(&$this->out, $this->profile));
373 function roleButton($role, $label)
375 list($action, $r2args) = $this->out->returnToArgs();
376 $r2args['action'] = $action;
378 $this->out->elementStart('li', "entity_role_$role");
379 if ($this->user->hasRole($role)) {
380 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
383 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
386 $this->out->elementEnd('li');
389 function showRemoteSubscribeLink()
391 $url = common_local_url('remotesubscribe',
392 array('nickname' => $this->profile->nickname));
393 $this->out->element('a', array('href' => $url,
394 'class' => 'entity_remote_subscribe'),