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(HTMLOutputter $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->avatarUrl(AVATAR_PROFILE_SIZE);
73 return $this->profile->getBestName();
78 return $this->profile->profileurl;
83 return $this->profile->location;
88 return $this->profile->homepage;
91 function description()
93 return $this->profile->bio;
96 function otherProfiles()
100 Event::handle('OtherAccountProfiles', array($this->profile, &$others));
107 $cur = common_current_user();
109 $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
113 // don't show self-tags again
114 if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
115 $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
121 function showActions()
123 if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
125 if ($this->profile->hasRole(Profile_role::DELETED)) {
126 $this->out->elementStart('div', 'entity_actions');
127 // TRANS: H2 for user actions in a profile.
128 $this->out->element('h2', null, _('User actions'));
129 $this->out->elementStart('ul');
130 $this->out->elementStart('p', array('class' => 'profile_deleted'));
131 // TRANS: Text shown in user profile of not yet compeltely deleted users.
132 $this->out->text(_('User deletion in progress...'));
133 $this->out->elementEnd('p');
134 $this->out->elementEnd('ul');
135 $this->out->elementEnd('div');
139 $cur = common_current_user();
141 $this->out->elementStart('div', 'entity_actions');
142 // TRANS: H2 for entity actions in a profile.
143 $this->out->element('h2', null, _('User actions'));
144 $this->out->elementStart('ul');
146 if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
147 if (empty($cur)) { // not logged in
148 if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
149 Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
152 if ($cur->id == $this->profile->id) { // your own page
153 $this->out->elementStart('li', 'entity_edit');
154 $this->out->element('a', array('href' => common_local_url('profilesettings'),
155 // TRANS: Link title for link on user profile.
156 'title' => _('Edit profile settings.')),
157 // TRANS: Link text for link on user profile.
158 _m('BUTTON','Edit'));
159 $this->out->elementEnd('li');
160 } else { // someone else's page
162 // subscribe/unsubscribe button
164 $this->out->elementStart('li', 'entity_subscribe');
166 if ($cur->isSubscribed($this->profile)) {
167 $usf = new UnsubscribeForm($this->out, $this->profile);
169 } else if ($cur->hasPendingSubscription($this->profile)) {
170 $sf = new CancelSubscriptionForm($this->out, $this->profile);
173 $sf = new SubscribeForm($this->out, $this->profile);
176 $this->out->elementEnd('li');
178 if ($this->profile->isLocal() && $cur->mutuallySubscribed($this->profile)) {
182 $this->out->elementStart('li', 'entity_send-a-message');
183 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
184 // TRANS: Link title for link on user profile.
185 'title' => _('Send a direct message to this user.')),
186 // TRANS: Link text for link on user profile.
187 _m('BUTTON','Message'));
188 $this->out->elementEnd('li');
192 if ($this->user->email && $this->user->emailnotifynudge) {
193 $this->out->elementStart('li', 'entity_nudge');
194 $nf = new NudgeForm($this->out, $this->user);
196 $this->out->elementEnd('li');
200 // return-to args, so we don't have to keep re-writing them
202 list($action, $r2args) = $this->out->returnToArgs();
204 // push the action into the list
206 $r2args['action'] = $action;
210 $blocked = $cur->hasBlocked($this->profile);
211 $this->out->elementStart('li', 'entity_block');
213 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
216 $bf = new BlockForm($this->out, $this->profile, $r2args);
219 $this->out->elementEnd('li');
221 // Some actions won't be applicable to non-local users.
222 $isLocal = !empty($this->user);
224 if ($cur->hasRight(Right::SANDBOXUSER) ||
225 $cur->hasRight(Right::SILENCEUSER) ||
226 $cur->hasRight(Right::DELETEUSER)) {
227 $this->out->elementStart('li', 'entity_moderation');
228 // TRANS: Label text on user profile to select a user role.
229 $this->out->element('p', null, _('Moderate'));
230 $this->out->elementStart('ul');
231 if ($cur->hasRight(Right::SANDBOXUSER)) {
232 $this->out->elementStart('li', 'entity_sandbox');
233 if ($this->profile->isSandboxed()) {
234 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
237 $sf = new SandboxForm($this->out, $this->profile, $r2args);
240 $this->out->elementEnd('li');
243 if ($cur->hasRight(Right::SILENCEUSER)) {
244 $this->out->elementStart('li', 'entity_silence');
245 if ($this->profile->isSilenced()) {
246 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
249 $sf = new SilenceForm($this->out, $this->profile, $r2args);
252 $this->out->elementEnd('li');
255 if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
256 $this->out->elementStart('li', 'entity_delete');
257 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
259 $this->out->elementEnd('li');
261 $this->out->elementEnd('ul');
262 $this->out->elementEnd('li');
265 if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
266 $this->out->elementStart('li', 'entity_role');
267 // TRANS: Label text on user profile to select a user role.
268 $this->out->element('p', null, _('User role'));
269 $this->out->elementStart('ul');
270 // TRANS: Role that can be set for a user profile.
271 $this->roleButton('administrator', _m('role', 'Administrator'));
272 // TRANS: Role that can be set for a user profile.
273 $this->roleButton('moderator', _m('role', 'Moderator'));
274 $this->out->elementEnd('ul');
275 $this->out->elementEnd('li');
280 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
283 $this->out->elementEnd('ul');
284 $this->out->elementEnd('div');
286 Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
290 function roleButton($role, $label)
292 list($action, $r2args) = $this->out->returnToArgs();
293 $r2args['action'] = $action;
295 $this->out->elementStart('li', "entity_role_$role");
296 if ($this->profile->hasRole($role)) {
297 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
300 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
303 $this->out->elementEnd('li');
308 $this->out->elementStart('div', 'profile_block account_profile_block section');
309 if (Event::handle('StartShowAccountProfileBlock', array($this->out, $this->profile))) {
311 Event::handle('EndShowAccountProfileBlock', array($this->out, $this->profile));
313 $this->out->elementEnd('div');