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