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/
50 class AccountProfileBlock extends ProfileBlock
52 protected $profile = null;
53 protected $user = null;
55 function __construct($out, $profile)
57 parent::__construct($out);
58 $this->profile = $profile;
59 $this->user = User::staticGet('id', $profile->id);
64 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
66 $avatar = $this->profile->getAvatar(73);
68 return (!empty($avatar)) ?
69 $avatar->displayUrl() :
70 Avatar::defaultImage(AVATAR_PROFILE_SIZE);
75 return $this->profile->getBestName();
80 return $this->profile->profileurl;
85 return $this->profile->location;
90 return $this->profile->homepage;
93 function description()
95 return $this->profile->bio;
100 $cur = common_current_user();
102 $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
106 // don't show self-tags again
107 if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
108 $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
114 function showActions()
116 if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
118 if ($this->profile->hasRole(Profile_role::DELETED)) {
119 $this->out->elementStart('div', 'entity_actions');
120 // TRANS: H2 for user actions in a profile.
121 $this->out->element('h2', null, _('User actions'));
122 $this->out->elementStart('ul');
123 $this->out->elementStart('p', array('class' => 'profile_deleted'));
124 // TRANS: Text shown in user profile of not yet compeltely deleted users.
125 $this->out->text(_('User deletion in progress...'));
126 $this->out->elementEnd('p');
127 $this->out->elementEnd('ul');
128 $this->out->elementEnd('div');
132 $cur = common_current_user();
134 $this->out->elementStart('div', 'entity_actions');
135 // TRANS: H2 for entity actions in a profile.
136 $this->out->element('h2', null, _('User actions'));
137 $this->out->elementStart('ul');
139 if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
140 if (empty($cur)) { // not logged in
141 if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
142 $this->out->elementStart('li', 'entity_subscribe');
143 $this->showRemoteSubscribeLink();
144 $this->out->elementEnd('li');
145 Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
148 if ($cur->id == $this->profile->id) { // your own page
149 $this->out->elementStart('li', 'entity_edit');
150 $this->out->element('a', array('href' => common_local_url('profilesettings'),
151 // TRANS: Link title for link on user profile.
152 'title' => _('Edit profile settings')),
153 // TRANS: Link text for link on user profile.
155 $this->out->elementEnd('li');
156 } else { // someone else's page
158 // subscribe/unsubscribe button
160 $this->out->elementStart('li', 'entity_subscribe');
162 if ($cur->isSubscribed($this->profile)) {
163 $usf = new UnsubscribeForm($this->out, $this->profile);
166 $sf = new SubscribeForm($this->out, $this->profile);
169 $this->out->elementEnd('li');
171 if ($cur->mutuallySubscribed($this->profile)) {
175 $this->out->elementStart('li', 'entity_send-a-message');
176 $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
177 // TRANS: Link title for link on user profile.
178 'title' => _('Send a direct message to this user')),
179 // TRANS: Link text for link on user profile.
181 $this->out->elementEnd('li');
185 if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
186 $this->out->elementStart('li', 'entity_nudge');
187 $nf = new NudgeForm($this->out, $this->user);
189 $this->out->elementEnd('li');
193 // return-to args, so we don't have to keep re-writing them
195 list($action, $r2args) = $this->out->returnToArgs();
197 // push the action into the list
199 $r2args['action'] = $action;
203 $blocked = $cur->hasBlocked($this->profile);
204 $this->out->elementStart('li', 'entity_block');
206 $ubf = new UnblockForm($this->out, $this->profile, $r2args);
209 $bf = new BlockForm($this->out, $this->profile, $r2args);
212 $this->out->elementEnd('li');
214 // Some actions won't be applicable to non-local users.
215 $isLocal = !empty($this->user);
217 if ($cur->hasRight(Right::SANDBOXUSER) ||
218 $cur->hasRight(Right::SILENCEUSER) ||
219 $cur->hasRight(Right::DELETEUSER)) {
220 $this->out->elementStart('li', 'entity_moderation');
221 // TRANS: Label text on user profile to select a user role.
222 $this->out->element('p', null, _('Moderate'));
223 $this->out->elementStart('ul');
224 if ($cur->hasRight(Right::SANDBOXUSER)) {
225 $this->out->elementStart('li', 'entity_sandbox');
226 if ($this->profile->isSandboxed()) {
227 $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
230 $sf = new SandboxForm($this->out, $this->profile, $r2args);
233 $this->out->elementEnd('li');
236 if ($cur->hasRight(Right::SILENCEUSER)) {
237 $this->out->elementStart('li', 'entity_silence');
238 if ($this->profile->isSilenced()) {
239 $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
242 $sf = new SilenceForm($this->out, $this->profile, $r2args);
245 $this->out->elementEnd('li');
248 if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
249 $this->out->elementStart('li', 'entity_delete');
250 $df = new DeleteUserForm($this->out, $this->profile, $r2args);
252 $this->out->elementEnd('li');
254 $this->out->elementEnd('ul');
255 $this->out->elementEnd('li');
258 if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
259 $this->out->elementStart('li', 'entity_role');
260 // TRANS: Label text on user profile to select a user role.
261 $this->out->element('p', null, _('User role'));
262 $this->out->elementStart('ul');
263 // TRANS: Role that can be set for a user profile.
264 $this->roleButton('administrator', _m('role', 'Administrator'));
265 // TRANS: Role that can be set for a user profile.
266 $this->roleButton('moderator', _m('role', 'Moderator'));
267 $this->out->elementEnd('ul');
268 $this->out->elementEnd('li');
273 Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
276 $this->out->elementEnd('ul');
277 $this->out->elementEnd('div');
279 Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
283 function roleButton($role, $label)
285 list($action, $r2args) = $this->out->returnToArgs();
286 $r2args['action'] = $action;
288 $this->out->elementStart('li', "entity_role_$role");
289 if ($this->profile->hasRole($role)) {
290 $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
293 $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
296 $this->out->elementEnd('li');
299 function showRemoteSubscribeLink()
301 $url = common_local_url('remotesubscribe',
302 array('nickname' => $this->profile->nickname));
303 $this->out->element('a', array('href' => $url,
304 'class' => 'entity_remote_subscribe'),
305 // TRANS: Link text for link that will subscribe to a remote profile.