3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Profile block to show for an account
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.
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.
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/>.
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/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
37 require_once INSTALLDIR.'/lib/peopletags.php';
40 * Profile block to show for an account
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/
49 class AccountProfileBlock extends ProfileBlock
51 protected $profile = null;
52 protected $user = null;
54 function __construct(Action $out, Profile $profile)
56 parent::__construct($out);
57 $this->profile = $profile;
59 $this->user = $this->profile->getUser();
60 } catch (NoSuchUserException $e) {
61 // The profile presented is non-local
62 assert(!$this->profile->isLocal());
68 return $this->profile->getBestName();
73 return $this->profile->profileurl;
78 return $this->profile->location;
83 return $this->profile->homepage;
86 function description()
88 return $this->profile->bio;
91 function otherProfiles()
95 Event::handle('OtherAccountProfiles', array($this->profile, &$others));
102 $cur = common_current_user();
104 $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
108 // don't show self-tags again
109 if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
110 $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
116 function showActions()
118 if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
120 if ($this->profile->hasRole(Profile_role::DELETED)) {
121 $this->out->elementStart('div', 'entity_actions');
122 // TRANS: H2 for user actions in a profile.
123 $this->out->element('h2', null, _('User actions'));
124 $this->out->elementStart('ul');
125 $this->out->elementStart('p', array('class' => 'profile_deleted'));
126 // TRANS: Text shown in user profile of not yet compeltely deleted users.
127 $this->out->text(_('User deletion in progress...'));
128 $this->out->elementEnd('p');
129 $this->out->elementEnd('ul');
130 $this->out->elementEnd('div');
134 $cur = common_current_user();
136 $this->out->elementStart('div', 'entity_actions');
137 // TRANS: H2 for entity actions in a profile.
138 $this->out->element('h2', null, _('User actions'));
139 $this->out->elementStart('ul');
141 if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
142 if (empty($cur)) { // not logged in
143 if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
144 Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
147 if ($cur->id == $this->profile->id) { // your own page
148 $this->out->elementStart('li', 'entity_edit');
149 $this->out->element('a', array('href' => common_local_url('profilesettings'),
150 // TRANS: Link title for link on user profile.
151 'title' => _('Edit profile settings.')),
152 // TRANS: Link text for link on user profile.
153 _m('BUTTON','Edit'));
154 $this->out->elementEnd('li');
155 } else { // someone else's page
157 // subscribe/unsubscribe button
159 $this->out->elementStart('li', 'entity_subscribe');
161 if ($cur->isSubscribed($this->profile)) {
162 $usf = new UnsubscribeForm($this->out, $this->profile);
164 } else if ($cur->hasPendingSubscription($this->profile)) {
165 $sf = new CancelSubscriptionForm($this->out, $this->profile);
168 $sf = new SubscribeForm($this->out, $this->profile);
171 $this->out->elementEnd('li');
173 if ($this->profile->isLocal() && $cur->mutuallySubscribed($this->profile)) {
177 $this->out->elementStart('li', 'entity_send-a-message');
178 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
179 // TRANS: Link title for link on user profile.
180 'title' => _('Send a direct message to this user.')),
181 // TRANS: Link text for link on user profile.
182 _m('BUTTON','Message'));
183 $this->out->elementEnd('li');
187 if ($this->user->email && $this->user->emailnotifynudge) {
188 $this->out->elementStart('li', 'entity_nudge');
189 $nf = new NudgeForm($this->out, $this->user);
191 $this->out->elementEnd('li');
195 // return-to args, so we don't have to keep re-writing them
197 list($action, $r2args) = $this->out->returnToArgs();
199 // push the action into the list
201 $r2args['action'] = $action;
205 $blocked = $cur->hasBlocked($this->profile);
206 $this->out->elementStart('li', 'entity_block');
208 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
211 $bf = new BlockForm($this->out, $this->profile, $r2args);
214 $this->out->elementEnd('li');
216 // Some actions won't be applicable to non-local users.
217 $isLocal = !empty($this->user);
219 if ($cur->hasRight(Right::SANDBOXUSER) ||
220 $cur->hasRight(Right::SILENCEUSER) ||
221 $cur->hasRight(Right::DELETEUSER)) {
222 $this->out->elementStart('li', 'entity_moderation');
223 // TRANS: Label text on user profile to select a user role.
224 $this->out->element('p', null, _('Moderate'));
225 $this->out->elementStart('ul');
226 if ($cur->hasRight(Right::SANDBOXUSER)) {
227 $this->out->elementStart('li', 'entity_sandbox');
228 if ($this->profile->isSandboxed()) {
229 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
232 $sf = new SandboxForm($this->out, $this->profile, $r2args);
235 $this->out->elementEnd('li');
238 if ($cur->hasRight(Right::SILENCEUSER)) {
239 $this->out->elementStart('li', 'entity_silence');
240 if ($this->profile->isSilenced()) {
241 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
244 $sf = new SilenceForm($this->out, $this->profile, $r2args);
247 $this->out->elementEnd('li');
250 if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
251 $this->out->elementStart('li', 'entity_delete');
252 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
254 $this->out->elementEnd('li');
256 $this->out->elementEnd('ul');
257 $this->out->elementEnd('li');
260 if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
261 $this->out->elementStart('li', 'entity_role');
262 // TRANS: Label text on user profile to select a user role.
263 $this->out->element('p', null, _('User role'));
264 $this->out->elementStart('ul');
265 // TRANS: Role that can be set for a user profile.
266 $this->roleButton('administrator', _m('role', 'Administrator'));
267 // TRANS: Role that can be set for a user profile.
268 $this->roleButton('moderator', _m('role', 'Moderator'));
269 $this->out->elementEnd('ul');
270 $this->out->elementEnd('li');
275 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
278 $this->out->elementEnd('ul');
279 $this->out->elementEnd('div');
281 Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
285 function roleButton($role, $label)
287 list($action, $r2args) = $this->out->returnToArgs();
288 $r2args['action'] = $action;
290 $this->out->elementStart('li', "entity_role_$role");
291 if ($this->profile->hasRole($role)) {
292 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
295 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
298 $this->out->elementEnd('li');
303 $this->out->elementStart('div', 'profile_block account_profile_block section');
304 if (Event::handle('StartShowAccountProfileBlock', array($this->out, $this->profile))) {
306 Event::handle('EndShowAccountProfileBlock', array($this->out, $this->profile));
308 $this->out->elementEnd('div');