avatarbynickname.php 3.01 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('STATUSNET') && !defined('LACONICA')) {
Robin Millette's avatar
Robin Millette committed
32 33
    exit(1);
}
Evan Prodromou's avatar
Evan Prodromou committed
34

Robin Millette's avatar
Robin Millette committed
35 36 37 38
/**
 * Retrieve user avatar by nickname action class.
 *
 * @category Action
39
 * @package  StatusNet
40 41
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
42
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
44
 */
45 46
class AvatarbynicknameAction extends Action
{
Robin Millette's avatar
Robin Millette committed
47 48 49 50 51 52 53
    /**
     * Class handler.
     *
     * @param array $args query arguments
     * 
     * @return boolean false if nickname or user isn't found
     */
54 55
    function handle($args)
    {
Evan Prodromou's avatar
Evan Prodromou committed
56 57 58
        parent::handle($args);
        $nickname = $this->trimmed('nickname');
        if (!$nickname) {
59
            $this->clientError(_('No nickname.'));
60 61 62
            return;
        }
        $size = $this->trimmed('size');
Evan Prodromou's avatar
Evan Prodromou committed
63
        if (!$size) {
64
            $this->clientError(_('No size.'));
65 66 67 68
            return;
        }
        $size = strtolower($size);
        if (!in_array($size, array('original', '96', '48', '24'))) {
69
            $this->clientError(_('Invalid size.'));
70 71
            return;
        }
72

73 74
        $user = User::staticGet('nickname', $nickname);
        if (!$user) {
75
            $this->clientError(_('No such user.'));
76 77 78 79
            return;
        }
        $profile = $user->getProfile();
        if (!$profile) {
80
            $this->clientError(_('User has no profile.'));
81 82 83 84 85 86 87
            return;
        }
        if ($size == 'original') {
            $avatar = $profile->getOriginal();
        } else {
            $avatar = $profile->getAvatar($size+0);
        }
88

89 90 91 92
        if ($avatar) {
            $url = $avatar->url;
        } else {
            if ($size == 'original') {
93
                $url = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
94
            } else {
95
                $url = Avatar::defaultImage($size+0);
96 97 98 99
            }
        }
        common_redirect($url, 302);
    }
100

101
    function isReadOnly($args)
102 103 104
    {
        return true;
    }
Evan Prodromou's avatar
Evan Prodromou committed
105
}
Robin Millette's avatar
Robin Millette committed
106