]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/avatarbynickname.php
Merge remote-tracking branch 'upstream/master' into social-master
[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('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * Retrieve user avatar by nickname action class.
35  *
36  * @category Action
37  * @package  GNUsocial
38  * @author   Evan Prodromou <evan@status.net>
39  * @author   Robin Millette <millette@status.net>
40  * @author   Mikael Nordfeldth <mmn@hethane.se>
41  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
42  * @link     http://www.gnu.org/software/social/
43  */
44 class AvatarbynicknameAction extends Action
45 {
46     /**
47      * Class handler.
48      *
49      * @param array $args query arguments
50      *
51      * @return boolean false if nickname or user isn't found
52      */
53     protected function handle()
54     {
55         parent::handle();
56         $nickname = $this->trimmed('nickname');
57         if (!$nickname) {
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) {
65             // TRANS: Client error displayed trying to get an avatar for a non-existing user.
66             $this->clientError(_('No such user.'));
67         }
68         $profile = $user->getProfile();
69         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         if ($size === 'original') {
75             try {
76                 $avatar = Avatar::getUploaded($profile);
77                 $url = $avatar->displayUrl();
78             } catch (NoAvatarException $e) {
79                 $url = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
80             }
81         } else {
82             $url = $profile->avatarUrl($size);
83         }
84
85         common_redirect($url, 302);
86     }
87
88     function isReadOnly(array $args=array())
89     {
90         return true;
91     }
92 }