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