]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/userprofile.php
Merge branch 'master' 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
102             $this->out->elementStart('dl', 'entity_depiction');
103             $this->out->element('dt', null, _('Photo'));
104             $this->out->elementStart('dd');
105             $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
106                                         'class' => 'photo avatar',
107                                         'width' => AVATAR_PROFILE_SIZE,
108                                         'height' => AVATAR_PROFILE_SIZE,
109                                         'alt' => $this->profile->nickname));
110             $this->out->elementEnd('dd');
111
112             $user = User::staticGet('id', $this->profile->id);
113
114             $cur = common_current_user();
115             if ($cur && $cur->id == $user->id) {
116                 $this->out->elementStart('dd');
117                 $this->out->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
118                 $this->out->elementEnd('dd');
119             }
120
121             $this->out->elementEnd('dl');
122
123             Event::handle('EndProfilePageAvatar', array($this->out, $this->profile));
124         }
125     }
126
127     function showNickname()
128     {
129         if (Event::handle('StartProfilePageNickname', array($this->out, $this->profile))) {
130
131             $this->out->elementStart('dl', 'entity_nickname');
132             $this->out->element('dt', null, _('Nickname'));
133             $this->out->elementStart('dd');
134             $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
135             $this->out->element('a', array('href' => $this->profile->profileurl,
136                                       'rel' => 'me', 'class' => $hasFN),
137                            $this->profile->nickname);
138             $this->out->elementEnd('dd');
139             $this->out->elementEnd('dl');
140
141             Event::handle('EndProfilePageNickname', array($this->out, $this->profile));
142         }
143     }
144
145     function showFullName()
146     {
147         if (Event::handle('StartProfilePageFullName', array($this->out, $this->profile))) {
148             if ($this->profile->fullname) {
149                 $this->out->elementStart('dl', 'entity_fn');
150                 $this->out->element('dt', null, _('Full name'));
151                 $this->out->elementStart('dd');
152                 $this->out->element('span', 'fn', $this->profile->fullname);
153                 $this->out->elementEnd('dd');
154                 $this->out->elementEnd('dl');
155             }
156             Event::handle('EndProfilePageFullName', array($this->out, $this->profile));
157         }
158     }
159
160     function showLocation()
161     {
162         if (Event::handle('StartProfilePageLocation', array($this->out, $this->profile))) {
163             if ($this->profile->location) {
164                 $this->out->elementStart('dl', 'entity_location');
165                 $this->out->element('dt', null, _('Location'));
166                 $this->out->element('dd', 'label', $this->profile->location);
167                 $this->out->elementEnd('dl');
168             }
169             Event::handle('EndProfilePageLocation', array($this->out, $this->profile));
170         }
171     }
172
173     function showHomepage()
174     {
175         if (Event::handle('StartProfilePageHomepage', array($this->out, $this->profile))) {
176             if ($this->profile->homepage) {
177                 $this->out->elementStart('dl', 'entity_url');
178                 $this->out->element('dt', null, _('URL'));
179                 $this->out->elementStart('dd');
180                 $this->out->element('a', array('href' => $this->profile->homepage,
181                                           'rel' => 'me', 'class' => 'url'),
182                                $this->profile->homepage);
183                 $this->out->elementEnd('dd');
184                 $this->out->elementEnd('dl');
185             }
186             Event::handle('EndProfilePageHomepage', array($this->out, $this->profile));
187         }
188     }
189
190     function showBio()
191     {
192         if (Event::handle('StartProfilePageBio', array($this->out, $this->profile))) {
193             if ($this->profile->bio) {
194                 $this->out->elementStart('dl', 'entity_note');
195                 $this->out->element('dt', null, _('Note'));
196                 $this->out->element('dd', 'note', $this->profile->bio);
197                 $this->out->elementEnd('dl');
198             }
199             Event::handle('EndProfilePageBio', array($this->out, $this->profile));
200         }
201     }
202
203     function showProfileTags()
204     {
205         if (Event::handle('StartProfilePageProfileTags', array($this->out, $this->profile))) {
206             $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
207
208             if (count($tags) > 0) {
209                 $this->out->elementStart('dl', 'entity_tags');
210                 $this->out->element('dt', null, _('Tags'));
211                 $this->out->elementStart('dd');
212                 $this->out->elementStart('ul', 'tags xoxo');
213                 foreach ($tags as $tag) {
214                     $this->out->elementStart('li');
215                     // Avoid space by using raw output.
216                     $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
217                       common_local_url('peopletag', array('tag' => $tag)) .
218                       '">' . $tag . '</a>';
219                     $this->out->raw($pt);
220                     $this->out->elementEnd('li');
221                 }
222                 $this->out->elementEnd('ul');
223                 $this->out->elementEnd('dd');
224                 $this->out->elementEnd('dl');
225             }
226             Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
227         }
228     }
229
230     function showEntityActions()
231     {
232         if ($this->profile->hasRole(Profile_role::DELETED)) {
233             $this->out->elementStart('div', 'entity_actions');
234             $this->out->element('h2', null, _('User actions'));
235             $this->out->elementStart('ul');
236             $this->out->elementStart('p', array('class' => 'profile_deleted'));
237             $this->out->text(_('User deletion in progress...'));
238             $this->out->elementEnd('p');
239             $this->out->elementEnd('ul');
240             $this->out->elementEnd('div');
241             return;
242         }
243         if (Event::handle('StartProfilePageActionsSection', array(&$this->out, $this->profile))) {
244
245             $cur = common_current_user();
246
247             $this->out->elementStart('div', 'entity_actions');
248             $this->out->element('h2', null, _('User actions'));
249             $this->out->elementStart('ul');
250
251             if (Event::handle('StartProfilePageActionsElements', array(&$this->out, $this->profile))) {
252                 if (empty($cur)) { // not logged in
253                     if (Event::handle('StartProfileRemoteSubscribe', array(&$this->out, $this->profile))) {
254                         $this->out->elementStart('li', 'entity_subscribe');
255                         $this->showRemoteSubscribeLink();
256                         $this->out->elementEnd('li');
257                         Event::handle('EndProfileRemoteSubscribe', array(&$this->out, $this->profile));
258                     }
259                 } else {
260                     if ($cur->id == $this->profile->id) { // your own page
261                         $this->out->elementStart('li', 'entity_edit');
262                         $this->out->element('a', array('href' => common_local_url('profilesettings'),
263                                                   'title' => _('Edit profile settings')),
264                                        _('Edit'));
265                         $this->out->elementEnd('li');
266                     } else { // someone else's page
267
268                         // subscribe/unsubscribe button
269
270                         $this->out->elementStart('li', 'entity_subscribe');
271
272                         if ($cur->isSubscribed($this->profile)) {
273                             $usf = new UnsubscribeForm($this->out, $this->profile);
274                             $usf->show();
275                         } else {
276                             $sf = new SubscribeForm($this->out, $this->profile);
277                             $sf->show();
278                         }
279                         $this->out->elementEnd('li');
280
281                         if ($cur->mutuallySubscribed($this->user)) {
282
283                             // message
284
285                             $this->out->elementStart('li', 'entity_send-a-message');
286                             $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
287                                                       'title' => _('Send a direct message to this user')),
288                                            _('Message'));
289                             $this->out->elementEnd('li');
290
291                             // nudge
292
293                             if ($this->user->email && $this->user->emailnotifynudge) {
294                                 $this->out->elementStart('li', 'entity_nudge');
295                                 $nf = new NudgeForm($this->out, $this->user);
296                                 $nf->show();
297                                 $this->out->elementEnd('li');
298                             }
299                         }
300
301                         // return-to args, so we don't have to keep re-writing them
302
303                         list($action, $r2args) = $this->out->returnToArgs();
304
305                         // push the action into the list
306
307                         $r2args['action'] = $action;
308
309                         // block/unblock
310
311                         $blocked = $cur->hasBlocked($this->profile);
312                         $this->out->elementStart('li', 'entity_block');
313                         if ($blocked) {
314                             $ubf = new UnblockForm($this->out, $this->profile, $r2args);
315                             $ubf->show();
316                         } else {
317                             $bf = new BlockForm($this->out, $this->profile, $r2args);
318                             $bf->show();
319                         }
320                         $this->out->elementEnd('li');
321
322                         if ($cur->hasRight(Right::SANDBOXUSER) ||
323                             $cur->hasRight(Right::SILENCEUSER) ||
324                             $cur->hasRight(Right::DELETEUSER)) {
325                             $this->out->elementStart('li', 'entity_moderation');
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->user->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->user->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 ($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 ($cur->hasRight(Right::GRANTROLE)) {
363                             $this->out->elementStart('li', 'entity_role');
364                             $this->out->element('p', null, _('User role'));
365                             $this->out->elementStart('ul');
366                             $this->roleButton('administrator', _m('role', 'Administrator'));
367                             $this->roleButton('moderator', _m('role', 'Moderator'));
368                             $this->out->elementEnd('ul');
369                             $this->out->elementEnd('li');
370                         }
371                     }
372                 }
373
374                 Event::handle('EndProfilePageActionsElements', array(&$this->out, $this->profile));
375             }
376
377             $this->out->elementEnd('ul');
378             $this->out->elementEnd('div');
379
380             Event::handle('EndProfilePageActionsSection', array(&$this->out, $this->profile));
381         }
382     }
383
384     function roleButton($role, $label)
385     {
386         list($action, $r2args) = $this->out->returnToArgs();
387         $r2args['action'] = $action;
388
389         $this->out->elementStart('li', "entity_role_$role");
390         if ($this->user->hasRole($role)) {
391             $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
392             $rf->show();
393         } else {
394             $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
395             $rf->show();
396         }
397         $this->out->elementEnd('li');
398     }
399
400     function showRemoteSubscribeLink()
401     {
402         $url = common_local_url('remotesubscribe',
403                                 array('nickname' => $this->profile->nickname));
404         $this->out->element('a', array('href' => $url,
405                                   'class' => 'entity_remote_subscribe'),
406                        _('Subscribe'));
407     }
408 }