-
-
Save vrudikov/7591150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* SEOphpthumb | |
* | |
* @category snippet | |
* @version 1.3 | |
* @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html | |
* @author Agel_Nash <Agel_Nash@xaker.ru> | |
*/ | |
if(!defined('MODX_BASE_PATH')){die('What are you doing? Get out of here!');} | |
//[[phpthumb? &input=`[+tvimagename+]` &options=`w_255,h=200`]] | |
if(empty($input) || !file_exists(MODX_BASE_PATH."/".$input)){ | |
$input = (empty($noimage) || !file_exists($noimage)) ? 'assets/snippets/phpthumb/noimage.png' : $noimage; | |
} | |
$options = isset($options) ? $options : ''; | |
$opt = $options; | |
$path_parts=pathinfo($input); | |
require_once MODX_BASE_PATH."/assets/snippets/phpthumb/phpthumb.class.php"; | |
$phpThumb = new phpthumb(); | |
$phpThumb->setSourceFilename($input); | |
$options = explode("&", $options); | |
$setOptions = array(); | |
foreach ($options as $opt) { | |
$opt = explode('=',$opt); | |
$key = str_replace('[]','',$opt[0]); | |
if (!empty($key)) { | |
/* allow arrays of options */ | |
if (isset($setOptions[$key])) { | |
if (is_string($setOptions[$key])) { | |
$setOptions[$key] = array($setOptions[$key]); | |
} | |
$setOptions[$key][] = $opt[1]; | |
} else { /* otherwise pass in as string */ | |
$setOptions[$key] = $opt[1]; | |
} | |
} | |
} | |
if(!isset($setOptions['f'])){ | |
$setOptions['f'] = (in_array(strtolower($path_parts['extension']), array('png','gif'))) ? strtolower($path_parts['extension']) : 'jpg'; | |
} | |
if(!isset($setOptions['q'])){ | |
$setOptions['q'] = 90; | |
} | |
foreach($setOptions as $item=>$value){ | |
$phpThumb->setParameter($item, $value); | |
} | |
$tmp=preg_replace("#^".$_SERVER['DOCUMENT_ROOT']."assets/images/#","",$input); | |
$tmp=preg_replace("#^assets/images/#","",$tmp); | |
$tmp=preg_replace("#/".$path_parts['basename']."$#","",$tmp); | |
$ftime=filemtime(MODX_BASE_PATH.$input); | |
$tmp="assets/cacheimg/".$tmp; | |
$tmp=explode("/",$tmp); | |
$tmp[]=md5(http_build_query($setOptions)); | |
$tmp[]=date("Y-m",$ftime); | |
for($i=0;$i<count($tmp);$i++){ | |
$folder.="/".$tmp[$i]; | |
if(!is_dir(MODX_BASE_PATH.$folder) || !file_exists(MODX_BASE_PATH.$folder)){ | |
mkdir(MODX_BASE_PATH.$folder); | |
} | |
} | |
$outputFilename =MODX_BASE_PATH.$folder."/".date("d_h_i_s",$ftime)."_".$path_parts['extension']."_".$path_parts['filename'].".".$setOptions['f']; | |
if (!file_exists($outputFilename)) if ($phpThumb->GenerateThumbnail()) $phpThumb->RenderToFile($outputFilename) ; | |
$res = explode("/assets", $outputFilename,2); | |
$res = "/assets".$res[1]; | |
return $res; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment