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')) {
34 require_once INSTALLDIR . '/lib/apiprivateauth.php';
37 * Ouputs avatar URL for a user, specified by screen name.
38 * Unlike most API endpoints, this returns an HTTP redirect rather than direct data.
42 * @author Brion Vibber <brion@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
46 class ApiUserProfileImageAction extends ApiPrivateAuthAction
49 * Take arguments for running
51 * @param array $args $_REQUEST args
53 * @return boolean success flag
56 function prepare($args)
58 parent::prepare($args);
59 $this->user = User::staticGet('nickname', $this->arg('screen_name'));
60 $this->size = $this->arg('size');
68 * Check the format and show the user info
70 * @param array $args $_REQUEST data (unused)
74 function handle($args)
76 parent::handle($args);
78 if (empty($this->user)) {
79 // TRANS: Client error displayed when requesting user information for a non-existing user.
80 $this->clientError(_('User not found.'), 404, $this->format);
84 $profile = $this->user->getProfile();
86 if (empty($profile)) {
87 // TRANS: Error message displayed when referring to a user without a profile.
88 $this->clientError(_('User has no profile.'));
92 $size = $this->avatarSize();
93 $avatar = $profile->getAvatar($size);
95 $url = $avatar->displayUrl();
97 $url = Avatar::defaultImage($size);
100 // We don't actually output JSON or XML data -- redirect!
101 common_redirect($url, 302);
105 * Get the appropriate pixel size for an avatar based on the request...
109 private function avatarSize()
111 switch ($this->size) {
113 return AVATAR_MINI_SIZE; // 24x24
115 return AVATAR_PROFILE_SIZE; // Twitter does 73x73, but we do 96x96
116 case 'normal': // fall through
118 return AVATAR_STREAM_SIZE; // 48x48
123 * Return true if read only.
127 * @param array $args other arguments
129 * @return boolean is read only action?
131 function isReadOnly($args)