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 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->element('img',
107 array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
108 'class' => 'photo avatar entity_depiction',
109 'width' => AVATAR_PROFILE_SIZE,
110 'height' => AVATAR_PROFILE_SIZE,
111 'alt' => $this->profile->nickname));
113 $cur = common_current_user();
115 if ($cur && $cur->id == $this->profile->id) {
116 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
119 Event::handle('EndProfilePageAvatar',
120 array($this->out, $this->profile));
124 function showNickname()
126 if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
128 $hasFN = ($this->profile->fullname) ? 'entity_nickname nickname url uid' : 'entity_nickname fn nickname url uid';
129 $this->out->element('a',
130 array('href' => $this->profile->profileurl,
133 $this->profile->nickname);
135 Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
139 function showFullName()
141 if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
142 if ($this->profile->fullname) {
143 $this->out->element('span',
145 $this->profile->fullname);
147 Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
151 function showLocation()
153 if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
154 if ($this->profile->location) {
155 $this->out->element('span',
156 'entity_location label',
157 $this->profile->location);
159 Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
163 function showHomepage()
165 if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
166 if ($this->profile->homepage) {
167 $this->out->element('a',
168 array('href' => $this->profile->homepage,
170 'class' => 'url entity_url'),
171 $this->profile->homepage);
173 Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
179 if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
180 if ($this->profile->bio) {
181 $this->out->element('div',
183 $this->profile->bio);
185 Event::handle('EndProfilePageBio', array($this->out, $this->profile));
189 function showProfileTags()
191 if (Event::handle('StartProfilePageProfileTags', array($this->out, $this->profile))) {
192 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
194 if (count($tags) > 0) {
195 $this->out->elementStart('ul', 'tags xoxo entity_tags');
196 foreach ($tags as $tag) {
197 $this->out->elementStart('li');
198 // Avoid space by using raw output.
199 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
200 common_local_url('peopletag', array('tag' => $tag)) .
201 '">' . $tag . '</a>';
202 $this->out->raw($pt);
203 $this->out->elementEnd('li');
205 $this->out->elementEnd('ul');
207 Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
211 function showEntityActions()
213 if ($this->profile->hasRole(Profile_role::DELETED)) {
214 $this->out->elementStart('div', 'entity_actions');
215 // TRANS: H2 for user actions in a profile.
216 $this->out->element('h2', null, _('User actions'));
217 $this->out->elementStart('ul');
218 $this->out->elementStart('p', array('class' => 'profile_deleted'));
219 // TRANS: Text shown in user profile of not yet compeltely deleted users.
220 $this->out->text(_('User deletion in progress...'));
221 $this->out->elementEnd('p');
222 $this->out->elementEnd('ul');
223 $this->out->elementEnd('div');
226 if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
228 $cur = common_current_user();
230 $this->out->elementStart('div', 'entity_actions');
231 // TRANS: H2 for entity actions in a profile.
232 $this->out->element('h2', null, _('User actions'));
233 $this->out->elementStart('ul');
235 if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
236 if (empty($cur)) { // not logged in
237 if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
238 $this->out->elementStart('li', 'entity_subscribe');
239 $this->showRemoteSubscribeLink();
240 $this->out->elementEnd('li');
241 Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
244 if ($cur->id == $this->profile->id) { // your own page
245 $this->out->elementStart('li', 'entity_edit');
246 $this->out->element('a', array('href' => common_local_url('profilesettings'),
247 // TRANS: Link title for link on user profile.
248 'title' => _('Edit profile settings')),
249 // TRANS: Link text for link on user profile.
251 $this->out->elementEnd('li');
252 } else { // someone else's page
254 // subscribe/unsubscribe button
256 $this->out->elementStart('li', 'entity_subscribe');
258 if ($cur->isSubscribed($this->profile)) {
259 $usf = new UnsubscribeForm($this->out, $this->profile);
262 $sf = new SubscribeForm($this->out, $this->profile);
265 $this->out->elementEnd('li');
267 if ($cur->mutuallySubscribed($this->profile)) {
271 $this->out->elementStart('li', 'entity_send-a-message');
272 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
273 // TRANS: Link title for link on user profile.
274 'title' => _('Send a direct message to this user')),
275 // TRANS: Link text for link on user profile.
277 $this->out->elementEnd('li');
281 if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
282 $this->out->elementStart('li', 'entity_nudge');
283 $nf = new NudgeForm($this->out, $this->user);
285 $this->out->elementEnd('li');
289 // return-to args, so we don't have to keep re-writing them
291 list($action, $r2args) = $this->out->returnToArgs();
293 // push the action into the list
295 $r2args['action'] = $action;
299 $blocked = $cur->hasBlocked($this->profile);
300 $this->out->elementStart('li', 'entity_block');
302 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
305 $bf = new BlockForm($this->out, $this->profile, $r2args);
308 $this->out->elementEnd('li');
310 // Some actions won't be applicable to non-local users.
311 $isLocal = !empty($this->user);
313 if ($cur->hasRight(Right::SANDBOXUSER) ||
314 $cur->hasRight(Right::SILENCEUSER) ||
315 $cur->hasRight(Right::DELETEUSER)) {
316 $this->out->elementStart('li', 'entity_moderation');
317 // TRANS: Label text on user profile to select a user role.
318 $this->out->element('p', null, _('Moderate'));
319 $this->out->elementStart('ul');
320 if ($cur->hasRight(Right::SANDBOXUSER)) {
321 $this->out->elementStart('li', 'entity_sandbox');
322 if ($this->profile->isSandboxed()) {
323 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
326 $sf = new SandboxForm($this->out, $this->profile, $r2args);
329 $this->out->elementEnd('li');
332 if ($cur->hasRight(Right::SILENCEUSER)) {
333 $this->out->elementStart('li', 'entity_silence');
334 if ($this->profile->isSilenced()) {
335 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
338 $sf = new SilenceForm($this->out, $this->profile, $r2args);
341 $this->out->elementEnd('li');
344 if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
345 $this->out->elementStart('li', 'entity_delete');
346 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
348 $this->out->elementEnd('li');
350 $this->out->elementEnd('ul');
351 $this->out->elementEnd('li');
354 if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
355 $this->out->elementStart('li', 'entity_role');
356 // TRANS: Label text on user profile to select a user role.
357 $this->out->element('p', null, _('User role'));
358 $this->out->elementStart('ul');
359 // TRANS: Role that can be set for a user profile.
360 $this->roleButton('administrator', _m('role', 'Administrator'));
361 // TRANS: Role that can be set for a user profile.
362 $this->roleButton('moderator', _m('role', 'Moderator'));
363 $this->out->elementEnd('ul');
364 $this->out->elementEnd('li');
369 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
372 $this->out->elementEnd('ul');
373 $this->out->elementEnd('div');
375 Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
379 function roleButton($role, $label)
381 list($action, $r2args) = $this->out->returnToArgs();
382 $r2args['action'] = $action;
384 $this->out->elementStart('li', "entity_role_$role");
385 if ($this->profile->hasRole($role)) {
386 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
389 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
392 $this->out->elementEnd('li');
395 function showRemoteSubscribeLink()
397 $url = common_local_url('remotesubscribe',
398 array('nickname' => $this->profile->nickname));
399 $this->out->element('a', array('href' => $url,
400 'class' => 'entity_remote_subscribe'),
401 // TRANS: Link text for link that will subscribe to a remote profile.