]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Use HTTPClient to download avatar
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 18 Jan 2015 01:44:55 +0000 (02:44 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 18 Jan 2015 01:44:55 +0000 (02:44 +0100)
also make updateAvatar public so we can call it from update_ostatus_profile.php

plugins/OStatus/classes/Ostatus_profile.php

index b94950138fd15d8acd8d615f1f4c38de4f66d0a2..9e5e7b64c075620f9e6150159616d5e97e151bcf 100644 (file)
@@ -1233,7 +1233,7 @@ class Ostatus_profile extends Managed_DataObject
      * @param string $url
      * @throws Exception in various failure cases
      */
-    protected function updateAvatar($url)
+    public function updateAvatar($url)
     {
         if ($url == $this->avatar) {
             // We've already got this one.
@@ -1262,10 +1262,15 @@ class Ostatus_profile extends Managed_DataObject
         // ripped from oauthstore.php (for old OMB client)
         $temp_filename = tempnam(sys_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.').':%s', $url, $response->getReasonPhrase()));
             }
+            // FIXME: make sure it's an image here instead of _after_ writing to a file?
+            file_put_contents($response->getBody(), $temp_filename);
 
             if ($this->isGroup()) {
                 $id = $this->group_id;