]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fixes issue #3612 with Twitter avatars that lack extension
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 24 May 2012 12:31:42 +0000 (14:31 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 24 May 2012 12:31:42 +0000 (14:31 +0200)
plugins/TwitterBridge/twitterimport.php

index 1c362d6fe8fe96e85b1ff8f05dccc9c8101f9d1d..2b8055b1263134e3899420cb1eb9d3455e95671b 100644 (file)
@@ -339,10 +339,7 @@ class TwitterImport
     {
         global $config;
 
-        $path_parts = pathinfo($twitter_user->profile_image_url);
-
-        $newname = 'Twitter_' . $twitter_user->id . '_' .
-            $path_parts['basename'];
+        $newname = 'Twitter_' . $twitter_user->id . '_' . basename($twitter_user->profile_image_url);
 
         $oldname = $profile->getAvatar(48)->filename;
 
@@ -370,15 +367,15 @@ class TwitterImport
 
         $path_parts = pathinfo($twitter_user->profile_image_url);
 
-        $img_root = substr($path_parts['basename'], 0, -11);
-        $ext = $path_parts['extension'];
+        $ext = (isset($path_parts['extension']) ? '.'.$path_parts['extension'] : '');  // some lack extension
+        $img_root = basename($path_parts['basename'], '_normal'.$ext); // cut off extension
         $mediatype = $this->getMediatype($ext);
 
         foreach (array('mini', 'normal', 'bigger') as $size) {
             $url = $path_parts['dirname'] . '/' .
-                $img_root . '_' . $size . ".$ext";
+                $img_root . '_' . $size . $ext;
             $filename = 'Twitter_' . $twitter_user->id . '_' .
-                $img_root . "_$size.$ext";
+                $img_root . '_' . $size . $ext;
 
             $this->updateAvatar($profile->id, $size, $mediatype, $filename);
             $this->fetchAvatar($url, $filename);
@@ -401,10 +398,10 @@ class TwitterImport
         $mediatype = null;
 
         switch (strtolower($ext)) {
-        case 'jpg':
+        case '.jpg':
             $mediatype = 'image/jpg';
             break;
-        case 'gif':
+        case '.gif':
             $mediatype = 'image/gif';
             break;
         default:
@@ -419,16 +416,15 @@ class TwitterImport
         global $config;
 
         $path_parts = pathinfo($user->profile_image_url);
-        $ext = $path_parts['extension'];
-        $end = strlen('_normal' . $ext);
-        $img_root = substr($path_parts['basename'], 0, -($end+1));
+        $ext = (isset($path_parts['extension']) ? '.'.$path_parts['extension'] : '');
+        $img_root = basename($path_parts['basename'], '_normal'.$ext);
         $mediatype = $this->getMediatype($ext);
 
         foreach (array('mini', 'normal', 'bigger') as $size) {
             $url = $path_parts['dirname'] . '/' .
-                $img_root . '_' . $size . ".$ext";
+                $img_root . '_' . $size . $ext;
             $filename = 'Twitter_' . $user->id . '_' .
-                $img_root . "_$size.$ext";
+                $img_root . '_' . $size . $ext;
 
             if ($this->fetchAvatar($url, $filename)) {
                 $this->newAvatar($id, $size, $mediatype, $filename);