]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/userprofile.php
fix ModPlus 'remote profile options' popup for Realtime
[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 class UserProfile extends Widget
52 {
53     var $user = null;
54     var $profile = null;
55
56     function __construct($action=null, $user=null, $profile=null)
57     {
58         parent::__construct($action);
59         $this->user = $user;
60         $this->profile = $profile;
61     }
62
63     function show()
64     {
65         $this->showProfileData();
66         $this->showEntityActions();
67     }
68
69     function showProfileData()
70     {
71         if (Event::handle('StartProfilePageProfileSection', array(&$this->out, $this->profile))) {
72
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'));
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             // TRANS: DT element in area for user avatar.
108             $this->out->element('dt', null, _('Photo'));
109             $this->out->elementStart('dd');
110             $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
111                                         'class' => 'photo avatar',
112                                         'width' => AVATAR_PROFILE_SIZE,
113                                         'height' => AVATAR_PROFILE_SIZE,
114                                         'alt' => $this->profile->nickname));
115             $this->out->elementEnd('dd');
116
117             $cur = common_current_user();
118             if ($cur && $cur->id == $this->profile->id) {
119                 $this->out->elementStart('dd');
120                 // TRANS: Link text for changeing the avatar of the logged in user.
121                 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
122                 $this->out->elementEnd('dd');
123             }
124
125             $this->out->elementEnd('dl');
126
127             Event::handle('EndProfilePageAvatar', array($this->out, $this->profile));
128         }
129     }
130
131     function showNickname()
132     {
133         if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
134
135             $this->out->elementStart('dl', 'entity_nickname');
136             // TRANS: DT for nick name in a profile.
137             $this->out->element('dt', null, _('Nickname'));
138             $this->out->elementStart('dd');
139             $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
140             $this->out->element('a', array('href' => $this->profile->profileurl,
141                                       'rel' => 'me', 'class' => $hasFN),
142                            $this->profile->nickname);
143             $this->out->elementEnd('dd');
144             $this->out->elementEnd('dl');
145
146             Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
147         }
148     }
149
150     function showFullName()
151     {
152         if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
153             if ($this->profile->fullname) {
154                 $this->out->elementStart('dl', 'entity_fn');
155                 // TRANS: DT for full name in a profile.
156                 $this->out->element('dt', null, _('Full name'));
157                 $this->out->elementStart('dd');
158                 $this->out->element('span', 'fn', $this->profile->fullname);
159                 $this->out->elementEnd('dd');
160                 $this->out->elementEnd('dl');
161             }
162             Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
163         }
164     }
165
166     function showLocation()
167     {
168         if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
169             if ($this->profile->location) {
170                 $this->out->elementStart('dl', 'entity_location');
171                 // TRANS: DT for location in a profile.
172                 $this->out->element('dt', null, _('Location'));
173                 $this->out->element('dd', 'label', $this->profile->location);
174                 $this->out->elementEnd('dl');
175             }
176             Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
177         }
178     }
179
180     function showHomepage()
181     {
182         if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
183             if ($this->profile->homepage) {
184                 $this->out->elementStart('dl', 'entity_url');
185                 // TRANS: DT for URL in a profile.
186                 $this->out->element('dt', null, _('URL'));
187                 $this->out->elementStart('dd');
188                 $this->out->element('a', array('href' => $this->profile->homepage,
189                                           'rel' => 'me', 'class' => 'url'),
190                                $this->profile->homepage);
191                 $this->out->elementEnd('dd');
192                 $this->out->elementEnd('dl');
193             }
194             Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
195         }
196     }
197
198     function showBio()
199     {
200         if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
201             if ($this->profile->bio) {
202                 $this->out->elementStart('dl', 'entity_note');
203                 // TRANS: DT for note in a profile.
204                 $this->out->element('dt', null, _('Note'));
205                 $this->out->element('dd', 'note', $this->profile->bio);
206                 $this->out->elementEnd('dl');
207             }
208             Event::handle('EndProfilePageBio', array($this->out, $this->profile));
209         }
210     }
211
212     function showProfileTags()
213     {
214         if (Event::handle('StartProfilePageProfileTags', array($this->out, $this->profile))) {
215             $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
216
217             if (count($tags) > 0) {
218                 $this->out->elementStart('dl', 'entity_tags');
219                 // TRANS: DT for tags in a profile.
220                 $this->out->element('dt', null, _('Tags'));
221                 $this->out->elementStart('dd');
222                 $this->out->elementStart('ul', 'tags xoxo');
223                 foreach ($tags as $tag) {
224                     $this->out->elementStart('li');
225                     // Avoid space by using raw output.
226                     $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
227                       common_local_url('peopletag', array('tag' => $tag)) .
228                       '">' . $tag . '</a>';
229                     $this->out->raw($pt);
230                     $this->out->elementEnd('li');
231                 }
232                 $this->out->elementEnd('ul');
233                 $this->out->elementEnd('dd');
234                 $this->out->elementEnd('dl');
235             }
236             Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
237         }
238     }
239
240     function showEntityActions()
241     {
242         if ($this->profile->hasRole(Profile_role::DELETED)) {
243             $this->out->elementStart('div', 'entity_actions');
244             // TRANS: H2 for user actions in a profile.
245             $this->out->element('h2', null, _('User actions'));
246             $this->out->elementStart('ul');
247             $this->out->elementStart('p', array('class' => 'profile_deleted'));
248             // TRANS: Text shown in user profile of not yet compeltely deleted users.
249             $this->out->text(_('User deletion in progress...'));
250             $this->out->elementEnd('p');
251             $this->out->elementEnd('ul');
252             $this->out->elementEnd('div');
253             return;
254         }
255         if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
256
257             $cur = common_current_user();
258
259             $this->out->elementStart('div', 'entity_actions');
260             // TRANS: H2 for entity actions in a profile.
261             $this->out->element('h2', null, _('User actions'));
262             $this->out->elementStart('ul');
263
264             if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
265                 if (empty($cur)) { // not logged in
266                     if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
267                         $this->out->elementStart('li', 'entity_subscribe');
268                         $this->showRemoteSubscribeLink();
269                         $this->out->elementEnd('li');
270                         Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
271                     }
272                 } else {
273                     if ($cur->id == $this->profile->id) { // your own page
274                         $this->out->elementStart('li', 'entity_edit');
275                         $this->out->element('a', array('href' => common_local_url('profilesettings'),
276                                                   // TRANS: Link title for link on user profile.
277                                                   'title' => _('Edit profile settings')),
278                                        // TRANS: Link text for link on user profile.
279                                        _('Edit'));
280                         $this->out->elementEnd('li');
281                     } else { // someone else's page
282
283                         // subscribe/unsubscribe button
284
285                         $this->out->elementStart('li', 'entity_subscribe');
286
287                         if ($cur->isSubscribed($this->profile)) {
288                             $usf = new UnsubscribeForm($this->out, $this->profile);
289                             $usf->show();
290                         } else {
291                             $sf = new SubscribeForm($this->out, $this->profile);
292                             $sf->show();
293                         }
294                         $this->out->elementEnd('li');
295
296                         if ($cur->mutuallySubscribed($this->profile)) {
297
298                             // message
299
300                             $this->out->elementStart('li', 'entity_send-a-message');
301                             $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
302                                                       // TRANS: Link title for link on user profile.
303                                                       'title' => _('Send a direct message to this user')),
304                                            // TRANS: Link text for link on user profile.
305                                            _('Message'));
306                             $this->out->elementEnd('li');
307
308                             // nudge
309
310                             if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
311                                 $this->out->elementStart('li', 'entity_nudge');
312                                 $nf = new NudgeForm($this->out, $this->user);
313                                 $nf->show();
314                                 $this->out->elementEnd('li');
315                             }
316                         }
317
318                         // return-to args, so we don't have to keep re-writing them
319
320                         list($action, $r2args) = $this->out->returnToArgs();
321
322                         // push the action into the list
323
324                         $r2args['action'] = $action;
325
326                         // block/unblock
327
328                         $blocked = $cur->hasBlocked($this->profile);
329                         $this->out->elementStart('li', 'entity_block');
330                         if ($blocked) {
331                             $ubf = new UnblockForm($this->out, $this->profile, $r2args);
332                             $ubf->show();
333                         } else {
334                             $bf = new BlockForm($this->out, $this->profile, $r2args);
335                             $bf->show();
336                         }
337                         $this->out->elementEnd('li');
338
339                         // Some actions won't be applicable to non-local users.
340                         $isLocal = !empty($this->user);
341
342                         if ($cur->hasRight(Right::SANDBOXUSER) ||
343                             $cur->hasRight(Right::SILENCEUSER) ||
344                             $cur->hasRight(Right::DELETEUSER)) {
345                             $this->out->elementStart('li', 'entity_moderation');
346                             // TRANS: Label text on user profile to select a user role.
347                             $this->out->element('p', null, _('Moderate'));
348                             $this->out->elementStart('ul');
349                             if ($cur->hasRight(Right::SANDBOXUSER)) {
350                                 $this->out->elementStart('li', 'entity_sandbox');
351                                 if ($this->profile->isSandboxed()) {
352                                     $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
353                                     $usf->show();
354                                 } else {
355                                     $sf = new SandboxForm($this->out, $this->profile, $r2args);
356                                     $sf->show();
357                                 }
358                                 $this->out->elementEnd('li');
359                             }
360
361                             if ($cur->hasRight(Right::SILENCEUSER)) {
362                                 $this->out->elementStart('li', 'entity_silence');
363                                 if ($this->profile->isSilenced()) {
364                                     $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
365                                     $usf->show();
366                                 } else {
367                                     $sf = new SilenceForm($this->out, $this->profile, $r2args);
368                                     $sf->show();
369                                 }
370                                 $this->out->elementEnd('li');
371                             }
372
373                             if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
374                                 $this->out->elementStart('li', 'entity_delete');
375                                 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
376                                 $df->show();
377                                 $this->out->elementEnd('li');
378                             }
379                             $this->out->elementEnd('ul');
380                             $this->out->elementEnd('li');
381                         }
382
383                         if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
384                             $this->out->elementStart('li', 'entity_role');
385                             // TRANS: Label text on user profile to select a user role.
386                             $this->out->element('p', null, _('User role'));
387                             $this->out->elementStart('ul');
388                             // TRANS: Role that can be set for a user profile.
389                             $this->roleButton('administrator', _m('role', 'Administrator'));
390                             // TRANS: Role that can be set for a user profile.
391                             $this->roleButton('moderator', _m('role', 'Moderator'));
392                             $this->out->elementEnd('ul');
393                             $this->out->elementEnd('li');
394                         }
395                     }
396                 }
397
398                 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
399             }
400
401             $this->out->elementEnd('ul');
402             $this->out->elementEnd('div');
403
404             Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
405         }
406     }
407
408     function roleButton($role, $label)
409     {
410         list($action, $r2args) = $this->out->returnToArgs();
411         $r2args['action'] = $action;
412
413         $this->out->elementStart('li', "entity_role_$role");
414         if ($this->profile->hasRole($role)) {
415             $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
416             $rf->show();
417         } else {
418             $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
419             $rf->show();
420         }
421         $this->out->elementEnd('li');
422     }
423
424     function showRemoteSubscribeLink()
425     {
426         $url = common_local_url('remotesubscribe',
427                                 array('nickname' => $this->profile->nickname));
428         $this->out->element('a', array('href' => $url,
429                                   'class' => 'entity_remote_subscribe'),
430                        // TRANS: Link text for link that will subscribe to a remote profile.
431                        _('Subscribe'));
432     }
433 }