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