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