mirror of
https://github.com/WhatCD/Gazelle.git
synced 2025-01-18 20:21:37 +00:00
Empty commit
This commit is contained in:
parent
9bc4828bce
commit
9f48e0c879
@ -1,73 +1,83 @@
|
||||
<?
|
||||
/**
|
||||
* This class determines the thumbnail equivalent of an image's url after being passed the original
|
||||
* This class determines the thumbnail equivalent of an image's url after being passed the original
|
||||
*
|
||||
**/
|
||||
**/
|
||||
|
||||
/**
|
||||
* The main function, called to get the thumbnail url.
|
||||
*/
|
||||
function to_thumbnail($url) {
|
||||
$thumb = $url;
|
||||
$extension = pathinfo($url, PATHINFO_EXTENSION);
|
||||
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;
|
||||
$thumb = $url;
|
||||
$extension = pathinfo($url, PATHINFO_EXTENSION);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replaces the extension.
|
||||
*/
|
||||
function replace_extension($string, $extension) {
|
||||
$string = preg_replace('/\.[^.]*$/', '', $string);
|
||||
$string = $string . $extension;
|
||||
return $string;
|
||||
$string = preg_replace('/\.[^.]*$/', '', $string);
|
||||
$string = $string . $extension;
|
||||
return $string;
|
||||
}
|
||||
|
||||
function contains($substring, $string) {
|
||||
return $pos = strpos($string, $substring);
|
||||
return $pos = strpos($string, $substring);
|
||||
|
||||
}
|
||||
|
||||
function hasWhatImgThumb($url) {
|
||||
return !contains("_thumb", $url);
|
||||
/**
|
||||
* 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);
|
||||
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;
|
||||
$extension = pathinfo($url, PATHINFO_EXTENSION);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
return $base . "/" . $path . "." . $extension;
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user