accountprofileblock.php 12.7 KB
Newer Older
Shashi's avatar
Shashi committed
1 2
<?php
/**
3 4
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2011, StatusNet, Inc.
Shashi's avatar
Shashi committed
5
 *
6
 * Profile block to show for an account
Shashi's avatar
Shashi committed
7 8 9
 *
 * PHP version 5
 *
10
 * This program is free software: you can redistribute it and/or modify
Shashi's avatar
Shashi committed
11 12 13 14 15 16 17 18 19 20 21 22
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
23
 * @category  Widget
Shashi's avatar
Shashi committed
24 25
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
26 27
 * @copyright 2011 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
Shashi's avatar
Shashi committed
28 29 30
 * @link      http://status.net/
 */

31 32 33
if (!defined('STATUSNET')) {
    // This check helps protect against security problems;
    // your code file can't be executed directly from the web.
Shashi's avatar
Shashi committed
34 35 36
    exit(1);
}

37 38
require_once INSTALLDIR.'/lib/peopletags.php';

Shashi's avatar
Shashi committed
39
/**
40
 * Profile block to show for an account
Shashi's avatar
Shashi committed
41
 *
42 43 44 45 46 47
 * @category  Widget
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @copyright 2011 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
 * @link      http://status.net/
Shashi's avatar
Shashi committed
48
 */
49
class AccountProfileBlock extends ProfileBlock
Shashi's avatar
Shashi committed
50
{
51
    protected $profile = null;
52
    protected $user    = null;
Shashi's avatar
Shashi committed
53

54
    function __construct($out, $profile)
Shashi's avatar
Shashi committed
55
    {
56
        parent::__construct($out);
Shashi's avatar
Shashi committed
57
        $this->profile = $profile;
58
        $this->user    = User::staticGet('id', $profile->id);
Shashi's avatar
Shashi committed
59 60
    }

61
    function avatar()
Shashi's avatar
Shashi committed
62
    {
63 64 65
        $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
        if (empty($avatar)) {
            $avatar = $this->profile->getAvatar(73);
Shashi's avatar
Shashi committed
66
        }
67 68
        return (!empty($avatar)) ?
            $avatar->displayUrl() :
69
            Avatar::defaultImage(AVATAR_PROFILE_SIZE);
Shashi's avatar
Shashi committed
70 71
    }

72
    function name()
Shashi's avatar
Shashi committed
73
    {
74
        return $this->profile->getBestName();
Shashi's avatar
Shashi committed
75 76
    }

77
    function url()
Shashi's avatar
Shashi committed
78
    {
79
        return $this->profile->profileurl;
Shashi's avatar
Shashi committed
80 81
    }

82
    function location()
Shashi's avatar
Shashi committed
83
    {
84
        return $this->profile->location;
Shashi's avatar
Shashi committed
85 86
    }

87
    function homepage()
Shashi's avatar
Shashi committed
88
    {
89
        return $this->profile->homepage;
Shashi's avatar
Shashi committed
90 91
    }

92
    function description()
Shashi's avatar
Shashi committed
93
    {
94
        return $this->profile->bio;
Shashi's avatar
Shashi committed
95 96
    }

97 98 99 100 101 102 103 104 105
    function otherProfiles()
    {
        $others = array();

        Event::handle('OtherAccountProfiles', array($this->profile, &$others));
        
        return $others;
    }

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    function showTags()
    {
        $cur = common_current_user();

        $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
        $self_tags->show();

        if ($cur) {
            // don't show self-tags again
            if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
                $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
                $tags->show();
            }
        }
    }

122
    function showActions()
Shashi's avatar
Shashi committed
123
    {
124
        if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
Shashi Gowda's avatar
Shashi Gowda committed
125

126 127 128 129 130 131 132 133 134 135 136 137
            if ($this->profile->hasRole(Profile_role::DELETED)) {
                $this->out->elementStart('div', 'entity_actions');
                // TRANS: H2 for user actions in a profile.
                $this->out->element('h2', null, _('User actions'));
                $this->out->elementStart('ul');
                $this->out->elementStart('p', array('class' => 'profile_deleted'));
                // TRANS: Text shown in user profile of not yet compeltely deleted users.
                $this->out->text(_('User deletion in progress...'));
                $this->out->elementEnd('p');
                $this->out->elementEnd('ul');
                $this->out->elementEnd('div');
                return;
Shashi's avatar
Shashi committed
138 139 140 141 142
            }

            $cur = common_current_user();

            $this->out->elementStart('div', 'entity_actions');
143
            // TRANS: H2 for entity actions in a profile.
Shashi's avatar
Shashi committed
144 145 146
            $this->out->element('h2', null, _('User actions'));
            $this->out->elementStart('ul');

147
            if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
Shashi's avatar
Shashi committed
148
                if (empty($cur)) { // not logged in
149 150
                    if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
                        Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
151
                    }
Shashi's avatar
Shashi committed
152 153 154 155
                } else {
                    if ($cur->id == $this->profile->id) { // your own page
                        $this->out->elementStart('li', 'entity_edit');
                        $this->out->element('a', array('href' => common_local_url('profilesettings'),
156
                                                  // TRANS: Link title for link on user profile.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
157
                                                  'title' => _('Edit profile settings.')),
158
                                       // TRANS: Link text for link on user profile.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
159
                                       _m('BUTTON','Edit'));
Shashi's avatar
Shashi committed
160 161 162 163 164 165 166 167 168 169
                        $this->out->elementEnd('li');
                    } else { // someone else's page

                        // subscribe/unsubscribe button

                        $this->out->elementStart('li', 'entity_subscribe');

                        if ($cur->isSubscribed($this->profile)) {
                            $usf = new UnsubscribeForm($this->out, $this->profile);
                            $usf->show();
170 171 172
                        } else if ($cur->hasPendingSubscription($this->profile)) {
                            $sf = new CancelSubscriptionForm($this->out, $this->profile);
                            $sf->show();
Shashi's avatar
Shashi committed
173 174 175 176 177 178
                        } else {
                            $sf = new SubscribeForm($this->out, $this->profile);
                            $sf->show();
                        }
                        $this->out->elementEnd('li');

179
                        if ($cur->mutuallySubscribed($this->profile)) {
Shashi's avatar
Shashi committed
180 181 182 183 184

                            // message

                            $this->out->elementStart('li', 'entity_send-a-message');
                            $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
185
                                                      // TRANS: Link title for link on user profile.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
186
                                                      'title' => _('Send a direct message to this user.')),
187
                                           // TRANS: Link text for link on user profile.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
188
                                           _m('BUTTON','Message'));
Shashi's avatar
Shashi committed
189 190 191 192
                            $this->out->elementEnd('li');

                            // nudge

193
                            if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
Shashi's avatar
Shashi committed
194 195 196 197 198 199 200
                                $this->out->elementStart('li', 'entity_nudge');
                                $nf = new NudgeForm($this->out, $this->user);
                                $nf->show();
                                $this->out->elementEnd('li');
                            }
                        }

201 202
                        // return-to args, so we don't have to keep re-writing them

203 204 205 206 207
                        list($action, $r2args) = $this->out->returnToArgs();

                        // push the action into the list

                        $r2args['action'] = $action;
208

Shashi's avatar
Shashi committed
209 210 211 212 213
                        // block/unblock

                        $blocked = $cur->hasBlocked($this->profile);
                        $this->out->elementStart('li', 'entity_block');
                        if ($blocked) {
214
                            $ubf = new UnblockForm($this->out, $this->profile, $r2args);
Shashi's avatar
Shashi committed
215 216
                            $ubf->show();
                        } else {
217
                            $bf = new BlockForm($this->out, $this->profile, $r2args);
Shashi's avatar
Shashi committed
218 219 220
                            $bf->show();
                        }
                        $this->out->elementEnd('li');
221

Brion Vibber's avatar
Brion Vibber committed
222 223 224
                        // Some actions won't be applicable to non-local users.
                        $isLocal = !empty($this->user);

225 226 227 228
                        if ($cur->hasRight(Right::SANDBOXUSER) ||
                            $cur->hasRight(Right::SILENCEUSER) ||
                            $cur->hasRight(Right::DELETEUSER)) {
                            $this->out->elementStart('li', 'entity_moderation');
229
                            // TRANS: Label text on user profile to select a user role.
230 231 232 233
                            $this->out->element('p', null, _('Moderate'));
                            $this->out->elementStart('ul');
                            if ($cur->hasRight(Right::SANDBOXUSER)) {
                                $this->out->elementStart('li', 'entity_sandbox');
234
                                if ($this->profile->isSandboxed()) {
235 236 237 238 239 240 241
                                    $usf = new UnSandboxForm($this->out, $this->profile, $r2args);
                                    $usf->show();
                                } else {
                                    $sf = new SandboxForm($this->out, $this->profile, $r2args);
                                    $sf->show();
                                }
                                $this->out->elementEnd('li');
242 243
                            }

244 245
                            if ($cur->hasRight(Right::SILENCEUSER)) {
                                $this->out->elementStart('li', 'entity_silence');
246
                                if ($this->profile->isSilenced()) {
247 248 249 250 251 252 253
                                    $usf = new UnSilenceForm($this->out, $this->profile, $r2args);
                                    $usf->show();
                                } else {
                                    $sf = new SilenceForm($this->out, $this->profile, $r2args);
                                    $sf->show();
                                }
                                $this->out->elementEnd('li');
254 255
                            }

Brion Vibber's avatar
Brion Vibber committed
256
                            if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
257 258 259 260 261 262
                                $this->out->elementStart('li', 'entity_delete');
                                $df = new DeleteUserForm($this->out, $this->profile, $r2args);
                                $df->show();
                                $this->out->elementEnd('li');
                            }
                            $this->out->elementEnd('ul');
263 264
                            $this->out->elementEnd('li');
                        }
265

Brion Vibber's avatar
Brion Vibber committed
266
                        if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
267
                            $this->out->elementStart('li', 'entity_role');
268
                            // TRANS: Label text on user profile to select a user role.
269 270
                            $this->out->element('p', null, _('User role'));
                            $this->out->elementStart('ul');
271
                            // TRANS: Role that can be set for a user profile.
272
                            $this->roleButton('administrator', _m('role', 'Administrator'));
273
                            // TRANS: Role that can be set for a user profile.
274 275 276 277
                            $this->roleButton('moderator', _m('role', 'Moderator'));
                            $this->out->elementEnd('ul');
                            $this->out->elementEnd('li');
                        }
Shashi's avatar
Shashi committed
278 279 280
                    }
                }

281
                Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
Shashi's avatar
Shashi committed
282 283 284 285 286
            }

            $this->out->elementEnd('ul');
            $this->out->elementEnd('div');

287
            Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
Shashi's avatar
Shashi committed
288 289 290
        }
    }

291 292 293 294 295 296
    function roleButton($role, $label)
    {
        list($action, $r2args) = $this->out->returnToArgs();
        $r2args['action'] = $action;

        $this->out->elementStart('li', "entity_role_$role");
297
        if ($this->profile->hasRole($role)) {
298 299 300 301 302 303 304 305 306
            $rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
            $rf->show();
        } else {
            $rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
            $rf->show();
        }
        $this->out->elementEnd('li');
    }

307 308
    function show()
    {
309
        $this->out->elementStart('div', 'profile_block account_profile_block section');
310 311 312 313 314 315
        if (Event::handle('StartShowAccountProfileBlock', array($this->out, $this->profile))) {
            parent::show();
            Event::handle('EndShowAccountProfileBlock', array($this->out, $this->profile));
        }
        $this->out->elementEnd('div');
    }
Shashi's avatar
Shashi committed
316
}