]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/accountprofileblock.php
Remote profiles in AccountProfileBlock generated errors
[quix0rs-gnu-social.git] / lib / accountprofileblock.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Profile block to show for an account
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Widget
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 require_once INSTALLDIR.'/lib/peopletags.php';
38
39 /**
40  * Profile block to show for an account
41  *
42  * @category  Widget
43  * @package   StatusNet
44  * @author    Evan Prodromou <evan@status.net>
45  * @copyright 2011 StatusNet, Inc.
46  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47  * @link      http://status.net/
48  */
49 class AccountProfileBlock extends ProfileBlock
50 {
51     protected $profile = null;
52     protected $user    = null;
53
54     function __construct(HTMLOutputter $out, Profile $profile)
55     {
56         parent::__construct($out);
57         $this->profile = $profile;
58         try {
59             $this->user = $this->profile->getUser();
60         } catch (NoSuchUserException $e) {
61             // The profile presented is non-local
62             assert(!$this->profile->isLocal());
63         }
64     }
65
66     function avatar()
67     {
68         return $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
69     }
70
71     function name()
72     {
73         return $this->profile->getBestName();
74     }
75
76     function url()
77     {
78         return $this->profile->profileurl;
79     }
80
81     function location()
82     {
83         return $this->profile->location;
84     }
85
86     function homepage()
87     {
88         return $this->profile->homepage;
89     }
90
91     function description()
92     {
93         return $this->profile->bio;
94     }
95
96     function otherProfiles()
97     {
98         $others = array();
99
100         Event::handle('OtherAccountProfiles', array($this->profile, &$others));
101         
102         return $others;
103     }
104
105     function showTags()
106     {
107         $cur = common_current_user();
108
109         $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
110         $self_tags->show();
111
112         if ($cur) {
113             // don't show self-tags again
114             if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
115                 $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
116                 $tags->show();
117             }
118         }
119     }
120
121     function showActions()
122     {
123         if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
124
125             if ($this->profile->hasRole(Profile_role::DELETED)) {
126                 $this->out->elementStart('div', 'entity_actions');
127                 // TRANS: H2 for user actions in a profile.
128                 $this->out->element('h2', null, _('User actions'));
129                 $this->out->elementStart('ul');
130                 $this->out->elementStart('p', array('class' => 'profile_deleted'));
131                 // TRANS: Text shown in user profile of not yet compeltely deleted users.
132                 $this->out->text(_('User deletion in progress...'));
133                 $this->out->elementEnd('p');
134                 $this->out->elementEnd('ul');
135                 $this->out->elementEnd('div');
136                 return;
137             }
138
139             $cur = common_current_user();
140
141             $this->out->elementStart('div', 'entity_actions');
142             // TRANS: H2 for entity actions in a profile.
143             $this->out->element('h2', null, _('User actions'));
144             $this->out->elementStart('ul');
145
146             if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
147                 if (empty($cur)) { // not logged in
148                     if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
149                         Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
150                     }
151                 } else {
152                     if ($cur->id == $this->profile->id) { // your own page
153                         $this->out->elementStart('li', 'entity_edit');
154                         $this->out->element('a', array('href' => common_local_url('profilesettings'),
155                                                   // TRANS: Link title for link on user profile.
156                                                   'title' => _('Edit profile settings.')),
157                                        // TRANS: Link text for link on user profile.
158                                        _m('BUTTON','Edit'));
159                         $this->out->elementEnd('li');
160                     } else { // someone else's page
161
162                         // subscribe/unsubscribe button
163
164                         $this->out->elementStart('li', 'entity_subscribe');
165
166                         if ($cur->isSubscribed($this->profile)) {
167                             $usf = new UnsubscribeForm($this->out, $this->profile);
168                             $usf->show();
169                         } else if ($cur->hasPendingSubscription($this->profile)) {
170                             $sf = new CancelSubscriptionForm($this->out, $this->profile);
171                             $sf->show();
172                         } else {
173                             $sf = new SubscribeForm($this->out, $this->profile);
174                             $sf->show();
175                         }
176                         $this->out->elementEnd('li');
177
178                         if ($this->profile->isLocal() && $cur->mutuallySubscribed($this->profile)) {
179
180                             // message
181
182                             $this->out->elementStart('li', 'entity_send-a-message');
183                             $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
184                                                       // TRANS: Link title for link on user profile.
185                                                       'title' => _('Send a direct message to this user.')),
186                                            // TRANS: Link text for link on user profile.
187                                            _m('BUTTON','Message'));
188                             $this->out->elementEnd('li');
189
190                             // nudge
191
192                             if ($this->user->email && $this->user->emailnotifynudge) {
193                                 $this->out->elementStart('li', 'entity_nudge');
194                                 $nf = new NudgeForm($this->out, $this->user);
195                                 $nf->show();
196                                 $this->out->elementEnd('li');
197                             }
198                         }
199
200                         // return-to args, so we don't have to keep re-writing them
201
202                         list($action, $r2args) = $this->out->returnToArgs();
203
204                         // push the action into the list
205
206                         $r2args['action'] = $action;
207
208                         // block/unblock
209
210                         $blocked = $cur->hasBlocked($this->profile);
211                         $this->out->elementStart('li', 'entity_block');
212                         if ($blocked) {
213                             $ubf = new UnblockForm($this->out, $this->profile, $r2args);
214                             $ubf->show();
215                         } else {
216                             $bf = new BlockForm($this->out, $this->profile, $r2args);
217                             $bf->show();
218                         }
219                         $this->out->elementEnd('li');
220
221                         // Some actions won't be applicable to non-local users.
222                         $isLocal = !empty($this->user);
223
224                         if ($cur->hasRight(Right::SANDBOXUSER) ||
225                             $cur->hasRight(Right::SILENCEUSER) ||
226                             $cur->hasRight(Right::DELETEUSER)) {
227                             $this->out->elementStart('li', 'entity_moderation');
228                             // TRANS: Label text on user profile to select a user role.
229                             $this->out->element('p', null, _('Moderate'));
230                             $this->out->elementStart('ul');
231                             if ($cur->hasRight(Right::SANDBOXUSER)) {
232                                 $this->out->elementStart('li', 'entity_sandbox');
233                                 if ($this->profile->isSandboxed()) {
234                                     $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
235                                     $usf->show();
236                                 } else {
237                                     $sf = new SandboxForm($this->out, $this->profile, $r2args);
238                                     $sf->show();
239                                 }
240                                 $this->out->elementEnd('li');
241                             }
242
243                             if ($cur->hasRight(Right::SILENCEUSER)) {
244                                 $this->out->elementStart('li', 'entity_silence');
245                                 if ($this->profile->isSilenced()) {
246                                     $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
247                                     $usf->show();
248                                 } else {
249                                     $sf = new SilenceForm($this->out, $this->profile, $r2args);
250                                     $sf->show();
251                                 }
252                                 $this->out->elementEnd('li');
253                             }
254
255                             if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
256                                 $this->out->elementStart('li', 'entity_delete');
257                                 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
258                                 $df->show();
259                                 $this->out->elementEnd('li');
260                             }
261                             $this->out->elementEnd('ul');
262                             $this->out->elementEnd('li');
263                         }
264
265                         if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
266                             $this->out->elementStart('li', 'entity_role');
267                             // TRANS: Label text on user profile to select a user role.
268                             $this->out->element('p', null, _('User role'));
269                             $this->out->elementStart('ul');
270                             // TRANS: Role that can be set for a user profile.
271                             $this->roleButton('administrator', _m('role', 'Administrator'));
272                             // TRANS: Role that can be set for a user profile.
273                             $this->roleButton('moderator', _m('role', 'Moderator'));
274                             $this->out->elementEnd('ul');
275                             $this->out->elementEnd('li');
276                         }
277                     }
278                 }
279
280                 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
281             }
282
283             $this->out->elementEnd('ul');
284             $this->out->elementEnd('div');
285
286             Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
287         }
288     }
289
290     function roleButton($role, $label)
291     {
292         list($action, $r2args) = $this->out->returnToArgs();
293         $r2args['action'] = $action;
294
295         $this->out->elementStart('li', "entity_role_$role");
296         if ($this->profile->hasRole($role)) {
297             $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
298             $rf->show();
299         } else {
300             $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
301             $rf->show();
302         }
303         $this->out->elementEnd('li');
304     }
305
306     function show()
307     {
308         $this->out->elementStart('div', 'profile_block account_profile_block section');
309         if (Event::handle('StartShowAccountProfileBlock', array($this->out, $this->profile))) {
310             parent::show();
311             Event::handle('EndShowAccountProfileBlock', array($this->out, $this->profile));
312         }
313         $this->out->elementEnd('div');
314     }
315 }