Fixes issue #3612 with Twitter avatars that lack extension

This commit is contained in:
Mikael Nordfeldth 2012-05-24 14:31:42 +02:00
parent cd77348852
commit 4c853f8117

View File

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