*
* @return void
*/
- function handle(array $args=array())
- protected function handle()
++ protected function handle(array $args=array())
{
- parent::handle();
+ parent::handle($args);
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400, $this->format
- );
- }
-
// Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini
// @todo FIXME: This should be better encapsulated
// ripped from oauthstore.php (for old OMB client)
- $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
+ $temp_filename = tempnam(common_get_temp_dir(), 'listener_avatar');
try {
- if (!copy($url, $temp_filename)) {
+ $client = new HTTPClient();
+ $response = $client->get($url);
+
+ if (!$response->isOk()) {
// TRANS: Server exception. %s is a URL.
- throw new ServerException(sprintf(_m('Unable to fetch avatar from %s.'), $url));
+ throw new ServerException(sprintf(_m('Unable to fetch avatar from %s to %s.'), $url, $temp_filename));
}
+ // FIXME: make sure it's an image here instead of _after_ writing to a file?
+ file_put_contents($temp_filename, $response->getBody());
if ($this->isGroup()) {
$id = $this->group_id;