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