accountprofileblock.php 12 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 37
    exit(1);
}

/**
38
 * Profile block to show for an account
Shashi's avatar
Shashi committed
39
 *
40 41 42 43 44 45
 * @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
46
 */
47 48

class AccountProfileBlock extends ProfileBlock
Shashi's avatar
Shashi committed
49
{
50
    protected $profile = null;
51
    protected $user    = null;
Shashi's avatar
Shashi committed
52

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

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

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

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

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

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

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

96
    function showActions()
Shashi's avatar
Shashi committed
97
    {
98
        if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
Shashi Gowda's avatar
Shashi Gowda committed
99

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

            $cur = common_current_user();

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

121
            if (Event::handle('StartProfilePageActionsElements', array($this->out, $this->profile))) {
Shashi's avatar
Shashi committed
122
                if (empty($cur)) { // not logged in
123
                    if (Event::handle('StartProfileRemoteSubscribe', array($this->out, $this->profile))) {
124 125 126
                        $this->out->elementStart('li', 'entity_subscribe');
                        $this->showRemoteSubscribeLink();
                        $this->out->elementEnd('li');
127
                        Event::handle('EndProfileRemoteSubscribe', array($this->out, $this->profile));
128
                    }
Shashi's avatar
Shashi committed
129 130 131 132
                } 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'),
133
                                                  // TRANS: Link title for link on user profile.
Shashi's avatar
Shashi committed
134
                                                  'title' => _('Edit profile settings')),
135
                                       // TRANS: Link text for link on user profile.
Shashi's avatar
Shashi committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
                                       _('Edit'));
                        $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();
                        } else {
                            $sf = new SubscribeForm($this->out, $this->profile);
                            $sf->show();
                        }
                        $this->out->elementEnd('li');

153
                        if ($cur->mutuallySubscribed($this->profile)) {
Shashi's avatar
Shashi committed
154 155 156 157 158

                            // message

                            $this->out->elementStart('li', 'entity_send-a-message');
                            $this->out->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)),
159
                                                      // TRANS: Link title for link on user profile.
Shashi's avatar
Shashi committed
160
                                                      'title' => _('Send a direct message to this user')),
161
                                           // TRANS: Link text for link on user profile.
Shashi's avatar
Shashi committed
162 163 164 165 166
                                           _('Message'));
                            $this->out->elementEnd('li');

                            // nudge

167
                            if ($this->user && $this->user->email && $this->user->emailnotifynudge) {
Shashi's avatar
Shashi committed
168 169 170 171 172 173 174
                                $this->out->elementStart('li', 'entity_nudge');
                                $nf = new NudgeForm($this->out, $this->user);
                                $nf->show();
                                $this->out->elementEnd('li');
                            }
                        }

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

177 178 179 180 181
                        list($action, $r2args) = $this->out->returnToArgs();

                        // push the action into the list

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

Shashi's avatar
Shashi committed
183 184 185 186 187
                        // block/unblock

                        $blocked = $cur->hasBlocked($this->profile);
                        $this->out->elementStart('li', 'entity_block');
                        if ($blocked) {
188
                            $ubf = new UnblockForm($this->out, $this->profile, $r2args);
Shashi's avatar
Shashi committed
189 190
                            $ubf->show();
                        } else {
191
                            $bf = new BlockForm($this->out, $this->profile, $r2args);
Shashi's avatar
Shashi committed
192 193 194
                            $bf->show();
                        }
                        $this->out->elementEnd('li');
195

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

199 200 201 202
                        if ($cur->hasRight(Right::SANDBOXUSER) ||
                            $cur->hasRight(Right::SILENCEUSER) ||
                            $cur->hasRight(Right::DELETEUSER)) {
                            $this->out->elementStart('li', 'entity_moderation');
203
                            // TRANS: Label text on user profile to select a user role.
204 205 206 207
                            $this->out->element('p', null, _('Moderate'));
                            $this->out->elementStart('ul');
                            if ($cur->hasRight(Right::SANDBOXUSER)) {
                                $this->out->elementStart('li', 'entity_sandbox');
208
                                if ($this->profile->isSandboxed()) {
209 210 211 212 213 214 215
                                    $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');
216 217
                            }

218 219
                            if ($cur->hasRight(Right::SILENCEUSER)) {
                                $this->out->elementStart('li', 'entity_silence');
220
                                if ($this->profile->isSilenced()) {
221 222 223 224 225 226 227
                                    $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');
228 229
                            }

Brion Vibber's avatar
Brion Vibber committed
230
                            if ($isLocal && $cur->hasRight(Right::DELETEUSER)) {
231 232 233 234 235 236
                                $this->out->elementStart('li', 'entity_delete');
                                $df = new DeleteUserForm($this->out, $this->profile, $r2args);
                                $df->show();
                                $this->out->elementEnd('li');
                            }
                            $this->out->elementEnd('ul');
237 238
                            $this->out->elementEnd('li');
                        }
239

Brion Vibber's avatar
Brion Vibber committed
240
                        if ($isLocal && $cur->hasRight(Right::GRANTROLE)) {
241
                            $this->out->elementStart('li', 'entity_role');
242
                            // TRANS: Label text on user profile to select a user role.
243 244
                            $this->out->element('p', null, _('User role'));
                            $this->out->elementStart('ul');
245
                            // TRANS: Role that can be set for a user profile.
246
                            $this->roleButton('administrator', _m('role', 'Administrator'));
247
                            // TRANS: Role that can be set for a user profile.
248 249 250 251
                            $this->roleButton('moderator', _m('role', 'Moderator'));
                            $this->out->elementEnd('ul');
                            $this->out->elementEnd('li');
                        }
Shashi's avatar
Shashi committed
252 253 254
                    }
                }

255
                Event::handle('EndProfilePageActionsElements', array($this->out, $this->profile));
Shashi's avatar
Shashi committed
256 257 258 259 260
            }

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

261
            Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
Shashi's avatar
Shashi committed
262 263 264
        }
    }

265 266 267 268 269 270
    function roleButton($role, $label)
    {
        list($action, $r2args) = $this->out->returnToArgs();
        $r2args['action'] = $action;

        $this->out->elementStart('li', "entity_role_$role");
271
        if ($this->profile->hasRole($role)) {
272 273 274 275 276 277 278 279 280
            $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');
    }

Shashi's avatar
Shashi committed
281 282 283 284 285 286
    function showRemoteSubscribeLink()
    {
        $url = common_local_url('remotesubscribe',
                                array('nickname' => $this->profile->nickname));
        $this->out->element('a', array('href' => $url,
                                  'class' => 'entity_remote_subscribe'),
287
                       // TRANS: Link text for link that will subscribe to a remote profile.
Shashi's avatar
Shashi committed
288 289 290
                       _('Subscribe'));
    }
}