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