accountprofileblock.php 12.5 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::getKV('id', $profile->id);
Shashi's avatar
Shashi committed
59 60
    }

61
    function avatar()
Shashi's avatar
Shashi committed
62
    {
63
        return $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
Shashi's avatar
Shashi committed
64 65
    }

66
    function name()
Shashi's avatar
Shashi committed
67
    {
68
        return $this->profile->getBestName();
Shashi's avatar
Shashi committed
69 70
    }

71
    function url()
Shashi's avatar
Shashi committed
72
    {
73
        return $this->profile->profileurl;
Shashi's avatar
Shashi committed
74 75
    }

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

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

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

91 92 93 94 95 96 97 98 99
    function otherProfiles()
    {
        $others = array();

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

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    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();
            }
        }
    }

116
    function showActions()
Shashi's avatar
Shashi committed
117
    {
118
        if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
Shashi Gowda's avatar
Shashi Gowda committed
119

120 121 122 123 124 125 126 127 128 129 130 131
            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
132 133 134 135 136
            }

            $cur = common_current_user();

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

141
            if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
Shashi's avatar
Shashi committed
142
                if (empty($cur)) { // not logged in
143 144
                    if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
                        Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
145
                    }
Shashi's avatar
Shashi committed
146 147 148 149
                } 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'),
150
                                                  // TRANS: Link title for link on user profile.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
151
                                                  'title' => _('Edit profile settings.')),
152
                                       // TRANS: Link text for link on user profile.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
153
                                       _m('BUTTON','Edit'));
Shashi's avatar
Shashi committed
154 155 156 157 158 159 160 161 162 163
                        $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();
164 165 166
                        } else if ($cur->hasPendingSubscription($this->profile)) {
                            $sf = new CancelSubscriptionForm($this->out, $this->profile);
                            $sf->show();
Shashi's avatar
Shashi committed
167 168 169 170 171 172
                        } else {
                            $sf = new SubscribeForm($this->out, $this->profile);
                            $sf->show();
                        }
                        $this->out->elementEnd('li');

173
                        if ($cur->mutuallySubscribed($this->profile)) {
Shashi's avatar
Shashi committed
174 175 176 177 178

                            // message

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

                            // nudge

187
                            if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
Shashi's avatar
Shashi committed
188 189 190 191 192 193 194
                                $this->out->elementStart('li', 'entity_nudge');
                                $nf = new NudgeForm($this->out, $this->user);
                                $nf->show();
                                $this->out->elementEnd('li');
                            }
                        }

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

197 198 199 200 201
                        list($action, $r2args) = $this->out->returnToArgs();

                        // push the action into the list

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

Shashi's avatar
Shashi committed
203 204 205 206 207
                        // block/unblock

                        $blocked = $cur->hasBlocked($this->profile);
                        $this->out->elementStart('li', 'entity_block');
                        if ($blocked) {
208
                            $ubf = new UnblockForm($this->out, $this->profile, $r2args);
Shashi's avatar
Shashi committed
209 210
                            $ubf->show();
                        } else {
211
                            $bf = new BlockForm($this->out, $this->profile, $r2args);
Shashi's avatar
Shashi committed
212 213 214
                            $bf->show();
                        }
                        $this->out->elementEnd('li');
215

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

219 220 221 222
                        if ($cur->hasRight(Right::SANDBOXUSER) ||
                            $cur->hasRight(Right::SILENCEUSER) ||
                            $cur->hasRight(Right::DELETEUSER)) {
                            $this->out->elementStart('li', 'entity_moderation');
223
                            // TRANS: Label text on user profile to select a user role.
224 225 226 227
                            $this->out->element('p', null, _('Moderate'));
                            $this->out->elementStart('ul');
                            if ($cur->hasRight(Right::SANDBOXUSER)) {
                                $this->out->elementStart('li', 'entity_sandbox');
228
                                if ($this->profile->isSandboxed()) {
229 230 231 232 233 234 235
                                    $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');
236 237
                            }

238 239
                            if ($cur->hasRight(Right::SILENCEUSER)) {
                                $this->out->elementStart('li', 'entity_silence');
240
                                if ($this->profile->isSilenced()) {
241 242 243 244 245 246 247
                                    $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');
248 249
                            }

Brion Vibber's avatar
Brion Vibber committed
250
                            if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
251 252 253 254 255 256
                                $this->out->elementStart('li', 'entity_delete');
                                $df = new DeleteUserForm($this->out, $this->profile, $r2args);
                                $df->show();
                                $this->out->elementEnd('li');
                            }
                            $this->out->elementEnd('ul');
257 258
                            $this->out->elementEnd('li');
                        }
259

Brion Vibber's avatar
Brion Vibber committed
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 264
                            $this->out->element('p', null, _('User role'));
                            $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 269 270 271
                            $this->roleButton('moderator', _m('role', 'Moderator'));
                            $this->out->elementEnd('ul');
                            $this->out->elementEnd('li');
                        }
Shashi's avatar
Shashi committed
272 273 274
                    }
                }

275
                Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
Shashi's avatar
Shashi committed
276 277 278 279 280
            }

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

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

285 286 287 288 289 290
    function roleButton($role, $label)
    {
        list($action, $r2args) = $this->out->returnToArgs();
        $r2args['action'] = $action;

        $this->out->elementStart('li', "entity_role_$role");
291
        if ($this->profile->hasRole($role)) {
292 293 294 295 296 297 298 299 300
            $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');
    }

301 302
    function show()
    {
303
        $this->out->elementStart('div', 'profile_block account_profile_block section');
304 305 306 307 308 309
        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
310
}