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 (Event::handle('StartProfilePageActionsSection', array(&$this->out, $this->profile))) {
233 $cur = common_current_user();
235 $this->out->elementStart('div', 'entity_actions');
236 $this->out->element('h2', null, _('User actions'));
237 $this->out->elementStart('ul');
239 if (Event::handle('StartProfilePageActionsElements', array(&$this->out, $this->profile))) {
240 if (empty($cur)) { // not logged in
241 if (Event::handle('StartProfileRemoteSubscribe', array(&$this->out, $this->profile))) {
242 $this->out->elementStart('li', 'entity_subscribe');
243 $this->showRemoteSubscribeLink();
244 $this->out->elementEnd('li');
245 Event::handle('EndProfileRemoteSubscribe', array(&$this->out, $this->profile));
248 if ($cur->id == $this->profile->id) { // your own page
249 $this->out->elementStart('li', 'entity_edit');
250 $this->out->element('a', array('href' => common_local_url('profilesettings'),
251 'title' => _('Edit profile settings')),
253 $this->out->elementEnd('li');
254 } else { // someone else's page
256 // subscribe/unsubscribe button
258 $this->out->elementStart('li', 'entity_subscribe');
260 if ($cur->isSubscribed($this->profile)) {
261 $usf = new UnsubscribeForm($this->out, $this->profile);
264 $sf = new SubscribeForm($this->out, $this->profile);
267 $this->out->elementEnd('li');
269 if ($cur->mutuallySubscribed($this->user)) {
273 $this->out->elementStart('li', 'entity_send-a-message');
274 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
275 'title' => _('Send a direct message to this user')),
277 $this->out->elementEnd('li');
281 if ($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 if ($cur->hasRight(Right::SANDBOXUSER) ||
311 $cur->hasRight(Right::SILENCEUSER) ||
312 $cur->hasRight(Right::DELETEUSER)) {
313 $this->out->elementStart('li', 'entity_moderation');
314 $this->out->element('p', null, _('Moderate'));
315 $this->out->elementStart('ul');
316 if ($cur->hasRight(Right::SANDBOXUSER)) {
317 $this->out->elementStart('li', 'entity_sandbox');
318 if ($this->user->isSandboxed()) {
319 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
322 $sf = new SandboxForm($this->out, $this->profile, $r2args);
325 $this->out->elementEnd('li');
328 if ($cur->hasRight(Right::SILENCEUSER)) {
329 $this->out->elementStart('li', 'entity_silence');
330 if ($this->user->isSilenced()) {
331 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
334 $sf = new SilenceForm($this->out, $this->profile, $r2args);
337 $this->out->elementEnd('li');
340 if ($cur->hasRight(Right::DELETEUSER)) {
341 $this->out->elementStart('li', 'entity_delete');
342 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
344 $this->out->elementEnd('li');
346 $this->out->elementEnd('ul');
347 $this->out->elementEnd('li');
352 Event::handle('EndProfilePageActionsElements', array(&$this->out, $this->profile));
355 $this->out->elementEnd('ul');
356 $this->out->elementEnd('div');
358 Event::handle('EndProfilePageActionsSection', array(&$this->out, $this->profile));
362 function showRemoteSubscribeLink()
364 $url = common_local_url('remotesubscribe',
365 array('nickname' => $this->profile->nickname));
366 $this->out->element('a', array('href' => $url,
367 'class' => 'entity_remote_subscribe'),