]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/userprofile.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / lib / userprofile.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Profile for a particular user
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Action
23  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/widget.php';
36
37 /**
38  * Profile of a user
39  *
40  * Shows profile information about a particular user
41  *
42  * @category Output
43  * @package  StatusNet
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/
48  *
49  * @see      HTMLOutputter
50  */
51
52 class UserProfile extends Widget
53 {
54     var $user = null;
55     var $profile = null;
56
57     function __construct($action=null, $user=null, $profile=null)
58     {
59         parent::__construct($action);
60         $this->user = $user;
61         $this->profile = $profile;
62     }
63
64     function show()
65     {
66         $this->showProfileData();
67         $this->showEntityActions();
68     }
69
70     function showProfileData()
71     {
72         if (Event::handle('StartProfilePageProfileSection', array(&$this->out, $this->profile))) {
73
74             $this->out->elementStart('div', array('id' => 'i',
75                                                   'class' => 'entity_profile vcard author'));
76             $this->out->element('h2', null, _('User profile'));
77
78             if (Event::handle('StartProfilePageProfileElements', array(&$this->out, $this->profile))) {
79
80                 $this->showAvatar();
81                 $this->showNickname();
82                 $this->showFullName();
83                 $this->showLocation();
84                 $this->showHomepage();
85                 $this->showBio();
86                 $this->showProfileTags();
87
88                 Event::handle('EndProfilePageProfileElements', array(&$this->out, $this->profile));
89             }
90
91             $this->out->elementEnd('div');
92             Event::handle('EndProfilePageProfileSection', array(&$this->out, $this->profile));
93         }
94     }
95
96     function showAvatar()
97     {
98         if (Event::handle('StartProfilePageAvatar', array($this->out, $this->profile))) {
99
100             $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
101             if (!$avatar) {
102                 // hack for remote Twitter users: no 96px, but large Twitter size is 73px
103                 $avatar = $this->profile->getAvatar(73);
104             }
105
106             $this->out->elementStart('dl', 'entity_depiction');
107             $this->out->element('dt', null, _('Photo'));
108             $this->out->elementStart('dd');
109             $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
110                                         'class' => 'photo avatar',
111                                         'width' => AVATAR_PROFILE_SIZE,
112                                         'height' => AVATAR_PROFILE_SIZE,
113                                         'alt' => $this->profile->nickname));
114             $this->out->elementEnd('dd');
115
116             $cur = common_current_user();
117             if ($cur && $cur->id == $this->profile->id) {
118                 $this->out->elementStart('dd');
119                 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
120                 $this->out->elementEnd('dd');
121             }
122
123             $this->out->elementEnd('dl');
124
125             Event::handle('EndProfilePageAvatar', array($this->out, $this->profile));
126         }
127     }
128
129     function showNickname()
130     {
131         if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
132
133             $this->out->elementStart('dl', 'entity_nickname');
134             $this->out->element('dt', null, _('Nickname'));
135             $this->out->elementStart('dd');
136             $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
137             $this->out->element('a', array('href' => $this->profile->profileurl,
138                                       'rel' => 'me', 'class' => $hasFN),
139                            $this->profile->nickname);
140             $this->out->elementEnd('dd');
141             $this->out->elementEnd('dl');
142
143             Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
144         }
145     }
146
147     function showFullName()
148     {
149         if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
150             if ($this->profile->fullname) {
151                 $this->out->elementStart('dl', 'entity_fn');
152                 $this->out->element('dt', null, _('Full name'));
153                 $this->out->elementStart('dd');
154                 $this->out->element('span', 'fn', $this->profile->fullname);
155                 $this->out->elementEnd('dd');
156                 $this->out->elementEnd('dl');
157             }
158             Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
159         }
160     }
161
162     function showLocation()
163     {
164         if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
165             if ($this->profile->location) {
166                 $this->out->elementStart('dl', 'entity_location');
167                 $this->out->element('dt', null, _('Location'));
168                 $this->out->element('dd', 'label', $this->profile->location);
169                 $this->out->elementEnd('dl');
170             }
171             Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
172         }
173     }
174
175     function showHomepage()
176     {
177         if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
178             if ($this->profile->homepage) {
179                 $this->out->elementStart('dl', 'entity_url');
180                 $this->out->element('dt', null, _('URL'));
181                 $this->out->elementStart('dd');
182                 $this->out->element('a', array('href' => $this->profile->homepage,
183                                           'rel' => 'me', 'class' => 'url'),
184                                $this->profile->homepage);
185                 $this->out->elementEnd('dd');
186                 $this->out->elementEnd('dl');
187             }
188             Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
189         }
190     }
191
192     function showBio()
193     {
194         if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
195             if ($this->profile->bio) {
196                 $this->out->elementStart('dl', 'entity_note');
197                 $this->out->element('dt', null, _('Note'));
198                 $this->out->element('dd', 'note', $this->profile->bio);
199                 $this->out->elementEnd('dl');
200             }
201             Event::handle('EndProfilePageBio', array($this->out, $this->profile));
202         }
203     }
204
205     function showProfileTags()
206     {
207         if (Event::handle('StartProfilePageProfileTags', array($this->out, $this->profile))) {
208             $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
209
210             if (count($tags) > 0) {
211                 $this->out->elementStart('dl', 'entity_tags');
212                 $this->out->element('dt', null, _('Tags'));
213                 $this->out->elementStart('dd');
214                 $this->out->elementStart('ul', 'tags xoxo');
215                 foreach ($tags as $tag) {
216                     $this->out->elementStart('li');
217                     // Avoid space by using raw output.
218                     $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
219                       common_local_url('peopletag', array('tag' => $tag)) .
220                       '">' . $tag . '</a>';
221                     $this->out->raw($pt);
222                     $this->out->elementEnd('li');
223                 }
224                 $this->out->elementEnd('ul');
225                 $this->out->elementEnd('dd');
226                 $this->out->elementEnd('dl');
227             }
228             Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
229         }
230     }
231
232     function showEntityActions()
233     {
234         if ($this->profile->hasRole(Profile_role::DELETED)) {
235             $this->out->elementStart('div', 'entity_actions');
236             $this->out->element('h2', null, _('User actions'));
237             $this->out->elementStart('ul');
238             $this->out->elementStart('p', array('class' => 'profile_deleted'));
239             $this->out->text(_('User deletion in progress...'));
240             $this->out->elementEnd('p');
241             $this->out->elementEnd('ul');
242             $this->out->elementEnd('div');
243             return;
244         }
245         if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
246
247             $cur = common_current_user();
248
249             $this->out->elementStart('div', 'entity_actions');
250             $this->out->element('h2', null, _('User actions'));
251             $this->out->elementStart('ul');
252
253             if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
254                 if (empty($cur)) { // not logged in
255                     if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
256                         $this->out->elementStart('li', 'entity_subscribe');
257                         $this->showRemoteSubscribeLink();
258                         $this->out->elementEnd('li');
259                         Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
260                     }
261                 } else {
262                     if ($cur->id == $this->profile->id) { // your own page
263                         $this->out->elementStart('li', 'entity_edit');
264                         $this->out->element('a', array('href' => common_local_url('profilesettings'),
265                                                   'title' => _('Edit profile settings')),
266                                        _('Edit'));
267                         $this->out->elementEnd('li');
268                     } else { // someone else's page
269
270                         // subscribe/unsubscribe button
271
272                         $this->out->elementStart('li', 'entity_subscribe');
273
274                         if ($cur->isSubscribed($this->profile)) {
275                             $usf = new UnsubscribeForm($this->out, $this->profile);
276                             $usf->show();
277                         } else {
278                             $sf = new SubscribeForm($this->out, $this->profile);
279                             $sf->show();
280                         }
281                         $this->out->elementEnd('li');
282
283                         if ($cur->mutuallySubscribed($this->profile)) {
284
285                             // message
286
287                             $this->out->elementStart('li', 'entity_send-a-message');
288                             $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
289                                                       'title' => _('Send a direct message to this user')),
290                                            _('Message'));
291                             $this->out->elementEnd('li');
292
293                             // nudge
294
295                             if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
296                                 $this->out->elementStart('li', 'entity_nudge');
297                                 $nf = new NudgeForm($this->out, $this->user);
298                                 $nf->show();
299                                 $this->out->elementEnd('li');
300                             }
301                         }
302
303                         // return-to args, so we don't have to keep re-writing them
304
305                         list($action, $r2args) = $this->out->returnToArgs();
306
307                         // push the action into the list
308
309                         $r2args['action'] = $action;
310
311                         // block/unblock
312
313                         $blocked = $cur->hasBlocked($this->profile);
314                         $this->out->elementStart('li', 'entity_block');
315                         if ($blocked) {
316                             $ubf = new UnblockForm($this->out, $this->profile, $r2args);
317                             $ubf->show();
318                         } else {
319                             $bf = new BlockForm($this->out, $this->profile, $r2args);
320                             $bf->show();
321                         }
322                         $this->out->elementEnd('li');
323
324                         // Some actions won't be applicable to non-local users.
325                         $isLocal = !empty($this->user);
326
327                         if ($cur->hasRight(Right::SANDBOXUSER) ||
328                             $cur->hasRight(Right::SILENCEUSER) ||
329                             $cur->hasRight(Right::DELETEUSER)) {
330                             $this->out->elementStart('li', 'entity_moderation');
331                             $this->out->element('p', null, _('Moderate'));
332                             $this->out->elementStart('ul');
333                             if ($cur->hasRight(Right::SANDBOXUSER)) {
334                                 $this->out->elementStart('li', 'entity_sandbox');
335                                 if ($this->profile->isSandboxed()) {
336                                     $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
337                                     $usf->show();
338                                 } else {
339                                     $sf = new SandboxForm($this->out, $this->profile, $r2args);
340                                     $sf->show();
341                                 }
342                                 $this->out->elementEnd('li');
343                             }
344
345                             if ($cur->hasRight(Right::SILENCEUSER)) {
346                                 $this->out->elementStart('li', 'entity_silence');
347                                 if ($this->profile->isSilenced()) {
348                                     $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
349                                     $usf->show();
350                                 } else {
351                                     $sf = new SilenceForm($this->out, $this->profile, $r2args);
352                                     $sf->show();
353                                 }
354                                 $this->out->elementEnd('li');
355                             }
356
357                             if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
358                                 $this->out->elementStart('li', 'entity_delete');
359                                 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
360                                 $df->show();
361                                 $this->out->elementEnd('li');
362                             }
363                             $this->out->elementEnd('ul');
364                             $this->out->elementEnd('li');
365                         }
366                         
367                         if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
368                             $this->out->elementStart('li', 'entity_role');
369                             $this->out->element('p', null, _('User role'));
370                             $this->out->elementStart('ul');
371                             $this->roleButton('administrator', _m('role', 'Administrator'));
372                             $this->roleButton('moderator', _m('role', 'Moderator'));
373                             $this->out->elementEnd('ul');
374                             $this->out->elementEnd('li');
375                         }
376                     }
377                 }
378
379                 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
380             }
381
382             $this->out->elementEnd('ul');
383             $this->out->elementEnd('div');
384
385             Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
386         }
387     }
388
389     function roleButton($role, $label)
390     {
391         list($action, $r2args) = $this->out->returnToArgs();
392         $r2args['action'] = $action;
393
394         $this->out->elementStart('li', "entity_role_$role");
395         if ($this->profile->hasRole($role)) {
396             $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
397             $rf->show();
398         } else {
399             $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
400             $rf->show();
401         }
402         $this->out->elementEnd('li');
403     }
404
405     function showRemoteSubscribeLink()
406     {
407         $url = common_local_url('remotesubscribe',
408                                 array('nickname' => $this->profile->nickname));
409         $this->out->element('a', array('href' => $url,
410                                   'class' => 'entity_remote_subscribe'),
411                        _('Subscribe'));
412     }
413 }