'.$text.'';
}
function mkdir_p($dir) {
$basename = dirname($dir);
if (!is_dir($basename)) {
mkdir_p($basename);
}
mkdir($dir);
}
function thumbsize ($src_width, $src_height, $desired_width, $desired_height) {
if ($desired_height) {
$tmp_width = $desired_height * $src_width / $src_height;
if ($desired_width == 0 || $tmp_width <= $desired_width) {
return array ($tmp_width, $desired_height);
}
}
if ($desired_width) {
$tmp_height = $desired_width * $src_height / $src_width;
return array ($desired_width, $tmp_height);
}
// should never reach here
die("Error calculating size");
}
function thumb($path, $image, $width, $height){
global $gallery_path, $use_imagemagick;
$thumb_dir = "thumbs/${width}x${height}/$path";
$thumb = "$thumb_dir/$image";
if(!is_file($thumb) || (filemtime("$path/$image") > filemtime($thumb))){
if ($use_imagemagick) {
$size = getimagesize("$path/$image");
$src_width = $size[0];
$src_height = $size[1];
} else {
if(preg_match("/\.png$/i",$image)){
$src_img = imagecreatefrompng("$path/$image");
}else{
$src_img = imagecreatefromjpeg("$path/$image");
}
$src_width = imagesx($src_img);
$src_height = imagesy($src_img);
}
list($dest_width, $dest_height) = thumbsize($src_width, $src_height, $width, $height);
if ($src_width <= $dest_width && $src_height <= $dest_height) {
return "$gallery_path/$path/$image";
}
if(!is_dir($thumb_dir)) {
mkdir_p($thumb_dir);
}
if ($use_imagemagick) {
//echo "convert -resize ${dest_width}x${dest_height} -filter Lanczos '$path/$image' '$thumb'
";
echo `umask 002; convert -resize ${dest_width}x${dest_height} -filter Lanczos '$path/$image' '$thumb' 2>&1`;
} else {
$dst_img = @imagecreatetruecolor($dest_width,$dest_height);
//$dst_img = imagecreate($dest_width,$dest_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
//imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
if(preg_match("/\.png$/i",$image)){
imagepng($dst_img,$thumb,100);
}else{
imagejpeg($dst_img,$thumb,100);
}
imagedestroy($src_img);
imagedestroy($dst_img);
}
}
return "$gallery_path/$thumb";
}
function alt($comment){
return htmlentities(preg_replace("/(\015\012)|(\015)|(\012)/"," ",$comment));
}
function htmldesc($desc){
$desc = nl2br(htmlentities($desc));
$desc = str_replace("<","<",$desc);
$desc = str_replace(">",">",$desc);
$desc = str_replace(""",'"',$desc);
return $desc;
}
function searchform ($search = "") {
return '
The following images match your query:
\n\n";
do{
$dir = $gallery_path.'/'.$row["dir"];
$img = $row["image"];
$alt = alt(desc($row["dir"],$row["image"],$row["description"]));
$body .= '';
//$body .= '
'.$row["dir"].'
'.$row["image"].'
No images found
"; } return array($title, $body); } function is_gallery_dir ($dir, $file) { return (is_dir("$dir/$file") && !preg_match("/^(\.)|(thumbs$)/",$file)); } function is_gallery_pic ($dir, $file) { return (preg_match("/\.(jpg|jpeg|png)$/i",$file)); } function make_links ($parent, $this_pic, $type) { global $gallery_path, $t_prev, $t_next, $t_up; if ($parent == "") { $parent = "."; } if ($handle = opendir($parent)) { while (false !== ($file = readdir($handle))) { if ($type == "dirs" && is_gallery_dir ($parent, $file) || $type == "files" && is_gallery_pic ($parent, $file)) { $files[] = $file; } } } else { echo "Unable to open $parent!\n"; } if (is_array($files)) { sort($files); $pos = array_search($this_pic, $files); if($prev = $files[$pos - 1]){ $prevlink = a_href(array($gallery_path,$parent,$prev), $t_prev); }else{ $prevlink = $t_prev; } if($next = $files[$pos + 1]){ $nextlink = a_href(array($gallery_path,$parent,$next), $t_next); }else{ $nextlink = $t_next; } } else { $prevlink = $t_prev; $nextlink = $t_next; } if ($parent == "" || $parent == ".") { $up = "$gallery_path/"; } else { $up = "$gallery_path/$parent.html"; } return "$prevlink $t_up $nextlink
"; } function read_file ($file) { if($fd = fopen ($file, "r")){ $data = fread($fd, filesize ($file)); } fclose($fd); return $data; } function desc($path,$image,$desc=""){ if ($desc) { return $desc; } $descfile = "$path/$image.txt"; if (is_file($descfile)) { $desc = read_file($descfile); } if (!$desc) { $desc = $image; } return $desc; } function pretty_name ($dir, $file) { if (is_file("$dir/$file.txt")) { return read_file("$dir/$file.txt"); } return str_replace("_", " ", $file); } function show_dir($show) { global $gallery_path, $use_sql, $main_title, $thumb_width, $thumb_height; $title = $main_title; $body = ""; $open = "."; if ($show) { $show = preg_replace(",/+$,",'', $show); $parent = dirname($show); $this_dir = basename($show); $links = make_links ($parent, $this_dir, "dirs"); $open = $show; $body .= $links; } if ($this_dir) { $title = pretty_name($parent, $this_dir); } if ($handle = opendir($open)) { while(false !== ($file = readdir($handle))){ if (is_gallery_dir($open, $file)) { $dirs[] = $file; } elseif (is_gallery_pic($open, $file)) { $images[] = $file; } } if (is_array($dirs)) { sort($dirs); reset($dirs); $body .= "\n";
foreach($images as $img){
$thumb = thumb($open, $img, $thumb_width, $thumb_height);
$alt = alt(desc($open,$img,$desc[$img]));
$body .= sprintf('',
$gallery_path.'/'.$show.'/'.$img.".html", $thumb, $img, $alt);
if($commented[$img] == 1){
$body .= "*\n";
}else{
$body .= "\n";
}
}
$body .= "
ERROR: Could not open directory '$open'
"; } if ($show) { $body .= $links; } return array($title, $body); } function show_file ($show) { global $gallery_path, $img_width, $img_height; $title = ""; $body = ""; $parent = dirname($show); $dir = './'.$parent; $image = basename($show); $links = make_links ($parent, $image, "files"); $desc = htmldesc(desc($dir, $image)); $smaller_img = thumb($parent, $image, 640, 640); $title = pretty_name($parent, $image); $body .= $links; $body .= sprintf(''."\n%s
\n", $gallery_path.'/'.$show, $smaller_img, $title, $desc); $body .= $links; $body .= comments ($dir, $image); return array($title, $body); } function comments ($dir, $image) { global $use_sql; if (!$use_sql) { return ""; } $text = ""; /* $text .= <| Write a comment: | |
|---|---|
| Nick: | * |
| E-mail: | |
| Webpage: | |
| Comment: | * |
| " /> | |
Written by '.$row["nick"].$row["webpage"].' on '.$row["added"].":
\n".$row["comment"]."
Written by '.$row["nick"].$row["webpage"].":
\n".$row["comment"]."
ERROR: File '$show' not found.
"; } include("header.php"); echo $body; if ($use_sql) { searchform(); } include("footer.php"); ?>