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

avatarbynickname.php 2.17 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php
/*
 * Laconica - a distributed open-source microblogging tool
 * Copyright (C) 2008, Controlez-Vous, Inc.
 *
 * 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/>.
 */

if (!defined('LACONICA')) { exit(1); }

22 23
class AvatarbynicknameAction extends Action
{
24 25
    function handle($args)
    {
Evan Prodromou's avatar
Evan Prodromou committed
26 27 28
        parent::handle($args);
        $nickname = $this->trimmed('nickname');
        if (!$nickname) {
29
            $this->clientError(_('No nickname.'));
30 31 32
            return;
        }
        $size = $this->trimmed('size');
Evan Prodromou's avatar
Evan Prodromou committed
33
        if (!$size) {
34
            $this->clientError(_('No size.'));
35 36 37 38
            return;
        }
        $size = strtolower($size);
        if (!in_array($size, array('original', '96', '48', '24'))) {
39
            $this->clientError(_('Invalid size.'));
40 41
            return;
        }
42

43 44
        $user = User::staticGet('nickname', $nickname);
        if (!$user) {
45
            $this->clientError(_('No such user.'));
46 47 48 49
            return;
        }
        $profile = $user->getProfile();
        if (!$profile) {
50
            $this->clientError(_('User has no profile.'));
51 52 53 54 55 56 57
            return;
        }
        if ($size == 'original') {
            $avatar = $profile->getOriginal();
        } else {
            $avatar = $profile->getAvatar($size+0);
        }
58

59 60 61 62 63 64 65 66 67 68 69
        if ($avatar) {
            $url = $avatar->url;
        } else {
            if ($size == 'original') {
                $url = common_default_avatar(AVATAR_PROFILE_SIZE);
            } else {
                $url = common_default_avatar($size+0);
            }
        }
        common_redirect($url, 302);
    }
Evan Prodromou's avatar
Evan Prodromou committed
70
}