Simple Gallery v0.9.1

"); print_r($ini_array); print(""); $my_ip = $_SERVER['REMOTE_ADDR']; # print("Your IP: $my_ip
\n"); $admin = 0; foreach ($ini_array['admin'] as $label => $ip) { if ($ip == $my_ip) { # print "IP $ip == $my_ip: ADMIN
\n"; print "ADMIN ($ip)
\n"; $admin = 1; } elseif (fnmatch($ip, $my_ip)) { # print "IP $ip match $my_ip
\n"; print "ADMIN ($ip)
\n"; $admin = 1; } else { # print "IP $ip != $my_ip
\n"; } } // next ip $allow = array(); $settings = array(); foreach ($ini_array['allow'] as $action => $value) { # print("DEBUG: action $action value '$value'
\n"); switch($value) { case "ADMIN": // must precede "true" because any string == true $allow[ $action ] = $admin; break; case true: $allow[ $action ] = 1; break; case false: $allow[ $action ] = 0; break; default: // this won't actually happen, either TRUE or FALSE will always match $allow[ $action ] = 0; break; } // end switch value } // next action # could we replace the following with << $settings = $ini_array['settings'] >> ? foreach ($ini_array['settings'] as $var => $value) { $settings[ $var ] = $value; } // next var # print("
"); print_r($allow); print("
"); $random1 = "sdfjnawklehfyshfweidhsf"; $random2 = "ieruwemnmnbiucxyvwemnbr"; switch ($cmd) { case "": break; case "hilite": if (! $allow['change_hilite'] ) { echo "
ERROR: permissions do not include change_hilite
\n"; } elseif (! is_writeable($thisdir) ) { echo "
ERROR: directory '$thisdir' is not writeable
\n"; } elseif (file_exists($this_hilite) and ! is_writeable($this_hilite) ) { echo "
ERROR: hilite file is not writeable
\n"; } elseif (! @copy($what, $this_hilite)) { echo "
ERROR: failed to set hilite
\n"; } else { echo "
updated hilite
\n"; } break; case "redo": if (! $allow['redo_thumb']) { echo "
ERROR: permissions do not include redo_thumb
\n"; } elseif (! preg_match('{/th_[.]?[^/.]*[.](GIF|JPG)$}i', $what)) { echo "
ERROR: '$what' is not a thumb file
\n"; } elseif (! file_exists($what)) { echo "
ERROR: thumb file '$what' does not exist
\n"; } elseif (! is_writeable($thisdir) ) { echo "
ERROR: directory '$thisdir' is not writeable
\n"; } elseif (! is_writeable($what) ) { echo "
ERROR: thumb file '$what' is not writeable
\n"; } elseif (! unlink($what)) { echo "
ERROR: failed to delete thumb file
\n"; } else { if (file_exists($what)) { echo "
ERROR: thumb file '$what' still exists after delete
\n"; } else { echo "
deleted thumb file $what
\n"; } } break; case "edit": if (! $allow['edit_file']) { echo "
ERROR: permissions do not include edit_file
\n"; } elseif (! preg_match('{/[.]?[^/.]*[.]TXT$}i', $what)) { echo "
ERROR: '$what' is not a text file
\n"; } elseif (! is_writeable($thisdir) ) { echo "
ERROR: directory '$thisdir' is not writeable
\n"; } elseif ( @$_POST['cancel'] ) { echo "
Cancelling edit of '$what'
\n"; } elseif ( @$_POST['submit'] ) { if ($_REQUEST[$random1] != $random2) { echo "
ERROR: bad security code passed
\n"; } else { $new_content = $_POST['content']; $new_content = get_magic_quotes_gpc() ? stripslashes($new_content) : $new_content; if (! $new_content) { if (file_exists($what)) { unlink($what); echo "
Deleted blank '$what'
\n"; } else { echo "
Not saving blank '$what'
\n"; } } else { if (! is_writeable($what) ) { unlink($what); echo "
Deleting non-writeable text file '$what'
\n"; } file_put_contents( $what, $new_content ); echo "
Saved edit of '$what'
\n"; } } } else { if (file_exists($what)) { $original_contents = file_get_contents($what); } else { echo "
File was missing: creating ...
\n"; $original_contents = ""; } // endif exists $original_lines = count( split("\n", $original_contents) ); ?>
Editing file '':
ERROR: permissions do not include rename_file\n"; } elseif ( (! is_dir($full_what)) and (! preg_match('{^[.]?[^/.]*[.](GIF|JPG)$}i', $what)) ) { echo "
ERROR: '$full_what' is neither a direcory nor an image file
\n"; } elseif (! file_exists($full_what)) { echo "
ERROR: image file '$full_what' does not exist
\n"; } elseif (! is_writeable($thisdir) ) { echo "
ERROR: directory '$thisdir' is not writeable
\n"; } elseif ( @$_POST['cancel'] ) { echo "
Cancelling rename of '$full_what'
\n"; } elseif ( @$_POST['submit'] ) { if ($_REQUEST[$random1] != $random2) { echo "
ERROR: bad security code passed
\n"; } else { $new_what = $_POST['new_what']; $full_new_what = "$thisdir/$new_what"; if (file_exists($full_new_what)) { echo "
ERROR: new name '$new_what' already exists
\n"; } elseif ( (! is_dir($full_what)) and (! preg_match('{^[.]?[^/.]*[.](GIF|JPG)$}i', $new_what)) ) { echo "
ERROR: new name '$new_what' is not an image file
\n"; } else { if (is_dir($full_what)) { if (rename($full_what, $full_new_what)) { echo "
Renamed '$what' to '$new_what'
\n"; } else { echo "
ERROR: Rename of '$what' to '$new_what' failed
\n"; } } else { $smallfile_old = "$thisdir/sm_$what"; $smallfile_new = "$thisdir/sm_$new_what"; $basename_old = image_basename($what); $basename_new = image_basename($new_what); $caption_old = "$thisdir/${basename_old}.txt"; $caption_new = "$thisdir/${basename_new}.txt"; $comments_old = "$thisdir/co_${basename_old}.txt"; $comments_new = "$thisdir/co_${basename_new}.txt"; $thumb_old = "$thisdir/th_$what"; $thumb_new = "$thisdir/th_$new_what"; safe_move($smallfile_old, $smallfile_new); safe_move($caption_old, $caption_new); safe_move($comments_old, $comments_new); safe_move($thumb_old, $thumb_new); safe_move($full_what, $full_new_what); echo "
Renamed '$what' to '$new_what' with all attendant files
\n"; } // endif is_dir } // endif new name exists } } else { ?>
File old name:
File new name:
ERROR: permissions do not include move_file\n"; } elseif (! file_exists($full_what)) { echo "
ERROR: file '$full_what' does not exist
\n"; } elseif ( (! is_dir($full_what)) and (! preg_match('{[^/.]*[.](GIF|JPG)$}i', $what)) ) { echo "
ERROR: '$full_what' is neither a direcory nor an image file
\n"; } elseif (! is_writeable($thisdir) ) { echo "
ERROR: directory '$thisdir' is not writeable
\n"; } elseif ( @$_POST['cancel'] ) { echo "
Cancelling rename of '$full_what'
\n"; } elseif ( @$_POST['submit'] ) { if ($_REQUEST[$random1] != $random2) { echo "
ERROR: bad security code passed
\n"; } else { $new_dir = $_POST['new_dir']; $full_new_what = "$new_dir/$what"; if (file_exists($full_new_what)) { echo "
ERROR: subdir '$what' already exists in '$new_dir'
\n"; } elseif (! is_dir($new_dir)) { echo "
ERROR: new name '$new_dir' is not a directory
\n"; } else { if (is_dir($full_what)) { if (rename($full_what, $full_new_what)) { echo "
Moved '$what' to '$new_dir'
\n"; } else { echo "
ERROR: Move of '$what' to '$new_dir' failed
\n"; } } else { $smallfile_old = "$thisdir/sm_$what"; $smallfile_new = "$new_dir/sm_$what"; $basename = image_basename($what); $caption_old = "$thisdir/${basename}.txt"; $caption_new = "$new_dir/${basename}.txt"; $comments_old = "$thisdir/co_${basename}.txt"; $comments_new = "$new_dir/co_${basename}.txt"; $thumb_old = "$thisdir/th_$what"; $thumb_new = "$new_dir/th_$what"; safe_move($smallfile_old, $smallfile_new); safe_move($caption_old, $caption_new); safe_move($comments_old, $comments_new); safe_move($thumb_old, $thumb_new); safe_move($full_what, $full_new_what); echo "
Moved '$what' to '$new_dir' with all attendant files
\n"; } // endif is_dir } // endif new name exists } } else { ?>
File name: File old directory:
File new directory:
ERROR: permissions do not include delete_file\n"; } elseif (! preg_match('{/[.]?[^/.]*[.](GIF|JPG)$}i', $full_what)) { echo "
ERROR: '$full_what' is not an image file
\n"; } elseif (! file_exists($full_what)) { echo "
ERROR: image file '$full_what' does not exist
\n"; } elseif (! is_writeable($thisdir) ) { echo "
ERROR: directory '$thisdir' is not writeable
\n"; } else { ?>
Confirm deletion of file '':
YES, DELETE NO, cancel
ERROR: permissions do not include delete_file\n"; } elseif (! preg_match('{/[.]?[^/.]*[.](GIF|JPG)$}i', $full_what)) { echo "
ERROR: '$full_what' is not an image file
\n"; } elseif (! file_exists($full_what)) { echo "
ERROR: image file '$full_what' does not exist
\n"; } elseif (! is_writeable($thisdir) ) { echo "
ERROR: directory '$thisdir' is not writeable
\n"; } elseif (! unlink($full_what)) { echo "
ERROR: failed to delete image file
\n"; } else { if (file_exists($what)) { echo "
ERROR: image file '$full_what' still exists after delete
\n"; } else { echo "
deleted image file $full_what
\n"; } } break; case "merge": $full_what = "$thisdir/$what"; if (! $allow['merge_dir']) { echo "
ERROR: permissions do not include merge_dir
\n"; } elseif (! file_exists($full_what)) { echo "
ERROR: file '$full_what' does not exist
\n"; } elseif (! is_dir($full_what)) { echo "
ERROR: '$full_what' is not a direcory
\n"; } elseif (! is_writeable($thisdir) ) { echo "
ERROR: directory '$thisdir' is not writeable
\n"; } elseif (! is_writeable($full_what) ) { echo "
ERROR: directory '$full_what' is not writeable
\n"; } elseif ( @$_POST['cancel'] ) { echo "
Cancelling merge of '$full_what'
\n"; } elseif ( @$_POST['submit'] ) { if ($_REQUEST[$random1] != $random2) { echo "
ERROR: bad security code passed
\n"; } else { $new_dir = $_POST['new_dir']; if (! is_dir($new_dir)) { echo "
ERROR: merge target '$new_dir' is not a directory
\n"; } else { echo "
Merging '$full_what' into '$new_dir'
\n"; $files_array = get_files_in_dir($full_what); foreach ($files_array as $f) { $old_file = "$full_what/$f"; $new_file = "$new_dir/$f"; echo "
... move '$f'
\n"; delete_older($old_file, $new_file); safe_move($old_file, $new_file); } rmdir($full_what); echo "
Done.
\n"; } // endif new name exists } } else { ?>
Merge directory: /
With directory:
ERROR: invalid cmd '$cmd'\n"; break; } ?>

(full size)\n"; } else { echo "
\n"; } $text_file = image_basename($thefile) . ".txt"; $comments = "$thisdir/co_$text_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("
no fullsize for thumb
\n"); $class .= " auto_error"; $thumb = $alt_thumb; } elseif ($settings['max_fix_thumbnails'] <= 0) { # print("
done enough thumbs $settings['max_fix_thumbnails']
\n"); # already done too many thumbnails $class .= " auto_enough"; $thumb = $alt_thumb; } else { # print("
create thumb $settings['max_fix_thumbnails']
\n"); $settings['max_fix_thumbnails']--; $command = "convert " . escapeshellarg($fullsize) . " -verbose " . " -resize " . escapeshellarg("150x>") . " -resize " . escapeshellarg("x150>") . " " . escapeshellarg($thumb); print("\n"); flush(); $last_line = exec($command, $all_output, $retval); print(""); print(""); if ($retval) { # print("
create thumb failed
\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); ?>

HILITE REDO RENAME MOVE DELETE MERGE \n"); } showfile($caption); if ($allow['edit_file']) { ?> * **

\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: $value) { $status = ($value ? "YES" : "NO"); ?> :