]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apiuserprofileimage.php
Merge remote-tracking branch 'upstream/master' into social-master
[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     protected function prepare(array $args=array())
55     {
56         parent::prepare($args);
57         $user = User::getKV('nickname', $this->arg('screen_name'));
58         if (!($user instanceof User)) {
59             // TRANS: Client error displayed when requesting user information for a non-existing user.
60             $this->clientError(_('User not found.'), 404);
61         }
62         $this->target = $user->getProfile();
63         $this->size = $this->arg('size');
64
65         return true;
66     }
67
68     /**
69      * Handle the request
70      *
71      * Check the format and show the user info
72      *
73      * @return void
74      */
75     protected function handle()
76     {
77         parent::handle();
78
79         $size = $this->avatarSize();
80         $url  = $this->target->avatarUrl($size);
81
82         // We don't actually output JSON or XML data -- redirect!
83         common_redirect($url, 302);
84     }
85
86     /**
87      * Get the appropriate pixel size for an avatar based on the request...
88      *
89      * @return int
90      */
91     private function avatarSize()
92     {
93         switch ($this->size) {
94             case 'mini':
95                 return AVATAR_MINI_SIZE; // 24x24
96             case 'bigger':
97                 return AVATAR_PROFILE_SIZE; // Twitter does 73x73, but we do 96x96
98             case 'normal': // fall through
99             default:
100                 return AVATAR_STREAM_SIZE; // 48x48
101         }
102     }
103
104     /**
105      * Return true if read only.
106      *
107      * MAY override
108      *
109      * @param array $args other arguments
110      *
111      * @return boolean is read only action?
112      */
113     function isReadOnly(array $args=array())
114     {
115         return true;
116     }
117 }