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 function prepare($args)
56 parent::prepare($args);
57 $this->user = User::getKV('nickname', $this->arg('screen_name'));
58 $this->size = $this->arg('size');
66 * Check the format and show the user info
68 * @param array $args $_REQUEST data (unused)
72 function handle($args)
74 parent::handle($args);
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);
82 $profile = $this->user->getProfile();
84 if (empty($profile)) {
85 // TRANS: Error message displayed when referring to a user without a profile.
86 $this->clientError(_('User has no profile.'));
90 $size = $this->avatarSize();
91 $url = $profile->avatarUrl($size);
93 // We don't actually output JSON or XML data -- redirect!
94 common_redirect($url, 302);
98 * Get the appropriate pixel size for an avatar based on the request...
102 private function avatarSize()
104 switch ($this->size) {
106 return AVATAR_MINI_SIZE; // 24x24
108 return AVATAR_PROFILE_SIZE; // Twitter does 73x73, but we do 96x96
109 case 'normal': // fall through
111 return AVATAR_STREAM_SIZE; // 48x48
116 * Return true if read only.
120 * @param array $args other arguments
122 * @return boolean is read only action?
124 function isReadOnly($args)