]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/userprofile.php
remove extraneous <dl> and <dt> tags
[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             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                 $this->out->elementStart('ul', 'tags xoxo entity_tags');
196                 foreach ($tags as $tag) {
197                     $this->out->elementStart('li');
198                     // Avoid space by using raw output.
199                     $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
200                       common_local_url('peopletag', array('tag' => $tag)) .
201                       '">' . $tag . '</a>';
202                     $this->out->raw($pt);
203                     $this->out->elementEnd('li');
204                 }
205                 $this->out->elementEnd('ul');
206             }
207             Event::handle('EndProfilePageProfileTags', array($this->out, $this->profile));
208         }
209     }
210
211     function showEntityActions()
212     {
213         if ($this->profile->hasRole(Profile_role::DELETED)) {
214             $this->out->elementStart('div', 'entity_actions');
215             $this->out->element('h2', null, _('User actions'));
216             $this->out->elementStart('ul');
217             $this->out->elementStart('p', array('class' => 'profile_deleted'));
218             $this->out->text(_('User deletion in progress...'));
219             $this->out->elementEnd('p');
220             $this->out->elementEnd('ul');
221             $this->out->elementEnd('div');
222             return;
223         }
224         if (Event::handle('StartProfilePageActionsSection', array(&$this->out, $this->profile))) {
225
226             $cur = common_current_user();
227
228             $this->out->elementStart('div', 'entity_actions');
229             $this->out->element('h2', null, _('User actions'));
230             $this->out->elementStart('ul');
231
232             if (Event::handle('StartProfilePageActionsElements', array(&$this->out, $this->profile))) {
233                 if (empty($cur)) { // not logged in
234                     if (Event::handle('StartProfileRemoteSubscribe', array(&$this->out, $this->profile))) {
235                         $this->out->elementStart('li', 'entity_subscribe');
236                         $this->showRemoteSubscribeLink();
237                         $this->out->elementEnd('li');
238                         Event::handle('EndProfileRemoteSubscribe', array(&$this->out, $this->profile));
239                     }
240                 } else {
241                     if ($cur->id == $this->profile->id) { // your own page
242                         $this->out->elementStart('li', 'entity_edit');
243                         $this->out->element('a', array('href' => common_local_url('profilesettings'),
244                                                   'title' => _('Edit profile settings')),
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                                                       'title' => _('Send a direct message to this user')),
269                                            _('Message'));
270                             $this->out->elementEnd('li');
271
272                             // nudge
273
274                             if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
275                                 $this->out->elementStart('li', 'entity_nudge');
276                                 $nf = new NudgeForm($this->out, $this->user);
277                                 $nf->show();
278                                 $this->out->elementEnd('li');
279                             }
280                         }
281
282                         // return-to args, so we don't have to keep re-writing them
283
284                         list($action, $r2args) = $this->out->returnToArgs();
285
286                         // push the action into the list
287
288                         $r2args['action'] = $action;
289
290                         // block/unblock
291
292                         $blocked = $cur->hasBlocked($this->profile);
293                         $this->out->elementStart('li', 'entity_block');
294                         if ($blocked) {
295                             $ubf = new UnblockForm($this->out, $this->profile, $r2args);
296                             $ubf->show();
297                         } else {
298                             $bf = new BlockForm($this->out, $this->profile, $r2args);
299                             $bf->show();
300                         }
301                         $this->out->elementEnd('li');
302
303                         // Some actions won't be applicable to non-local users.
304                         $isLocal = !empty($this->user);
305
306                         if ($cur->hasRight(Right::SANDBOXUSER) ||
307                             $cur->hasRight(Right::SILENCEUSER) ||
308                             $cur->hasRight(Right::DELETEUSER)) {
309                             $this->out->elementStart('li', 'entity_moderation');
310                             $this->out->element('p', null, _('Moderate'));
311                             $this->out->elementStart('ul');
312                             if ($cur->hasRight(Right::SANDBOXUSER)) {
313                                 $this->out->elementStart('li', 'entity_sandbox');
314                                 if ($this->profile->isSandboxed()) {
315                                     $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
316                                     $usf->show();
317                                 } else {
318                                     $sf = new SandboxForm($this->out, $this->profile, $r2args);
319                                     $sf->show();
320                                 }
321                                 $this->out->elementEnd('li');
322                             }
323
324                             if ($cur->hasRight(Right::SILENCEUSER)) {
325                                 $this->out->elementStart('li', 'entity_silence');
326                                 if ($this->profile->isSilenced()) {
327                                     $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
328                                     $usf->show();
329                                 } else {
330                                     $sf = new SilenceForm($this->out, $this->profile, $r2args);
331                                     $sf->show();
332                                 }
333                                 $this->out->elementEnd('li');
334                             }
335
336                             if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
337                                 $this->out->elementStart('li', 'entity_delete');
338                                 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
339                                 $df->show();
340                                 $this->out->elementEnd('li');
341                             }
342                             $this->out->elementEnd('ul');
343                             $this->out->elementEnd('li');
344                         }
345                         
346                         if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
347                             $this->out->elementStart('li', 'entity_role');
348                             $this->out->element('p', null, _('User role'));
349                             $this->out->elementStart('ul');
350                             $this->roleButton('administrator', _m('role', 'Administrator'));
351                             $this->roleButton('moderator', _m('role', 'Moderator'));
352                             $this->out->elementEnd('ul');
353                             $this->out->elementEnd('li');
354                         }
355                     }
356                 }
357
358                 Event::handle('EndProfilePageActionsElements', array(&$this->out, $this->profile));
359             }
360
361             $this->out->elementEnd('ul');
362             $this->out->elementEnd('div');
363
364             Event::handle('EndProfilePageActionsSection', array(&$this->out, $this->profile));
365         }
366     }
367
368     function roleButton($role, $label)
369     {
370         list($action, $r2args) = $this->out->returnToArgs();
371         $r2args['action'] = $action;
372
373         $this->out->elementStart('li', "entity_role_$role");
374         if ($this->profile->hasRole($role)) {
375             $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
376             $rf->show();
377         } else {
378             $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
379             $rf->show();
380         }
381         $this->out->elementEnd('li');
382     }
383
384     function showRemoteSubscribeLink()
385     {
386         $url = common_local_url('remotesubscribe',
387                                 array('nickname' => $this->profile->nickname));
388         $this->out->element('a', array('href' => $url,
389                                   'class' => 'entity_remote_subscribe'),
390                        _('Subscribe'));
391     }
392 }