Improved fetching of remote avatars
authorMarcel Werk <burntime@woltlab.com>
Tue, 25 Apr 2017 15:46:58 +0000 (17:46 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 25 Apr 2017 15:47:28 +0000 (17:47 +0200)
wcfsetup/install/files/lib/data/user/avatar/UserAvatarAction.class.php

index 860ec04ace27dbdb927e1dbfa4e4e2b7a4379535..9c89b31702ba659408e33e3ecb9b3c2003a88241 100644 (file)
@@ -14,6 +14,7 @@ use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\WCF;
 use wcf\util\FileUtil;
 use wcf\util\HTTPRequest;
+use wcf\util\ImageUtil;
 
 /**
  * Executes avatar-related actions.
@@ -189,8 +190,21 @@ class UserAvatarAction extends AbstractDatabaseObjectAction {
                }
                $tmp = pathinfo($tmp['path']);
                if (!isset($tmp['basename']) || !isset($tmp['extension'])) {
-                       @unlink($filename);
-                       return;
+                       if (!isset($tmp['basename'])) {
+                               $tmp['basename'] = basename($filename);
+                       }
+                       
+                       if (!isset($tmp['extension'])) {
+                               $imageData = @getimagesize($filename);
+                               if ($imageData !== false) {
+                                       $tmp['extension'] = ImageUtil::getExtensionByMimeType($imageData['mime']);
+                               }
+                       }
+                       
+                       if (empty($tmp['extension'])) {
+                               @unlink($filename);
+                               return;
+                       }
                }
                
                $data = [