[=', '/\\(:thumb(list)?\\s*(.*?):\\)/ei', "FmtThumbList('$pagename',PSS('$2'),'$1')"); function FmtThumbList($pagename, $args, $list='') { global $UploadDir, $UploadPrefixFmt, $UploadUrlFmt, $AlwaysRedoThumbs,$ThumbTableCols,$PCache, $ThumbBgColor, $TimeFmt, $EnableDirectDownload, $ThumbPx, $ThumbTitleFormat, $ThumbLimit; static $ThumbGalNum = 0; $ThumbGalNum++; $opt = ParseArgs($args); $currentpage = MakePageName($pagename, $pagename); if($list)//usual "thumblist" { if (@$opt[''][0]) $pagename = MakePageName($pagename, $opt[''][0]); } else// "thumb" was used { if (! @$opt[''][0]) return; if(preg_match("!^(.*)\\/([^\\/]+)$!", $opt[''][0], $m) ) { $pagename = MakePageName($pagename, $m[1]); $opt['image'] = $m[2]; } else { $opt['image'] = $opt[''][0]; } } if(!$_POST['preview'] && !$AlwaysRedoThumbs && intval(@$opt['supercache'])) { $output = ThumbGetCache($currentpage, $pagename, $ThumbGalNum); if($output) return '<:block>'. Keep($output); } if (@$opt['ext']) $matchext = '/\\.(' . implode('|', preg_split('/\\W+/', $opt['ext'], -1, PREG_SPLIT_NO_EMPTY)) . ')$/i'; if (@$opt['prefix']) $prefixmatch = '/^' . preg_quote($opt['prefix']) . '/'; $titlefmt =(@$opt['titlefmt'])? $opt['titlefmt'] : $ThumbTitleFormat; if (@$opt['px'] && intval($opt['px']) > 10 ) $Px = intval($opt['px']); else $Px = $ThumbPx; $atarget = (@$opt['target'])? ' target="'.htmlspecialchars($opt['target']).'"' : ''; $thumbcols = isset($opt['cols'])? intval($opt['cols']) : $ThumbTableCols; $caption = @$opt['caption']; $start = intval(@$opt['start']); if(!$start)$start = 1; $limit = isset($opt['limit'])? intval(@$opt['limit']) : $ThumbLimit; $tableattributes = array("border", "cellpadding", "cellspacing", "rules", "style", "bgcolor", "align"); $mytabattr = ""; foreach($tableattributes as $k) { if(isset($opt[$k])) $mytabattr .= " $k=\"".htmlspecialchars($opt[$k])."\""; } $mybgcolor = preg_match("/^#[0-9a-f]{6}$/i", @$opt['bgcolor'])? $opt['bgcolor'] : $ThumbBgColor; $uploaddir = FmtPageName("$UploadDir$UploadPrefixFmt", $pagename); $uploadurl = FmtPageName(IsEnabled($EnableDirectDownload, 1) ? "$UploadUrlFmt$UploadPrefixFmt/" : "\$PageUrl?action=download&upname=", $pagename); $dirp = @opendir($uploaddir); if (!$dirp) return ''; $filelist = array(); while (($file=readdir($dirp)) !== false) { if ($file{0} == '.') continue; if (@$opt['image'] && $file != $opt['image']) continue; if (preg_match("/^th\\d+---/", $file)) continue; if (@$matchext && !preg_match(@$matchext, $file)) continue; if (@$prefixmatch && !preg_match($prefixmatch, $file)) continue; $filelist[$file] = $file; } closedir($dirp); if(!count($filelist) ) return; natcasesort($filelist); if($thumbcols) { $Px4 = $Px+4; $outputstart = ""; if($caption)$outputstart .= ""; $td1 = ""; } else {$td1 = " "; $td2 = '';} $td=0; $i=1; $output = ''; foreach($filelist as $file=>$x) { $filepath = "$uploaddir/$file"; $info = @getimagesize($filepath); if(! $info) continue; if($start>1 && $i<$start) { $i++; continue; } if($limit>0 && $i>=$limit+$start) { break; } $stat = stat($filepath); $replArr = array( "%%" => "%", "%f" => $file, "%w" => $info[0], "%h" => $info[1], "%b" => $stat['size'], "%k" => round($stat['size']/1024), "%t" => strftime($TimeFmt, $stat['mtime']) ); $title = htmlspecialchars(strtr($titlefmt, $replArr)); $name = PUE("$uploadurl$file"); if($thumbcols && $td%$thumbcols == 0)$output .= "\n\n"; if($thumbcols && $info[0] > $info[1]) // w > h { $imgh = round($Px * $info[1] / $info[0]); $imgw = $Px; } else { $imgh = $Px; $imgw = round($Px * $info[0] / $info[1]);} if($imgh>=$info[1])// the picture is not bigger than the thumb, display it { list($imgw, $imgh)= $info; $thumbname = $name; $a1=$a2=""; } else { $thumbprefix = "th$imgh---".substr($mybgcolor, 1). "--"; $thumbpath = "$uploaddir/$thumbprefix$file.jpg"; $thumbname = PUE("$uploadurl$thumbprefix$file.jpg"); if($AlwaysRedoThumbs || !file_exists($thumbpath) || filemtime($thumbpath)<$stat['mtime'] ) { CreateThumb($filepath, $thumbpath, $imgh, $info, $mybgcolor); } $a1 = ""; $a2 = ""; } $output .= "$td1$a1$thumbname$a2$td2\n"; if($thumbcols && $td%$thumbcols == $thumbcols-1)$output .= "\n\n"; $i++;$td++; } if($td%$thumbcols) $output .= "\n\n"; if($thumbcols && $output) { $output = "$outputstart$output\n
$caption
"; $td2 = "
\n"; } if(!$_POST['preview'] && !$AlwaysRedoThumbs && intval(@$opt['supercache'])) ThumbSetCache($currentpage, $pagename, $ThumbGalNum, $output); return '<:block>'. Keep($output); } function CreateThumb($filepath, $thumbpath, $nh, $info, $bgc="#ffff00") { global $ThumbQuality; $rr = hexdec(substr($bgc, 1, 2) ); $gg = hexdec(substr($bgc, 3, 2) ); $bb = hexdec(substr($bgc, 5, 2) ); list($imgw, $imgh, $t) = $info; switch ($t) { case 1: $img = imagecreatefromgif($filepath); break; case 2: $img = imagecreatefromjpeg($filepath); break; case 3: $img = imagecreatefrompng($filepath); break; } if (!@$img) {return;} $nw = round($imgw * $nh / $imgh); $transp = imagecolortransparent($img); if ($transp >= 0 || $t==3)// hacking a transparent image { imagecolortransparent($img, -1); imagecolorset($img, $transp, $rr, $gg, $bb); $img2 = imagecreatetruecolor($imgw,$imgh); $back = imagecolorallocate($img2, $rr, $gg, $bb); imagefill($img2, 0, 0, $back); imagecopy($img2, $img, 0, 0, 0, 0, $imgw, $imgh ); imagedestroy($img); $img = $img2; } $nimg = imagecreatetruecolor($nw,$nh); imagecopyresampled($nimg,$img,0,0,0,0,$nw,$nh,$imgw,$imgh); imagejpeg($nimg,$thumbpath,$ThumbQuality); imagedestroy($nimg); imagedestroy($img); } function PurgeThumbnails($pagename) { global $UploadDir, $UploadPrefixFmt; $page = RetrieveAuthPage($pagename,"edit"); if (!$page) { Abort("?Not enough permissions to purge all thumbs for $UploadPrefixFmt"); return; } $uploaddir = FmtPageName("$UploadDir$UploadPrefixFmt", $pagename); if ($dirp = @opendir($uploaddir)) { while (($file=readdir($dirp)) !== false) { if (!preg_match("/^(th\\d+---|\\.thumblist\\.)/", $file)) continue; unlink("$uploaddir/$file"); } closedir($dirp); } redirect($pagename); } $HandleActions['purgethumbs'] = "PurgeThumbnails"; function ThumbGetCache($currentpage, $uploadpage, $n) { global $UploadDir, $UploadPrefixFmt, $PCache, $MessagesFmt; $ptime = $PCache[$currentpage]['time']; $cachefile = FmtPageName("$UploadDir$UploadPrefixFmt/.thumblist.$currentpage.$n.cache", $uploadpage); if(file_exists($cachefile) && filemtime($cachefile) >= $ptime) { if($handle = @fopen($cachefile, "r")) { $contents = @fread($handle, filesize($cachefile)); fclose($handle); } $MessagesFmt[] = "Got cache for $currentpage, gallery $n
\n"; return @$contents; } else return ""; } function ThumbSetCache($currentpage, $uploadpage, $n, $html) { global $UploadDir, $UploadPrefixFmt, $MessagesFmt; $MessagesFmt[] = "Caching gallery $n for $currentpage
\n"; $cachefile = FmtPageName("$UploadDir$UploadPrefixFmt/.thumblist.$currentpage.$n.cache", $uploadpage); if ($handle = fopen($cachefile, 'w+')) { @fwrite($handle, $html); fclose($handle); } }