diff --git a/classes/class_image_tools.php b/classes/class_image_tools.php index 95dc27c2..cbb908e7 100644 --- a/classes/class_image_tools.php +++ b/classes/class_image_tools.php @@ -4,35 +4,40 @@ * **/ - function to_thumbnail($url) { $thumb = $url; $extension = pathinfo($url, PATHINFO_EXTENSION); - if(contains('whatimg', $url)) { - if($extension == 'jpeg' || $extension == 'jpg') { - $thumb = replace_extension($url, '_thumb.jpg'); - } - if($extension == 'png') { - $thumb = replace_extension($url, '_thumb.png'); - } - if($extension == 'gif') { - $thumb = replace_extension($url, '_thumb.gif'); - } - } - elseif(contains('imgur', $url)) { - if($extension == 'jpeg') { - $thumb = replace_extension($url, 'm.jpeg'); - } - if($extension == 'jpg') { - $thumb = replace_extension($url, 'm.jpg'); - } - if($extension == 'png') { - $thumb = replace_extension($url, 'm.png'); - } - if($extension == 'gif') { - $thumb = replace_extension($url, 'm.gif'); - } - } + if(contains('whatimg', $url)) { + if(hasWhatImgThumb($url)) { + if($extension == 'jpeg') { + $thumb = replace_extension($url, '_thumb.jpeg'); + } + if($extension == 'jpg') { + $thumb = replace_extension($url, '_thumb.jpg'); + } + if($extension == 'png') { + $thumb = replace_extension($url, '_thumb.png'); + } + if($extension == 'gif') { + $thumb = replace_extension($url, '_thumb.gif'); + } + } + } + elseif(contains('imgur', $url)) { + $url = cleanImgurUrl($url); + if($extension == 'jpeg') { + $thumb = replace_extension($url, 'm.jpeg'); + } + if($extension == 'jpg') { + $thumb = replace_extension($url, 'm.jpg'); + } + if($extension == 'png') { + $thumb = replace_extension($url, 'm.png'); + } + if($extension == 'gif') { + $thumb = replace_extension($url, 'm.gif'); + } + } return $thumb; } @@ -44,13 +49,21 @@ function replace_extension($string, $extension) { } function contains($substring, $string) { - $pos = strpos($string, $substring); - if($pos === false) { - return false; - } - else { - return true; - } + return $pos = strpos($string, $substring); +} +function hasWhatImgThumb($url) { + return !contains("_thumb", $url); +} + +function cleanImgurUrl($url) { + $extension = pathinfo($url, PATHINFO_EXTENSION); + $path = preg_replace('/\.[^.]*$/', '', $url); + $last = $path[strlen($path)-1]; + + if($last == 'm' || $last == 'l' || $last == 's' || $last == 'h' || $last == 'b') { + $path = substr($path, 0, -1); + } + return $path . "." . $extension; } ?> diff --git a/sections/artist/artist.php b/sections/artist/artist.php index 3a1146ce..92c3d76a 100644 --- a/sections/artist/artist.php +++ b/sections/artist/artist.php @@ -520,7 +520,7 @@ function compare($X, $Y){