avatarbynickname.php 2.92 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
Robin Millette's avatar
Robin Millette committed
2 3 4 5 6 7
/**
 * Retrieve user avatar by nickname action class.
 *
 * PHP version 5
 *
 * @category Action
8
 * @package  StatusNet
9 10
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
11
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
13
 *
14
 * StatusNet - the distributed open-source microblogging tool
15
 * Copyright (C) 2008, 2009, StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * This program is free software: you can redistribute it and/or modify
 * 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/>.
 */

31
if (!defined('GNUSOCIAL')) { exit(1); }
Evan Prodromou's avatar
Evan Prodromou committed
32

Robin Millette's avatar
Robin Millette committed
33 34 35 36
/**
 * Retrieve user avatar by nickname action class.
 *
 * @category Action
mmn's avatar
mmn committed
37
 * @package  GNUsocial
38 39
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
40
 * @author   Mikael Nordfeldth <mmn@hethane.se>
Robin Millette's avatar
Robin Millette committed
41
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
42
 * @link     http://www.gnu.org/software/social/
Robin Millette's avatar
Robin Millette committed
43
 */
44 45
class AvatarbynicknameAction extends Action
{
Robin Millette's avatar
Robin Millette committed
46 47 48 49
    /**
     * Class handler.
     *
     * @param array $args query arguments
Siebrand Mazeland's avatar
Siebrand Mazeland committed
50
     *
Robin Millette's avatar
Robin Millette committed
51 52
     * @return boolean false if nickname or user isn't found
     */
53
    protected function handle()
54
    {
55
        parent::handle();
Evan Prodromou's avatar
Evan Prodromou committed
56 57
        $nickname = $this->trimmed('nickname');
        if (!$nickname) {
Siebrand Mazeland's avatar
Siebrand Mazeland committed
58
            // TRANS: Client error displayed trying to get an avatar without providing a nickname.
59
            $this->clientError(_('No nickname.'));
60
        }
61
        $size = $this->trimmed('size') ?: 'original';
62

63
        $user = User::getKV('nickname', $nickname);
64
        if (!$user) {
Siebrand Mazeland's avatar
Siebrand Mazeland committed
65
            // TRANS: Client error displayed trying to get an avatar for a non-existing user.
66
            $this->clientError(_('No such user.'));
67 68 69
        }
        $profile = $user->getProfile();
        if (!$profile) {
70
            // TRANS: Error message displayed when referring to a user without a profile.
71
            $this->clientError(_('User has no profile.'));
72
        }
73

74 75
        if ($size === 'original') {
            try {
76
                $avatar = Avatar::getUploaded($profile);
77
                $url = $avatar->displayUrl();
78
            } catch (NoAvatarException $e) {
79
                $url = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
80
            }
81 82
        } else {
            $url = $profile->avatarUrl($size);
83
        }
84

85 86
        common_redirect($url, 302);
    }
87

88
    function isReadOnly($args)
89 90 91
    {
        return true;
    }
Evan Prodromou's avatar
Evan Prodromou committed
92
}