Empty commit

This commit is contained in:
Git 2012-07-03 08:00:15 +00:00
parent 9bc4828bce
commit 9f48e0c879

View File

@ -4,6 +4,9 @@
*
**/
/**
* The main function, called to get the thumbnail url.
*/
function to_thumbnail($url) {
$thumb = $url;
$extension = pathinfo($url, PATHINFO_EXTENSION);
@ -22,8 +25,7 @@ function to_thumbnail($url) {
$thumb = replace_extension($url, '_thumb.gif');
}
}
}
elseif(contains('imgur', $url)) {
} elseif (contains('imgur', $url)) {
$url = cleanImgurUrl($url);
if ($extension == 'jpeg') {
$thumb = replace_extension($url, 'm.jpeg');
@ -41,7 +43,9 @@ function to_thumbnail($url) {
return $thumb;
}
/**
* Replaces the extension.
*/
function replace_extension($string, $extension) {
$string = preg_replace('/\.[^.]*$/', '', $string);
$string = $string . $extension;
@ -50,24 +54,30 @@ function replace_extension($string, $extension) {
function contains($substring, $string) {
return $pos = strpos($string, $substring);
}
/**
* Checks if url points to a whatimg thumbnail.
*/
function hasWhatImgThumb($url) {
return !contains("_thumb", $url);
}
/**
* Cleans up imgur url if it already has a modifier attached to the end of it.
*/
function cleanImgurUrl($url) {
$extension = pathinfo($url, PATHINFO_EXTENSION);
$path = preg_replace('/\.[^.]*$/', '', $url);
$full = preg_replace('/\.[^.]*$/', '', $url);
$base = substr($full, 0, strrpos($full, '/'));
$path = substr($full, strrpos($full, '/') + 1);
if (strlen($path) == 6) {
$last = $path[strlen($path) - 1];
if ($last == 'm' || $last == 'l' || $last == 's' || $last == 'h' || $last == 'b') {
$path = substr($path, 0, -1);
}
}
elseif(strlen($path) == 5) {
$path .= 'm';
}
return $path . "." . $extension;
return $base . "/" . $path . "." . $extension;
}
?>