]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/avatarbynickname.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / actions / avatarbynickname.php
1 <?php
2 /**
3  * Retrieve user avatar by nickname action class.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://status.net/
13  *
14  * StatusNet - the distributed open-source microblogging tool
15  * Copyright (C) 2008, 2009, StatusNet, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * Retrieve user avatar by nickname action class.
37  *
38  * @category Action
39  * @package  StatusNet
40  * @author   Evan Prodromou <evan@status.net>
41  * @author   Robin Millette <millette@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://status.net/
44  */
45 class AvatarbynicknameAction extends Action
46 {
47     /**
48      * Class handler.
49      *
50      * @param array $args query arguments
51      *
52      * @return boolean false if nickname or user isn't found
53      */
54     function handle($args)
55     {
56         parent::handle($args);
57         $nickname = $this->trimmed('nickname');
58         if (!$nickname) {
59             // TRANS: Client error displayed trying to get an avatar without providing a nickname.
60             $this->clientError(_('No nickname.'));
61             return;
62         }
63         $size = $this->trimmed('size');
64         if (!$size) {
65             // TRANS: Client error displayed trying to get an avatar without providing an avatar size.
66             $this->clientError(_('No size.'));
67             return;
68         }
69         $size = strtolower($size);
70         if (!in_array($size, array('original', '96', '48', '24'))) {
71             // TRANS: Client error displayed trying to get an avatar providing an invalid avatar size.
72             $this->clientError(_('Invalid size.'));
73             return;
74         }
75
76         $user = User::staticGet('nickname', $nickname);
77         if (!$user) {
78             // TRANS: Client error displayed trying to get an avatar for a non-existing user.
79             $this->clientError(_('No such user.'));
80             return;
81         }
82         $profile = $user->getProfile();
83         if (!$profile) {
84             // TRANS: Client error displayed trying to get an avatar for a user without a profile.
85             $this->clientError(_('User has no profile.'));
86             return;
87         }
88         if ($size == 'original') {
89             $avatar = $profile->getOriginal();
90         } else {
91             $avatar = $profile->getAvatar($size+0);
92         }
93
94         if ($avatar) {
95             $url = $avatar->url;
96         } else {
97             if ($size == 'original') {
98                 $url = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
99             } else {
100                 $url = Avatar::defaultImage($size+0);
101             }
102         }
103         common_redirect($url, 302);
104     }
105
106     function isReadOnly($args)
107     {
108         return true;
109     }
110 }