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.
38 * Profile block to show for an account
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/
48 class AccountProfileBlock extends ProfileBlock
50 protected $profile = null;
51 protected $user = null;
53 function __construct($out, $profile)
55 parent::__construct($out);
56 $this->profile = $profile;
57 $this->user = User::staticGet('id', $profile->id);
62 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
64 $avatar = $this->profile->getAvatar(73);
66 return (!empty($avatar)) ?
67 $avatar->displayUrl() :
68 Avatar::defaultImage(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 showActions()
98 if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
100 if ($this->profile->hasRole(Profile_role::DELETED)) {
101 $this->out->elementStart('div', 'entity_actions');
102 // TRANS: H2 for user actions in a profile.
103 $this->out->element('h2', null, _('User actions'));
104 $this->out->elementStart('ul');
105 $this->out->elementStart('p', array('class' => 'profile_deleted'));
106 // TRANS: Text shown in user profile of not yet compeltely deleted users.
107 $this->out->text(_('User deletion in progress...'));
108 $this->out->elementEnd('p');
109 $this->out->elementEnd('ul');
110 $this->out->elementEnd('div');
114 $cur = common_current_user();
116 $this->out->elementStart('div', 'entity_actions');
117 // TRANS: H2 for entity actions in a profile.
118 $this->out->element('h2', null, _('User actions'));
119 $this->out->elementStart('ul');
121 if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
122 if (empty($cur)) { // not logged in
123 if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
124 $this->out->elementStart('li', 'entity_subscribe');
125 $this->showRemoteSubscribeLink();
126 $this->out->elementEnd('li');
127 Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
130 if ($cur->id == $this->profile->id) { // your own page
131 $this->out->elementStart('li', 'entity_edit');
132 $this->out->element('a', array('href' => common_local_url('profilesettings'),
133 // TRANS: Link title for link on user profile.
134 'title' => _('Edit profile settings')),
135 // TRANS: Link text for link on user profile.
137 $this->out->elementEnd('li');
138 } else { // someone else's page
140 // subscribe/unsubscribe button
142 $this->out->elementStart('li', 'entity_subscribe');
144 if ($cur->isSubscribed($this->profile)) {
145 $usf = new UnsubscribeForm($this->out, $this->profile);
147 } else if ($cur->hasPendingSubscription($this->profile)) {
148 $sf = new CancelSubscriptionForm($this->out, $this->profile);
151 $sf = new SubscribeForm($this->out, $this->profile);
154 $this->out->elementEnd('li');
156 if ($cur->mutuallySubscribed($this->profile)) {
160 $this->out->elementStart('li', 'entity_send-a-message');
161 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
162 // TRANS: Link title for link on user profile.
163 'title' => _('Send a direct message to this user')),
164 // TRANS: Link text for link on user profile.
166 $this->out->elementEnd('li');
170 if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
171 $this->out->elementStart('li', 'entity_nudge');
172 $nf = new NudgeForm($this->out, $this->user);
174 $this->out->elementEnd('li');
178 // return-to args, so we don't have to keep re-writing them
180 list($action, $r2args) = $this->out->returnToArgs();
182 // push the action into the list
184 $r2args['action'] = $action;
188 $blocked = $cur->hasBlocked($this->profile);
189 $this->out->elementStart('li', 'entity_block');
191 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
194 $bf = new BlockForm($this->out, $this->profile, $r2args);
197 $this->out->elementEnd('li');
199 // Some actions won't be applicable to non-local users.
200 $isLocal = !empty($this->user);
202 if ($cur->hasRight(Right::SANDBOXUSER) ||
203 $cur->hasRight(Right::SILENCEUSER) ||
204 $cur->hasRight(Right::DELETEUSER)) {
205 $this->out->elementStart('li', 'entity_moderation');
206 // TRANS: Label text on user profile to select a user role.
207 $this->out->element('p', null, _('Moderate'));
208 $this->out->elementStart('ul');
209 if ($cur->hasRight(Right::SANDBOXUSER)) {
210 $this->out->elementStart('li', 'entity_sandbox');
211 if ($this->profile->isSandboxed()) {
212 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
215 $sf = new SandboxForm($this->out, $this->profile, $r2args);
218 $this->out->elementEnd('li');
221 if ($cur->hasRight(Right::SILENCEUSER)) {
222 $this->out->elementStart('li', 'entity_silence');
223 if ($this->profile->isSilenced()) {
224 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
227 $sf = new SilenceForm($this->out, $this->profile, $r2args);
230 $this->out->elementEnd('li');
233 if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
234 $this->out->elementStart('li', 'entity_delete');
235 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
237 $this->out->elementEnd('li');
239 $this->out->elementEnd('ul');
240 $this->out->elementEnd('li');
243 if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
244 $this->out->elementStart('li', 'entity_role');
245 // TRANS: Label text on user profile to select a user role.
246 $this->out->element('p', null, _('User role'));
247 $this->out->elementStart('ul');
248 // TRANS: Role that can be set for a user profile.
249 $this->roleButton('administrator', _m('role', 'Administrator'));
250 // TRANS: Role that can be set for a user profile.
251 $this->roleButton('moderator', _m('role', 'Moderator'));
252 $this->out->elementEnd('ul');
253 $this->out->elementEnd('li');
258 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
261 $this->out->elementEnd('ul');
262 $this->out->elementEnd('div');
264 Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
268 function roleButton($role, $label)
270 list($action, $r2args) = $this->out->returnToArgs();
271 $r2args['action'] = $action;
273 $this->out->elementStart('li', "entity_role_$role");
274 if ($this->profile->hasRole($role)) {
275 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
278 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
281 $this->out->elementEnd('li');
284 function showRemoteSubscribeLink()
286 $url = common_local_url('remotesubscribe',
287 array('nickname' => $this->profile->nickname));
288 $this->out->element('a', array('href' => $url,
289 'class' => 'entity_remote_subscribe'),
290 // TRANS: Link text for link that will subscribe to a remote profile.