We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

accountprofileblock.php 11.8 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
if (!defined('GNUSOCIAL')) { exit(1); }
32

Shashi's avatar
Shashi committed
33
/**
34
 * Profile block to show for an account
Shashi's avatar
Shashi committed
35
 *
36 37 38 39 40 41
 * @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
42
 */
43
class AccountProfileBlock extends ProfileBlock
Shashi's avatar
Shashi committed
44
{
45
    protected $profile = null;
46
    protected $user    = null;
Shashi's avatar
Shashi committed
47

48
    function __construct(Action $out, Profile $profile)
Shashi's avatar
Shashi committed
49
    {
50
        parent::__construct($out);
Shashi's avatar
Shashi committed
51
        $this->profile = $profile;
52 53 54 55 56 57
        try {
            $this->user = $this->profile->getUser();
        } catch (NoSuchUserException $e) {
            // The profile presented is non-local
            assert(!$this->profile->isLocal());
        }
Shashi's avatar
Shashi committed
58 59
    }

60
    function name()
Shashi's avatar
Shashi committed
61
    {
62
        return $this->profile->getBestName();
Shashi's avatar
Shashi committed
63 64
    }

65
    function url()
Shashi's avatar
Shashi committed
66
    {
67
        return $this->profile->profileurl;
Shashi's avatar
Shashi committed
68 69
    }

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

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

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

85 86 87 88 89 90 91 92 93
    function otherProfiles()
    {
        $others = array();

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

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    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();
            }
        }
    }

110
    function showActions()
Shashi's avatar
Shashi committed
111
    {
112
        if (Event::handle('StartProfilePageActionsSection', array($this->out, $this->profile))) {
Shashi Gowda's avatar
Shashi Gowda committed
113

114 115 116 117 118 119 120 121 122 123 124 125
            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
126 127 128 129 130
            }

            $cur = common_current_user();

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

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

167
                        if ($this->profile->isLocal() && $cur->mutuallySubscribed($this->profile)) {
Shashi's avatar
Shashi committed
168 169
                            // nudge

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

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

180 181 182 183 184
                        list($action, $r2args) = $this->out->returnToArgs();

                        // push the action into the list

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

Shashi's avatar
Shashi committed
186 187 188 189 190
                        // block/unblock

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

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

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

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

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

Brion Vibber's avatar
Brion Vibber committed
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 247
                            $this->out->element('p', null, _('User role'));
                            $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 252 253 254
                            $this->roleButton('moderator', _m('role', 'Moderator'));
                            $this->out->elementEnd('ul');
                            $this->out->elementEnd('li');
                        }
Shashi's avatar
Shashi committed
255 256 257
                    }
                }

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

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

264
            Event::handle('EndProfilePageActionsSection', array($this->out, $this->profile));
Shashi's avatar
Shashi committed
265 266 267
        }
    }

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

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

284 285
    function show()
    {
286
        $this->out->elementStart('div', 'profile_block account_profile_block section');
287 288 289 290 291 292
        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
293
}