3 * StatusNet, the distributed open-source microblogging tool
5 * Return a user's avatar image
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.
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.
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/>.
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/
30 if (!defined('STATUSNET')) {
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.
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/
44 class ApiUserProfileImageAction extends ApiPrivateAuthAction
47 * Take arguments for running
49 * @param array $args $_REQUEST args
51 * @return boolean success flag
54 protected function prepare(array $args=array())
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);
62 $this->target = $user->getProfile();
63 $this->size = $this->arg('size');
71 * Check the format and show the user info
75 protected function handle()
79 $size = $this->avatarSize();
80 $url = $this->target->avatarUrl($size);
82 // We don't actually output JSON or XML data -- redirect!
83 common_redirect($url, 302);
87 * Get the appropriate pixel size for an avatar based on the request...
91 private function avatarSize()
93 switch ($this->size) {
95 return AVATAR_MINI_SIZE; // 24x24
97 return AVATAR_PROFILE_SIZE; // Twitter does 73x73, but we do 96x96
98 case 'normal': // fall through
100 return AVATAR_STREAM_SIZE; // 48x48
105 * Return true if read only.
109 * @param array $args other arguments
111 * @return boolean is read only action?
113 function isReadOnly($args)