]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/userprofile.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline 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', '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 (Event::handle('StartProfilePageActionsSection', array(&$this->out, $this->profile))) {
232
233             $cur = common_current_user();
234
235             $this->out->elementStart('div', 'entity_actions');
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                     $this->out->elementStart('li', 'entity_subscribe');
242                     $this->showRemoteSubscribeLink();
243                     $this->out->elementEnd('li');
244                 } else {
245                     if ($cur->id == $this->profile->id) { // your own page
246                         $this->out->elementStart('li', 'entity_edit');
247                         $this->out->element('a', array('href' => common_local_url('profilesettings'),
248                                                   'title' => _('Edit profile settings')),
249                                        _('Edit'));
250                         $this->out->elementEnd('li');
251                     } else { // someone else's page
252
253                         // subscribe/unsubscribe button
254
255                         $this->out->elementStart('li', 'entity_subscribe');
256
257                         if ($cur->isSubscribed($this->profile)) {
258                             $usf = new UnsubscribeForm($this->out, $this->profile);
259                             $usf->show();
260                         } else {
261                             $sf = new SubscribeForm($this->out, $this->profile);
262                             $sf->show();
263                         }
264                         $this->out->elementEnd('li');
265
266                         if ($cur->mutuallySubscribed($this->user)) {
267
268                             // message
269
270                             $this->out->elementStart('li', 'entity_send-a-message');
271                             $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
272                                                       'title' => _('Send a direct message to this user')),
273                                            _('Message'));
274                             $this->out->elementEnd('li');
275
276                             // nudge
277
278                             if ($this->user->email && $this->user->emailnotifynudge) {
279                                 $this->out->elementStart('li', 'entity_nudge');
280                                 $nf = new NudgeForm($this->out, $this->user);
281                                 $nf->show();
282                                 $this->out->elementEnd('li');
283                             }
284                         }
285
286                         // return-to args, so we don't have to keep re-writing them
287
288                         list($action, $r2args) = $this->out->returnToArgs();
289
290                         // push the action into the list
291
292                         $r2args['action'] = $action;
293
294                         // block/unblock
295
296                         $blocked = $cur->hasBlocked($this->profile);
297                         $this->out->elementStart('li', 'entity_block');
298                         if ($blocked) {
299                             $ubf = new UnblockForm($this->out, $this->profile, $r2args);
300                             $ubf->show();
301                         } else {
302                             $bf = new BlockForm($this->out, $this->profile, $r2args);
303                             $bf->show();
304                         }
305                         $this->out->elementEnd('li');
306
307                         if ($cur->hasRight(Right::SANDBOXUSER) ||
308                             $cur->hasRight(Right::SILENCEUSER) ||
309                             $cur->hasRight(Right::DELETEUSER)) {
310                             $this->out->elementStart('li', 'entity_moderation');
311                             $this->out->element('p', null, _('Moderate'));
312                             $this->out->elementStart('ul');
313                             if ($cur->hasRight(Right::SANDBOXUSER)) {
314                                 $this->out->elementStart('li', 'entity_sandbox');
315                                 if ($this->user->isSandboxed()) {
316                                     $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
317                                     $usf->show();
318                                 } else {
319                                     $sf = new SandboxForm($this->out, $this->profile, $r2args);
320                                     $sf->show();
321                                 }
322                                 $this->out->elementEnd('li');
323                             }
324
325                             if ($cur->hasRight(Right::SILENCEUSER)) {
326                                 $this->out->elementStart('li', 'entity_silence');
327                                 if ($this->user->isSilenced()) {
328                                     $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
329                                     $usf->show();
330                                 } else {
331                                     $sf = new SilenceForm($this->out, $this->profile, $r2args);
332                                     $sf->show();
333                                 }
334                                 $this->out->elementEnd('li');
335                             }
336
337                             if ($cur->hasRight(Right::DELETEUSER)) {
338                                 $this->out->elementStart('li', 'entity_delete');
339                                 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
340                                 $df->show();
341                                 $this->out->elementEnd('li');
342                             }
343                             $this->out->elementEnd('ul');
344                             $this->out->elementEnd('li');
345                         }
346                     }
347                 }
348
349                 Event::handle('EndProfilePageActionsElements', array(&$this->out, $this->profile));
350             }
351
352             $this->out->elementEnd('ul');
353             $this->out->elementEnd('div');
354
355             Event::handle('EndProfilePageActionsSection', array(&$this->out, $this->profile));
356         }
357     }
358
359     function showRemoteSubscribeLink()
360     {
361         $url = common_local_url('remotesubscribe',
362                                 array('nickname' => $this->profile->nickname));
363         $this->out->element('a', array('href' => $url,
364                                   'class' => 'entity_remote_subscribe'),
365                        _('Subscribe'));
366     }
367 }