90, 'ImageTplFmt' => '(:include {*$:ImageTemplate} {$FullName}-ImageTemplate {$Group}.ImageTemplate {$SiteGroup}.ImageTemplate:)', 'NoImageTplFmt' => '!! {*$UpFile} %p center% {*$PrevLink} [[{*$FullName}?action=browse | $[Back to gallery] ]] {*$NextLink}\\\\ {*$ImgTagTL} (:title {*$FullName} / {*$UpFile}:)', 'UseTmpl' => 0, 'PurgeRedirectFmt' => '{$PageUrl}?action=upload', 'ImageMagickExe' => '', 'DefaultCLTpl' => 'default', 'fCreateIM'=> 'ThumbCreateIM','fCreateGD'=> 'ThumbCreateGD','fProcessGD'=> '', 'AutoPurgeThumbsDays'=> 0, 'MaxThumbs'=> 3000, 'DirThumbsRatio'=> 3, 'AutoPurgeRatio'=> 0.3, 'AutoPurgeDelay'=> 1800, 'AutoPurgeLock'=> "$WorkDir/.thumblist.lock", 'Sharpen' => 16, )); SDVA($HandleActions, array('imgtpl'=>'HandleImageTemplate', 'purgethumbs'=>"HandlePurgeThumbnails",'createthumb'=>"HandleCreateThumb")); SDVA($HandleAuth, array('purgethumbs' => 'edit', 'imgtpl'=>'read', 'createthumb'=>'read')); SDV($RobotActions['imgtpl'], 1); SDV($RobotActions['createthumb'], 1); function HandleCreateThumb($pagename, $auth="read") { global $UploadDir, $UploadPrefixFmt, $ThumbList; if(!$ThumbList['EnableThumbs'])Abort("Thumbnail creation is disabled."); $fCreate = $ThumbList['ImageMagickExe'] ? $ThumbList['fCreateIM'] : $ThumbList['fCreateGD']; $page = RetrieveAuthPage($pagename,$auth,1, READPAGE_CURRENT);#will ask for pw if needed $uploaddir = FmtPageName("$UploadDir$UploadPrefixFmt", $pagename); $t = $_REQUEST['upname']; $pt = "$uploaddir/$t"; $lock = "$uploaddir/.$t.lock"; if(!file_exists($lock)) { if(file_exists($pt)){HandleDownload($pagename);} else Abort("?Lock file not found."); exit; } ThumbAutoPurge($uploaddir); if(preg_match( "/^th(\\d+)---(?:([0-9a-f]{6}|none)--)?(.+)\\.(jpg|png)$/i", $t, $m ) ) { $f = "$uploaddir/{$m[3]}"; if(!file_exists($f) ) Abort("?Source file $f not found."); $info = @getimagesize($f); list($imgw, $imgh, $t) = $info; $nh = $m[1]; $nw = round($imgw * $nh / $imgh); if(!file_exists($pt) || filemtime($f)>filemtime($pt))#source newer than thumb $fCreate($f,$pt,$imgw,$imgh,$nw,$nh,$t, "#{$m[2]}", @$_REQUEST['imcl']); if(!file_exists($pt)) Abort("Thumbnail $pt was not created for $f."); @unlink($lock); HandleDownload($pagename); exit; } Abort("?Unrecognized format: ThumbList upname='$t'."); } function HandlePurgeThumbnails($pagename, $auth='edit') { RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); global $UploadDir, $UploadPrefixFmt, $ThumbList, $Now; $uploaddir = FmtPageName("$UploadDir$UploadPrefixFmt", $pagename); if ($dirp = @opendir($uploaddir)) { while (($file=readdir($dirp)) !== false) { if (!preg_match("/^(th\\d+---|\\.thumblist)/", $file)) continue; $days = floatval(IsEnabled($_REQUEST['days'], $ThumbList['AutoPurgeThumbsDays'])); if($days>0 && filemtime("$uploaddir/$file")>$Now-$days*86400) continue; unlink("$uploaddir/$file"); } closedir($dirp); } if(@$_REQUEST['redirect']>'')Redirect(MakePageName($pagename, $_REQUEST['redirect'])); else Redirect($pagename, $ThumbList['PurgeRedirectFmt']); } function ThumbCreateGD($filepath,$thumbpath,$imgw,$imgh,$nw,$nh,$t,$bgc,$cl='') { global $ThumbList; if(!isset($ThumbList['ImTypes'][$t])) return; if($bgc == "#none")$bgc="#ffffff";# TODO $rr = hexdec(substr($bgc, 1, 2) ); $gg = hexdec(substr($bgc, 3, 2) ); $bb = hexdec(substr($bgc, 5, 2) ); $gd2 = function_exists('imagecreatetruecolor'); $imcopy = ($gd2)?'imagecopyresampled':'imagecopyresized'; $imcreate=($gd2)?'imagecreatetruecolor':'imagecreate'; $fcreate = "imagecreatefrom".$ThumbList['ImTypes'][$t]; $img = $fcreate($filepath); if (!@$img){return;} $nimg = $imcreate($nw,$nh); if($t != 2)imagefill($nimg, 0, 0, imagecolorallocate($nimg, $rr, $gg, $bb)); $imcopy($nimg,$img,0,0,0,0,$nw,$nh,$imgw,$imgh); imagedestroy($img); if(function_exists('imageconvolution')) { $amount = $ThumbList['Sharpen']; imageconvolution($nimg, array(array(-1,-1,-1),array(-1,$amount,-1),array(-1,-1,-1)),$amount-8,0); } if(function_exists($ThumbList['fProcessGD'])) $nimg = $ThumbList['fProcessGD']($nimg); if(preg_match("/\\.png$/", $thumbpath))imagepng($nimg,$thumbpath,1); else imagejpeg($nimg,$thumbpath,$ThumbList['Quality']); imagedestroy($nimg); } function ThumbCreateIM($filepath,$thumbpath,$imgw,$imgh,$nw,$nh,$t,$bgc,$cl='') { global $ThumbList; if($bgc == "#")$bgc="#ffffff"; if($bgc == "#none")$bgc="none"; $replArr = array( 'x'=>$ThumbList['ImageMagickExe'], 'c'=>$bgc, 'q'=>$ThumbList['Quality'], 'p'=>escapeshellcmd($thumbpath), 'P'=>escapeshellcmd($filepath), 'w'=>$nw, 'W'=>$imgw, 'h'=>$nh, 'H'=>$imgh,); $cl = IsEnabled($ThumbList['IMCLTpl'][$cl], $ThumbList['IMCLTpl'][$ThumbList['DefaultCLTpl']]); foreach($replArr as $k=>$v) { $cl = preg_replace("/\\{%$k\\}/", $v, $cl); if(is_numeric($v)) { $ThumbList['tmp'] = $v; $cl = preg_replace_callback("/\\{%$k([+-]\\d+)\\}/", 'cb_tl_num', $cl); } } $cl = preg_replace_callback("/\\{%RAND([+-]\\d+)([+-]\\d+)([\\*\\/]\\d+)?\\}/", "cb_tl_rand", $cl); $r = exec($cl, $o, $status); if(intval($status)!=0) Abort("convert returned
$r\n".print_r($o, true) ."'with a status '$status'.