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