]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apiuserprofileimage.php
Qvitter API changes (thanks hannes2peer)
[quix0rs-gnu-social.git] / actions / apiuserprofileimage.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Return a user's avatar image
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  API
23  * @package   StatusNet
24  * @author    Brion Vibber <brion@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Ouputs avatar URL for a user, specified by screen name.
36  * Unlike most API endpoints, this returns an HTTP redirect rather than direct data.
37  *
38  * @category API
39  * @package  StatusNet
40  * @author   Brion Vibber <brion@status.net>
41  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42  * @link     http://status.net/
43  */
44 class ApiUserProfileImageAction extends ApiPrivateAuthAction
45 {
46     /**
47      * Take arguments for running
48      *
49      * @param array $args $_REQUEST args
50      *
51      * @return boolean success flag
52      *
53      */
54     function prepare($args)
55     {
56         parent::prepare($args);
57         $this->user = User::getKV('nickname', $this->arg('screen_name'));
58         $this->size = $this->arg('size');
59
60         return true;
61     }
62
63     /**
64      * Handle the request
65      *
66      * Check the format and show the user info
67      *
68      * @param array $args $_REQUEST data (unused)
69      *
70      * @return void
71      */
72     function handle($args)
73     {
74         parent::handle($args);
75
76         if (empty($this->user)) {
77             // TRANS: Client error displayed when requesting user information for a non-existing user.
78             $this->clientError(_('User not found.'), 404, $this->format);
79             return;
80         }
81
82         $profile = $this->user->getProfile();
83
84         if (empty($profile)) {
85             // TRANS: Error message displayed when referring to a user without a profile.
86             $this->clientError(_('User has no profile.'));
87             return;
88         }
89
90         $size = $this->avatarSize();
91         $url  = $profile->avatarUrl($size);
92
93         // We don't actually output JSON or XML data -- redirect!
94         common_redirect($url, 302);
95     }
96
97     /**
98      * Get the appropriate pixel size for an avatar based on the request...
99      *
100      * @return int
101      */
102     private function avatarSize()
103     {
104         switch ($this->size) {
105             case 'mini':
106                 return AVATAR_MINI_SIZE; // 24x24
107             case 'bigger':
108                 return AVATAR_PROFILE_SIZE; // Twitter does 73x73, but we do 96x96
109             case 'normal': // fall through
110             default:
111                 return AVATAR_STREAM_SIZE; // 48x48
112         }
113     }
114
115     /**
116      * Return true if read only.
117      *
118      * MAY override
119      *
120      * @param array $args other arguments
121      *
122      * @return boolean is read only action?
123      */
124     function isReadOnly($args)
125     {
126         return true;
127     }
128 }