if ($allow['show_hilite']) {
$hilite_label = "Highlight";
$hilite_comment = "Highlight for this directory";
if ( ! file_exists($this_hilite) ) {
$this_hilite = "no_hilite.jpg";
$hilite_label = "No highlight";
$hilite_comment = "This directory has no highlight";
}
?>
} // endif show_hilite
$files_array = array();
// Open a known directory, and proceed to read its contents
if (is_dir($thisdir)) {
if ($dh = opendir($thisdir)) {
while (($file = readdir($dh)) !== false) {
$type = filetype("$thisdir/$file");
switch ($type) {
case 'file':
$display = 0;
$extension = pathinfo($file, PATHINFO_EXTENSION);
$extension_lower = strtolower($extension);
if ($extension != $extension_lower) {
# "$extension$" means "string with $extension at the end"
$new_filename = ereg_replace("$extension$", $extension_lower, $file);
# print("DEBUG: filename $file => lower $new_filename \n");
delete_older("$thisdir/$file", "$thisdir/$new_filename");
if (safe_move("$thisdir/$file", "$thisdir/$new_filename")) {
$file = $new_filename;
}
} // endif not lower
if ( preg_match('/[.]thumb[.]/', $file) ) {
# thumbnail
} elseif ( preg_match('/[.]sized[.]/', $file) ) {
# downsized file
} elseif ( preg_match('/^th_/', $file) ) {
# thumbnail
} elseif ( preg_match('/^sm_/', $file) ) {
# downsized file
} elseif ( preg_match('/^[.]/', $file) and (! $allow['show_hidden']) ) {
# begins with a dot
} elseif ( "no_thumb.jpg" == $file ) {
# downsized file
} elseif ( "no_hilite.jpg" == $file ) {
# downsized file
} elseif ( preg_match('/hilite[.](jpg|gif)/', $file) ) {
# highlight or an alternative highlight
} else {
switch ($extension_lower) {
case "jpg":
case "gif":
$display++;
break;
default:
// don't display other extensions
break;
} // end switch extension
} // endif thumbnail
if ($display) {
$files_array[ $file ] = 1; # 1 means file
} else {
# echo "(hide $file) \n";
}
break;
case 'dir':
$display = 0;
if ($file == "." or $file == "..") {
# current or parent dir
} elseif ( preg_match('/^[.]/', $file) and (! $allow['show_hidden']) ) {
# begins with a dot
} else {
$display++;
}
if ($display) {
$files_array[ $file ] = 0; # 0 means dir
} else {
# echo "(hide $file) \n";
}
break;
default:
print("found type '$type' \n");
break;
} // switch filetype
} // next file
closedir($dh);
} // endif opendir
} // endif is_dir
ksort($files_array);
foreach ($files_array as $file => $is_image) {
if ($is_image) {
# file
$class = "image";
$thumb = "$thisdir/th_$file";
$thumb_desc = "th_$file";
$link = "?d=$thisdir&f=$file";
$alt_thumb = "no_thumb.jpg";
$text_file = image_basename($file) . ".txt";
$caption = "$thisdir/$text_file";
$fullsize = "$thisdir/$file";
$comments = "$thisdir/co_$text_file";
$comment_title = "Edit photo comment";
} else {
# dir
$class = "dir";
$thumb = "$thisdir/$file/hilite.jpg";
$thumb_desc = "$file/hilite.jpg";
$link = "?d=$thisdir/$file";
$alt_thumb = "no_hilite.jpg";
$caption = "$thisdir/$file/caption.txt";
$fullsize = "";
$comments = "$thisdir/$file/summary.txt";
$comment_title = "Edit directory summary";
}
if ( ! file_exists($thumb) ) {
if (! $is_image) {
# print("
No auto-thumb for directory
\n");
$class .= " auto_no";
$thumb = $alt_thumb;
} elseif (! fullsize) {
# no fullsize to pull thumbnail from
# print("
\n");
$class .= " auto_error";
$thumb = $alt_thumb;
} else {
# don't change the thumb: it should exist now
$class .= " auto_new";
}
flush();
} # endif fixing thumbnails
}
$file_desc = str_replace("_", " ", $file);
?>
$buttons = 0;
if (($allow['change_hilite']) and ($thumb != $alt_thumb)) {
?>
HILITE
$buttons++;
} // endif change_hilite
if (($allow['redo_thumb']) and ($thumb != $alt_thumb) and ($is_image)) {
?>
REDO
$buttons++;
} // endif redo_thumb
if ($allow['rename_file']) {
?>
RENAME
$buttons++;
} // endif rename_file
if ($allow['move_file']) {
?>
MOVE
$buttons++;
} // endif move_file
if (($allow['delete_file']) and ($is_image)) {
?>
DELETE
$buttons++;
} // endif delete_file
if (($allow['merge_dir']) and (! $is_image)) {
?>
MERGE
$buttons++;
} // endif merge_dir
if ($buttons) { print(" \n"); }
showfile($caption);
if ($allow['edit_file']) {
?>
***
} // endif edit_file
?>
?>
} // next file
} // endif $thefile
function showfile($filename, $alternate_text="") {
if (file_exists($filename)) {
$contents = file_get_contents($filename);
$contents = trim($contents);
$contents = str_replace("\n", " \n", $contents);
print $contents;
} elseif ($alternate_text) {
print $alternate_text;
} else {
print "[" . str_replace("_", " ", $filename) . "]";
}
} // end function showfile
function image_basename($filename) {
$extensions = array(
".GIF",
".gif",
".JPG",
".jpg",
);
$filename = str_replace($extensions, "", $filename);
return $filename;
} // end function image_basename
function delete_older($file1, $file2, $print=0) {
# returns filename that wasn't deleted
$retVal = $file1;
if (! file_exists($file1)) {
if ($print) { print("file1 '$file1' doesn't exist, don't delete \n"); }
$retVal = $file2;
} elseif (! file_exists($file2)) {
if ($print) { print("file2 '$file2' doesn't exist, don't delete \n"); }
$retVal = $file1;
} else {
$mtime1 = filemtime($file1);
$mtime2 = filemtime($file2);
if ($mtime1 < $mtime2) {
if ($print) { print("file1 '$file1' older, deleting \n"); }
unlink($file1);
$retVal = $file2;
} else {
if ($print) { print("file2 '$file2' older, deleting \n"); }
unlink($file2);
$retVal = $file1;
}
}
return $retVal;
} // end function delete_older
function safe_move($file1, $file2, $print=0) {
# returns 1 (true) if file rename succeeded
if (file_exists($file2)) {
if ($print) { print("file2 '$file2' exists, don't rename \n"); }
$retVal = 0;
} elseif (! file_exists($file1)) {
if ($print) { print("file1 '$file1' doesn't exist, don't rename \n"); }
$retVal = 0;
} else {
if ($print) { print("rename($file1, $file2) \n"); }
$retVal = rename($file1, $file2);
# return success value returned by function
}
return $retVal;
} // end function safe_move
function get_all_dirs( $dir = "." ) {
global $allow;
# print("DEBUG: called get_all_dirs($dir) \n");
$retVal = array();
if (is_dir($dir)) {
array_push($retVal, $dir);
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$type = filetype("$dir/$file");
switch ($type) {
case 'file':
// ignore files
break;
case 'dir':
if ($file == "." or $file == "..") {
# current or parent dir
} elseif ( preg_match('/^[.]/', $file) and (! $allow['show_hidden']) ) {
# begins with a dot
} else {
$subfolders = get_all_dirs("$dir/$file");
$retVal = array_merge($retVal, $subfolders);
} // endif parent dir
break;
default:
// ignore other types, if any exist
break;
} // end switch
} // next file
} // endif opendir
} // endif is_dir
sort($retVal);
return $retVal;
} // end function get_all_dirs
// returns only the local portion of the filename, not prepended by directory name
function get_files_in_dir($dir) {
# print("DEBUG: called get_files_in_dir($dir) \n");
$retVal = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file == "." or $file == "..") {
# current or parent dir
} else {
array_push($retVal, $file);
} // endif parent dir
} // next file
} // endif opendir
} // endif is_dir
sort($retVal);
return $retVal;
} // end function get_files_in_dir
?>
Simple Gallery was written by Lord Corwyn Ravenwing.
Bug reports should be sent to the webminister of this website, who will forward them to the author.
IP OPTIONS:
foreach ($allow as $name => $value) {
$status = ($value ? "YES" : "NO");
?>
:
}
?>