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