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