]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/userprofile.php
people tag UI elements
[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 require_once INSTALLDIR.'/lib/peopletags.php';
37
38 /**
39  * Profile of a user
40  *
41  * Shows profile information about a particular user
42  *
43  * @category Output
44  * @package  StatusNet
45  * @author   Evan Prodromou <evan@status.net>
46  * @author   Sarven Capadisli <csarven@status.net>
47  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48  * @link     http://status.net/
49  *
50  * @see      HTMLOutputter
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             // TRANS: H2 for user profile information.
77             $this->out->element('h2', null, _('User profile'));
78
79             if (Event::handle('StartProfilePageProfileElements', array(&$this->out, $this->profile))) {
80
81                 $this->showAvatar();
82                 $this->showNickname();
83                 $this->showFullName();
84                 $this->showLocation();
85                 $this->showHomepage();
86                 $this->showBio();
87                 $this->showProfileTags();
88
89                 Event::handle('EndProfilePageProfileElements', array(&$this->out, $this->profile));
90             }
91
92             $this->out->elementEnd('div');
93             Event::handle('EndProfilePageProfileSection', array(&$this->out, $this->profile));
94         }
95     }
96
97     function showAvatar()
98     {
99         if (Event::handle('StartProfilePageAvatar', array($this->out, $this->profile))) {
100
101             $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
102             if (!$avatar) {
103                 // hack for remote Twitter users: no 96px, but large Twitter size is 73px
104                 $avatar = $this->profile->getAvatar(73);
105             }
106
107             $this->out->element('img', 
108                                 array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
109                                       'class' => 'photo avatar entity_depiction',
110                                       'width' => AVATAR_PROFILE_SIZE,
111                                       'height' => AVATAR_PROFILE_SIZE,
112                                       'alt' => $this->profile->nickname));
113             
114             $cur = common_current_user();
115
116             if ($cur && $cur->id == $this->profile->id) {
117                 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
118             }
119
120             Event::handle('EndProfilePageAvatar',
121                           array($this->out, $this->profile));
122         }
123     }
124
125     function showNickname()
126     {
127         if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
128
129             $hasFN = ($this->profile->fullname) ? 'entity_nickname nickname url uid' : 'entity_nickname fn nickname url uid';
130             $this->out->element('a',
131                                 array('href' => $this->profile->profileurl,
132                                       'rel' => 'me',
133                                       'class' => $hasFN),
134                            $this->profile->nickname);
135
136             Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
137         }
138     }
139
140     function showFullName()
141     {
142         if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
143             if ($this->profile->fullname) {
144                 $this->out->element('span',
145                                     'entity_fn fn',
146                                     $this->profile->fullname);
147             }
148             Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
149         }
150     }
151
152     function showLocation()
153     {
154         if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
155             if ($this->profile->location) {
156                 $this->out->element('span',
157                                     'entity_location label',
158                                     $this->profile->location);
159             }
160             Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
161         }
162     }
163
164     function showHomepage()
165     {
166         if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
167             if ($this->profile->homepage) {
168                 $this->out->element('a',
169                                     array('href' => $this->profile->homepage,
170                                           'rel' => 'me',
171                                           'class' => 'url entity_url'),
172                                $this->profile->homepage);
173             }
174             Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
175         }
176     }
177
178     function showBio()
179     {
180         if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
181             if ($this->profile->bio) {
182                 $this->out->element('div',
183                                     'note entity_note',
184                                     $this->profile->bio);
185             }
186             Event::handle('EndProfilePageBio', array($this->out, $this->profile));
187         }
188     }
189
190     function showProfileTags()
191     {
192         $cur = common_current_user();
193
194         $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
195         $self_tags->show();
196
197         if ($cur) {
198             // don't show self-tags again
199             if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
200                 $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
201                 $tags->show();
202             }
203         }
204     }
205
206     function showEntityActions()
207     {
208         if ($this->profile->hasRole(Profile_role::DELETED)) {
209             $this->out->elementStart('div', 'entity_actions');
210             // TRANS: H2 for user actions in a profile.
211             $this->out->element('h2', null, _('User actions'));
212             $this->out->elementStart('ul');
213             $this->out->elementStart('p', array('class' => 'profile_deleted'));
214             // TRANS: Text shown in user profile of not yet compeltely deleted users.
215             $this->out->text(_('User deletion in progress...'));
216             $this->out->elementEnd('p');
217             $this->out->elementEnd('ul');
218             $this->out->elementEnd('div');
219             return;
220         }
221         if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
222
223             $cur = common_current_user();
224
225             $this->out->elementStart('div', 'entity_actions');
226             // TRANS: H2 for entity actions in a profile.
227             $this->out->element('h2', null, _('User actions'));
228             $this->out->elementStart('ul');
229
230             if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
231                 if (empty($cur)) { // not logged in
232                     if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
233                         $this->out->elementStart('li', 'entity_subscribe');
234                         $this->showRemoteSubscribeLink();
235                         $this->out->elementEnd('li');
236                         Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
237                     }
238                 } else {
239                     if ($cur->id == $this->profile->id) { // your own page
240                         $this->out->elementStart('li', 'entity_edit');
241                         $this->out->element('a', array('href' => common_local_url('profilesettings'),
242                                                   // TRANS: Link title for link on user profile.
243                                                   'title' => _('Edit profile settings')),
244                                        // TRANS: Link text for link on user profile.
245                                        _('Edit'));
246                         $this->out->elementEnd('li');
247                     } else { // someone else's page
248
249                         // subscribe/unsubscribe button
250
251                         $this->out->elementStart('li', 'entity_subscribe');
252
253                         if ($cur->isSubscribed($this->profile)) {
254                             $usf = new UnsubscribeForm($this->out, $this->profile);
255                             $usf->show();
256                         } else {
257                             $sf = new SubscribeForm($this->out, $this->profile);
258                             $sf->show();
259                         }
260                         $this->out->elementEnd('li');
261
262                         if ($cur->mutuallySubscribed($this->profile)) {
263
264                             // message
265
266                             $this->out->elementStart('li', 'entity_send-a-message');
267                             $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
268                                                       // TRANS: Link title for link on user profile.
269                                                       'title' => _('Send a direct message to this user')),
270                                            // TRANS: Link text for link on user profile.
271                                            _('Message'));
272                             $this->out->elementEnd('li');
273
274                             // nudge
275
276                             if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
277                                 $this->out->elementStart('li', 'entity_nudge');
278                                 $nf = new NudgeForm($this->out, $this->user);
279                                 $nf->show();
280                                 $this->out->elementEnd('li');
281                             }
282                         }
283
284                         // return-to args, so we don't have to keep re-writing them
285
286                         list($action, $r2args) = $this->out->returnToArgs();
287
288                         // push the action into the list
289
290                         $r2args['action'] = $action;
291
292                         // block/unblock
293
294                         $blocked = $cur->hasBlocked($this->profile);
295                         $this->out->elementStart('li', 'entity_block');
296                         if ($blocked) {
297                             $ubf = new UnblockForm($this->out, $this->profile, $r2args);
298                             $ubf->show();
299                         } else {
300                             $bf = new BlockForm($this->out, $this->profile, $r2args);
301                             $bf->show();
302                         }
303                         $this->out->elementEnd('li');
304
305                         // Some actions won't be applicable to non-local users.
306                         $isLocal = !empty($this->user);
307
308                         if ($cur->hasRight(Right::SANDBOXUSER) ||
309                             $cur->hasRight(Right::SILENCEUSER) ||
310                             $cur->hasRight(Right::DELETEUSER)) {
311                             $this->out->elementStart('li', 'entity_moderation');
312                             // TRANS: Label text on user profile to select a user role.
313                             $this->out->element('p', null, _('Moderate'));
314                             $this->out->elementStart('ul');
315                             if ($cur->hasRight(Right::SANDBOXUSER)) {
316                                 $this->out->elementStart('li', 'entity_sandbox');
317                                 if ($this->profile->isSandboxed()) {
318                                     $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
319                                     $usf->show();
320                                 } else {
321                                     $sf = new SandboxForm($this->out, $this->profile, $r2args);
322                                     $sf->show();
323                                 }
324                                 $this->out->elementEnd('li');
325                             }
326
327                             if ($cur->hasRight(Right::SILENCEUSER)) {
328                                 $this->out->elementStart('li', 'entity_silence');
329                                 if ($this->profile->isSilenced()) {
330                                     $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
331                                     $usf->show();
332                                 } else {
333                                     $sf = new SilenceForm($this->out, $this->profile, $r2args);
334                                     $sf->show();
335                                 }
336                                 $this->out->elementEnd('li');
337                             }
338
339                             if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
340                                 $this->out->elementStart('li', 'entity_delete');
341                                 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
342                                 $df->show();
343                                 $this->out->elementEnd('li');
344                             }
345                             $this->out->elementEnd('ul');
346                             $this->out->elementEnd('li');
347                         }
348
349                         if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
350                             $this->out->elementStart('li', 'entity_role');
351                             // TRANS: Label text on user profile to select a user role.
352                             $this->out->element('p', null, _('User role'));
353                             $this->out->elementStart('ul');
354                             // TRANS: Role that can be set for a user profile.
355                             $this->roleButton('administrator', _m('role', 'Administrator'));
356                             // TRANS: Role that can be set for a user profile.
357                             $this->roleButton('moderator', _m('role', 'Moderator'));
358                             $this->out->elementEnd('ul');
359                             $this->out->elementEnd('li');
360                         }
361                     }
362                 }
363
364                 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
365             }
366
367             $this->out->elementEnd('ul');
368             $this->out->elementEnd('div');
369
370             Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
371         }
372     }
373
374     function roleButton($role, $label)
375     {
376         list($action, $r2args) = $this->out->returnToArgs();
377         $r2args['action'] = $action;
378
379         $this->out->elementStart('li', "entity_role_$role");
380         if ($this->profile->hasRole($role)) {
381             $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
382             $rf->show();
383         } else {
384             $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
385             $rf->show();
386         }
387         $this->out->elementEnd('li');
388     }
389
390     function showRemoteSubscribeLink()
391     {
392         $url = common_local_url('remotesubscribe',
393                                 array('nickname' => $this->profile->nickname));
394         $this->out->element('a', array('href' => $url,
395                                   'class' => 'entity_remote_subscribe'),
396                        // TRANS: Link text for link that will subscribe to a remote profile.
397                        _('Subscribe'));
398     }
399 }