]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/accountprofileblock.php
Misses this file to merge. I like the comments.
[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(Action $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 name()
67     {
68         return $this->profile->getBestName();
69     }
70
71     function url()
72     {
73         return $this->profile->profileurl;
74     }
75
76     function location()
77     {
78         return $this->profile->location;
79     }
80
81     function homepage()
82     {
83         return $this->profile->homepage;
84     }
85
86     function description()
87     {
88         return $this->profile->bio;
89     }
90
91     function otherProfiles()
92     {
93         $others = array();
94
95         Event::handle('OtherAccountProfiles', array($this->profile, &$others));
96         
97         return $others;
98     }
99
100     function showTags()
101     {
102         $cur = common_current_user();
103
104         $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
105         $self_tags->show();
106
107         if ($cur) {
108             // don't show self-tags again
109             if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
110                 $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
111                 $tags->show();
112             }
113         }
114     }
115
116     function showActions()
117     {
118         if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
119
120             if ($this->profile->hasRole(Profile_role::DELETED)) {
121                 $this->out->elementStart('div', 'entity_actions');
122                 // TRANS: H2 for user actions in a profile.
123                 $this->out->element('h2', null, _('User actions'));
124                 $this->out->elementStart('ul');
125                 $this->out->elementStart('p', array('class' => 'profile_deleted'));
126                 // TRANS: Text shown in user profile of not yet compeltely deleted users.
127                 $this->out->text(_('User deletion in progress...'));
128                 $this->out->elementEnd('p');
129                 $this->out->elementEnd('ul');
130                 $this->out->elementEnd('div');
131                 return;
132             }
133
134             $cur = common_current_user();
135
136             $this->out->elementStart('div', 'entity_actions');
137             // TRANS: H2 for entity actions in a profile.
138             $this->out->element('h2', null, _('User actions'));
139             $this->out->elementStart('ul');
140
141             if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
142                 if (empty($cur)) { // not logged in
143                     if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
144                         Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
145                     }
146                 } else {
147                     if ($cur->id == $this->profile->id) { // your own page
148                         $this->out->elementStart('li', 'entity_edit');
149                         $this->out->element('a', array('href' => common_local_url('profilesettings'),
150                                                   // TRANS: Link title for link on user profile.
151                                                   'title' => _('Edit profile settings.')),
152                                        // TRANS: Link text for link on user profile.
153                                        _m('BUTTON','Edit'));
154                         $this->out->elementEnd('li');
155                     } else { // someone else's page
156
157                         // subscribe/unsubscribe button
158
159                         $this->out->elementStart('li', 'entity_subscribe');
160
161                         if ($cur->isSubscribed($this->profile)) {
162                             $usf = new UnsubscribeForm($this->out, $this->profile);
163                             $usf->show();
164                         } else if ($cur->hasPendingSubscription($this->profile)) {
165                             $sf = new CancelSubscriptionForm($this->out, $this->profile);
166                             $sf->show();
167                         } else {
168                             $sf = new SubscribeForm($this->out, $this->profile);
169                             $sf->show();
170                         }
171                         $this->out->elementEnd('li');
172
173                         if ($this->profile->isLocal() && $cur->mutuallySubscribed($this->profile)) {
174                             // nudge
175
176                             if ($this->user->email && $this->user->emailnotifynudge) {
177                                 $this->out->elementStart('li', 'entity_nudge');
178                                 $nf = new NudgeForm($this->out, $this->user);
179                                 $nf->show();
180                                 $this->out->elementEnd('li');
181                             }
182                         }
183
184                         // return-to args, so we don't have to keep re-writing them
185
186                         list($action, $r2args) = $this->out->returnToArgs();
187
188                         // push the action into the list
189
190                         $r2args['action'] = $action;
191
192                         // block/unblock
193
194                         $blocked = $cur->hasBlocked($this->profile);
195                         $this->out->elementStart('li', 'entity_block');
196                         if ($blocked) {
197                             $ubf = new UnblockForm($this->out, $this->profile, $r2args);
198                             $ubf->show();
199                         } else {
200                             $bf = new BlockForm($this->out, $this->profile, $r2args);
201                             $bf->show();
202                         }
203                         $this->out->elementEnd('li');
204
205                         // Some actions won't be applicable to non-local users.
206                         $isLocal = !empty($this->user);
207
208                         if ($cur->hasRight(Right::SANDBOXUSER) ||
209                             $cur->hasRight(Right::SILENCEUSER) ||
210                             $cur->hasRight(Right::DELETEUSER)) {
211                             $this->out->elementStart('li', 'entity_moderation');
212                             // TRANS: Label text on user profile to select a user role.
213                             $this->out->element('p', null, _('Moderate'));
214                             $this->out->elementStart('ul');
215                             if ($cur->hasRight(Right::SANDBOXUSER)) {
216                                 $this->out->elementStart('li', 'entity_sandbox');
217                                 if ($this->profile->isSandboxed()) {
218                                     $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
219                                     $usf->show();
220                                 } else {
221                                     $sf = new SandboxForm($this->out, $this->profile, $r2args);
222                                     $sf->show();
223                                 }
224                                 $this->out->elementEnd('li');
225                             }
226
227                             if ($cur->hasRight(Right::SILENCEUSER)) {
228                                 $this->out->elementStart('li', 'entity_silence');
229                                 if ($this->profile->isSilenced()) {
230                                     $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
231                                     $usf->show();
232                                 } else {
233                                     $sf = new SilenceForm($this->out, $this->profile, $r2args);
234                                     $sf->show();
235                                 }
236                                 $this->out->elementEnd('li');
237                             }
238
239                             if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
240                                 $this->out->elementStart('li', 'entity_delete');
241                                 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
242                                 $df->show();
243                                 $this->out->elementEnd('li');
244                             }
245                             $this->out->elementEnd('ul');
246                             $this->out->elementEnd('li');
247                         }
248
249                         if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
250                             $this->out->elementStart('li', 'entity_role');
251                             // TRANS: Label text on user profile to select a user role.
252                             $this->out->element('p', null, _('User role'));
253                             $this->out->elementStart('ul');
254                             // TRANS: Role that can be set for a user profile.
255                             $this->roleButton('administrator', _m('role', 'Administrator'));
256                             // TRANS: Role that can be set for a user profile.
257                             $this->roleButton('moderator', _m('role', 'Moderator'));
258                             $this->out->elementEnd('ul');
259                             $this->out->elementEnd('li');
260                         }
261                     }
262                 }
263
264                 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
265             }
266
267             $this->out->elementEnd('ul');
268             $this->out->elementEnd('div');
269
270             Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
271         }
272     }
273
274     function roleButton($role, $label)
275     {
276         list($action, $r2args) = $this->out->returnToArgs();
277         $r2args['action'] = $action;
278
279         $this->out->elementStart('li', "entity_role_$role");
280         if ($this->profile->hasRole($role)) {
281             $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
282             $rf->show();
283         } else {
284             $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
285             $rf->show();
286         }
287         $this->out->elementEnd('li');
288     }
289
290     function show()
291     {
292         $this->out->elementStart('div', 'profile_block account_profile_block section');
293         if (Event::handle('StartShowAccountProfileBlock', array($this->out, $this->profile))) {
294             parent::show();
295             Event::handle('EndShowAccountProfileBlock', array($this->out, $this->profile));
296         }
297         $this->out->elementEnd('div');
298     }
299 }