// 2.8 -- Added image resizing // 2.9 -- Added compact thumbnail display // 2.9a -- Fixed folder icon url // 2.9b -- Fix "undefined index 'edit'" warning // 3.0 -- Cleaned up code based on running with ALL debug msgs on // 3.0a -- Fixed a few more minor bugs // 3.1 -- Changed compact mode to use clipped, square thumbnails; added // optional 'immediate' display of movies which is now the default // 3.2 -- Add some foundational code to support online editing of settings; // Add ablilty to display text files and to exclude some subdirs // 3.2a -- Added test to make sure saved convert-path is valid // 3.2b -- Removed write_defaults call from convert_path() and ensured when // write_defaults IS called it saves a valid convert path. 3.2a was // causeing empty dflt.txt file to be written. // 3.2c -- Fixed loop count in get_icons which was preventing the text icon // from being retreived. // 3.3 -- Allow exclusion list in .imgdir to include files, not just subdirs; // Added nicer default title; // 3.3a -- Fixed thumbnail aspect ratio problems // 3.3b -- Added ability to customize folder and text file icon as well as // spacing // 3.3c -- fixed caption problem for converted files and those with JPG in // name instead of JPG. // 3.4 -- Set defaults to more reasonable values for 'compact' presentation // 3.4a -- Added ablility to set seperator between folder-based titles // 3.4b -- Set title of website to displayed title. // 3.5 -- Cleaned up to be xhtml compliant; utilized more css; removed // 'center' tags; reduced reliance on tables for formating; // 3.5a -- Added ability to add customized header. Needed to support SQREAM // 3.5b -- Minor bug fix // 3.5c -- More code restructuring for better performanc; generalized how // image meta data is stored; added support for star ratings; // deprecated the .captions folder. // 3.5d -- Added rudimentary support for adding captions and star ratings // interactively; Added ability to display captions while hovering; // Cleaned up html valididty problems; // 3.5e -- More cleanup and minor bug fixes; // 3.5f -- Final cleanup before adding new features. // 3.5g -- Added no-refresh server updates when annotating pics; // Added preliminary support for CPicFolders to speedup loading // 3.6 -- Full implementation of CPicFolders and fixed bug related to // image caching on server -- significant speedup! // 3.6a -- Add ability to pre-process images // 3.6b -- Bug Fixes associated with building of filelists // 3.6c -- Added immediate flushing for "no output" operations; added some // debugging support; added ability to regenerate file-lists when // pre-processing images. // 3.7 -- Finished major work on page preprocessing; added option to remove // the preprocessing and rebuildthumb links; made preprocessing work // recursively and only if thumbnails/converted images don't // already exist. // 4.0 -- Prevented creation of thumbnails for non-image files; made it ok // if converted images are within one pixel of target; fixed bug when // path to images had a '.' in it. // 4.1 -- Add code to look at file modification time when creating thumbs // or converting images.` // 4.2 -- Add ability to sort by star rating and to make 5-star images // bigger // 4.3a -- Fixed some minor bugs in code. // 4.3b -- Check for existance of imgdir.css; // 5.0 -- Add support for RSS feeds; in particular piclens/CoolIris support // 5.1 -- Add support for printing out version from command line // 5.1a -- Fixed minor warning message exposed by newer version of php // 5.1b -- Ensured all images used have copies on berzerker in "images" // 5.2 -- Changed some default options, specifically disabling RSS and // off the display of the pre-process links. $gVersion = "v5.2"; $gWorkspace = ".imgdir"; $gDefaultsFile = "$gWorkspace/dflt.txt"; // Parse command line arguments into _REQUEST array parse_args($argv, $argc); // If only requesting version, print it and exit if (isset($_REQUEST['version'])) { print("$gVersion\n"); exit; } // If .imgdir doesn't exist or isn't writable, display setup instructions if (!is_writable($gWorkspace)) { display_setup_instructions_and_exit(); } // Ensure .imgdir workspace is setup properly setup_workspace(); // Read user settings from file, or set them to hard coded defaults process_defaults_file(); // Set current state information set_global_state_variables(); set_sort_state(); // Convert and display specific image if requested if (isset($_REQUEST['show'])) { show_and_exit($_REQUEST['show']); } // Remove thumbnails if they are being rebuilt if (isset($_REQUEST['remove_thumbs'])) { if (!$gOpt['debug']) { header("HTTP/1.0 204 No Content"); flush(); } remove_thumbs_and_exit(); } // Remove rss files if they are being rebuilt if (isset($_REQUEST['remove_rss'])) { if (!$gOpt['debug']) { header("HTTP/1.0 204 No Content"); flush(); } remove_rss_and_exit(); } // Edit user settings if requested if (isset($_REQUEST['edit'])) { edit_settings_and_exit(); } // Apply modified user settings if requested if (isset($_POST['set'])) { if (!$gOpt['debug']) { header("HTTP/1.0 204 No Content"); flush(); } assign_settings(); $dflt_file = $gDefaultsFile . ".new"; write_defaults($dflt_file, $gOpt); } if (isset($_REQUEST['debug'])) $gOpt['debug'] = true; // Ready to boogie... Get the index of pictures $pic_folder = new CPicFolder($gState['parent'], $gOpt['sortby'], $gOpt['order'], $gOpt['minstars']); save_old_captions($gState['parent'], $pic_folder); // Write out rss file(s) if needed if ($gOpt['enable_rss']) write_rss($pic_folder); if (isset($_REQUEST['rate'])) $rating = $_REQUEST['rate']; if (isset($_REQUEST['new_caption'])) $new_caption = $_REQUEST['new_caption']; if (isset($_REQUEST['idx'])) $idx = $_REQUEST['idx']; if (isset($idx) && ((isset($rating)) || isset($new_caption))) { if (!$gOpt['debug']) { header("HTTP/1.0 204 No Content"); flush(); } $pic = $pic_folder->GetInfo($idx); $pic->UpdateMetaData($rating, $new_caption); exit; } if (isset($_REQUEST['preprocess'])) { if (!$gOpt['debug']) { header("HTTP/1.0 204 No Content"); flush(); } $recurse = true; $force = false; $allflists = false; CPicFolder::PreProcessThumbnails($gState['parent'], $recurse, $force); CPicFolder::PreProcess($gState['parent'], $allflists, $recurse); exit; } // **** START OF MAIN HTML **** // // Print style sheet, title, and user-provided header $gStart = microtime(true); // For timing analysis -gdg print_html_head($pic_folder); // Save state in hidden post variables // gdg print_hidden_post_variables($_REQUEST['idx']); // Print state for debugging purposes if (isset($_REQUEST['debug'])) $gOpt['debug'] = true; if ($gOpt['debug']) print_state(); // Print main title and ImgDir splash message print_title(); // Print customizable link print_link(); $idx = $gState['idx']; if ($gState['idx'] == -1) { print_subdirs($pic_folder->GetCount()); if ($gState['annotate']) annotate_thumbnails($pic_folder); else print_thumbnails($pic_folder); } else { print_single_image($pic_folder, $idx); } print_html_foot(); // **** END OF MAIN HTML **** // function add_annotation_state(&$string) { global $gState; if ($gState['annotate']) $string .= "&annotate=1"; } function add_showdir_collapse_flag(&$string) { if (isset($_REQUEST['show_dir'])) $string .= "&show_dir"; if (isset($_REQUEST['collapse'])) { $collapse = $_REQUEST['collapse']; $string .= "&collapse=$collapse"; } } function add_debug_flag(&$string) { global $gOpt; if ($gOpt['debug']) $string .= "&debug"; } function add_sort_flags(&$string) { if (isset($_REQUEST['O'])) { $order = $_REQUEST['O']; $string .= "&O=$order"; } if (isset($_REQUEST['C'])) { $order = $_REQUEST['C']; $string .= "&C=$order"; } } function get_title() { global $gVersion; global $gOpt; $title = $gOpt['title']; if (!isset($title) || ($title == "")) { $seperator = get_seperator(); if (ereg("index.php", $_SERVER['REQUEST_URI'])) { $title = ereg_replace("index.php.*$", "", $_SERVER['REQUEST_URI']); $title = str_replace("/", $seperator, trim($title, "/")); } else if (ereg("imgdir.php", $_SERVER['REQUEST_URI'])) { $title = ereg_replace("imgdir.php.*$", "", $_SERVER['REQUEST_URI']); $title = str_replace("/", $seperator, trim($title, "/")); } else { $title = $_SERVER['REQUEST_URI']; $title = str_replace("/", $seperator, trim($title, "/")); } } if (!isset($title) || ($title == "")) { $title = "ImgDir $gVersion"; } return $title; } function get_page_number($idx) { global $gOpt; return (1 + floor($idx/ $gOpt['per_page'])); } function print_html_head($pic_folder) { global $gOpt; print("\n"); print("\n"); print("\n"); print_style_sheet(); $title = get_title(); print("$title\n"); if ($gOpt['enable_rss']) { // Get rss filename $rss_file = $pic_folder->GetRSSFile(); print("\n"); print("\n"); } print("\n"); print("\n"); // Add user-provided header if (isset($gOpt['include_header'])) { $include_header = $gOpt['include_header']; include("$include_header"); } // Begin form $php_self = $_SERVER['PHP_SELF']; print "
\n"; // Begin container print ("
\n"); } function print_html_foot() { print("
\n"); print("
\n"); print("\n"); print("\n"); } function print_title() { global $gVersion; global $gOpt; global $gWorkspace; $title = get_title(); print "

$title

\n"; if (!ereg("ImgDir", $title)) { print "

\n"; print ""; if ($gOpt['enable_rss']) print "Powered by ImgDir $gVersion - now PicLens Enabled!\n"; else print "Powered by ImgDir $gVersion\n"; print "

\n"; if ($gOpt['enable_rss']) { print "\n"; print " \n"; } } } function print_link() { global $gOpt; $link_target = $gOpt['link_target']; if (isset($link_target) && ($link_target != "")) { $link_label = $gOpt['link_label']; if (!isset($link_label)) $link_label = "Back to Home Page"; print "

$link_label

\n"; } } function print_subdirs($numpics) { global $gOpt; global $gState; // Convenience variables $parent = $gState['parent']; $php_self = $_SERVER['PHP_SELF']; // Get all subdirectories in current parent //$subdir_list = get_subdirs($parent, $gOpt['sortby'], $gOpt['order']); $subdir_list = get_subdirs($parent, "fname", "ascending"); print_description($parent, $gOpt['description_file']); $numitems = $numpics + count($subdir_list); if ($numitems > $gOpt['sort_link_pic_count']) { display_sort_links($php_self, $parent, $gOpt['sortby'], $gOpt['order']); } $start_idx = 0; $end_idx = count($subdir_list); // Display subdirectory icons in a table if (($gState['show_dir'] == 1) && ($end_idx > 0)) { if ($gState['collapse']) { $target = "$php_self?parent_dir=$parent&collapse=0"; $page = $_REQUEST['page']; if (isset($page)) $target .= "&page=$page"; if (isset($_REQUEST['show_dir'])) $target .= "&show_dir"; print "

Display Hidden Folders

\n"; } else { print "\n"; $columns = $gOpt['per_row']; if ($columns == 0) { add_all_subdirs($parent, $subdir_list); $numRows = $end_idx; } else { for ($ii = $start_idx; $ii < $end_idx; $ii += $columns) { add_subdir_row($parent, $subdir_list, $ii, $columns, $end_idx); } $numRows = ($end_idx - $start_idx) / $columns; } print "
\n"; if ($numRows > $gOpt['collapse_row_count']) print_collapse_option($parent); } } } function annotate_thumbnails($pic_folder) { global $gOpt; global $gState; $start_idx = 0; $end_idx = $pic_folder->GetCount(); $per_page = $gOpt['per_page']; if ($end_idx >= $per_page) { $last_page = get_page_number($end_idx - 1); $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1; if ($page > $last_page) $page = $last_page; $end_idx = $page * $per_page; $start_idx = $end_idx - $per_page; } else { $page = 1; $last_page = 1; } // Display image icons in a table print "\n"; for ($ii = $start_idx; $ii < $end_idx; $ii++) { $pic = $pic_folder->GetInfo($ii); print("\n\n"); print "\n"; print "\n"; print "\n"; print("\n"); print "\n"; print "\n"; } print "
\n"; $pic->AddEntry($gState['parent'], $ii); print "\n"; $pic->DisplayCaption(1, $ii); print "
\n"; print_star_rating(1, $gState['parent'], $ii, $pic); print "

\n"; print_folder_footer($page, $last_page); } function print_thumbnails($pic_folder) { global $gOpt; global $gState; // Get all files in current parent // preload_thumbnails($file_list); //if ($gOpt['preload']) //preload($file_list); $start_idx = 0; $end_idx = $pic_folder->GetCount(); $per_page = $gOpt['per_page']; if ($end_idx >= $per_page) { $last_page = get_page_number($end_idx - 1); $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1; if ($page > $last_page) $page = $last_page; // gdg new way?? //$start_idx = ($page - 1) * $per_page; //if (($start_idx + $per_page > $end_idx) { // $end_idx = $start_idx + $per_page; //} $end_idx = $page * $per_page; $start_idx = $end_idx - $per_page; } else { $page = 1; $last_page = 1; } // Display row of image icons $cellspacing = (isset($gOpt['compact']) && $gOpt['compact']) ? 0 : 5; for ($ii = $start_idx; $ii < $end_idx; $ii += $gOpt['per_row']) { add_image_row($gState['parent'], $pic_folder, $ii, $gOpt['per_row'], $end_idx); } print_folder_footer($page, $last_page); } function print_single_image($pic_folder, &$idx) { global $gState; $count = $pic_folder->GetCount(); $parent = $gState['parent']; $pic = $pic_folder->GetInfo($idx); if ($gState['annotate']) { $rating = $_REQUEST['rate']; $new_caption = $_REQUEST['new_caption']; $pic->UpdateMetaData($rating, $new_caption); if (isset($rating) && ($idx < $count - 1)) $idx++; } print_image_navigation($parent, 0, $idx, $count); $pic->DisplayImage($parent, $idx); print_image_footer($pic_folder, $idx); } function print_folder_footer($thisPage, $lastPage) { global $gState; global $gOpt; if ($gState['annotate']) print_stop_annotation(); if (($gState['parent'] !== ".") || ($lastPage > 1)) print_page_navigation($thisPage, $lastPage, $gState['parent']); if ($gOpt['enable_rss']) print_piclens_button(); if ($gOpt['show_rebuildthumb_link']) print_rebuild_thumbnails(); if ($gOpt['enable_rss'] && $gOpt['show_rebuildrss_link']) print_rebuild_rss(); if ($gOpt['show_preprocess_link']) print_preprocess(); // print_visit_imgdir(); } function print_image_footer($pic_folder, $thisIdx) { global $gState; if ($gState['annotate']) print_stop_annotation(); $startIdx = 0; $endIdx = $pic_folder->GetCount(); // gdt we can just pas in the endIdx print_image_navigation($gState['parent'], $startIdx, $thisIdx, $endIdx); // print_visit_imgdir(); } function print_star_rating($allowChange, $parent, $thisIdx, $pic) { if ($allowChange) { $php_self = $_SERVER['PHP_SELF']; $target = "$php_self?parent_dir=$parent&idx=$thisIdx"; add_showdir_collapse_flag($target); add_sort_flags($target); // gdg add_annotation_state($target); $t1 = $target . "&rate=1"; $t2 = $target . "&rate=2"; $t3 = $target . "&rate=3"; $t4 = $target . "&rate=4"; $t5 = $target . "&rate=5"; $pxwidth = 30 * $pic->numstars; print("
\n"); print("\n"); print("
\n"); } } function print_image_navigation($parent, $startIdx, $thisIdx, $endIdx) { $php_self = $_SERVER['PHP_SELF']; $lastValidIdx = $endIdx - 1; if ($thisIdx > $startIdx) { $prevIdx = $thisIdx - 1; $target = "$php_self?parent_dir=$parent&idx=$prevIdx"; add_showdir_collapse_flag($target); add_sort_flags($target); add_annotation_state($target); $left = "Prev"; } else { $left = "Prev"; } $page = get_page_number($thisIdx); $target = "$php_self?parent_dir=$parent&page=$page"; add_showdir_collapse_flag($target); add_sort_flags($target); add_annotation_state($target); $center = "Back To Thumbnail View"; if ($thisIdx < $lastValidIdx) { $nextIdx = $thisIdx + 1; $target = "$php_self?parent_dir=$parent&idx=$nextIdx"; add_showdir_collapse_flag($target); add_sort_flags($target); add_annotation_state($target); $right = "Next"; } else { $right = "Next"; } print "\n"; print "\n"; print " \n"; print " \n"; print " \n"; print "\n"; print "
$left$center$right
\n"; } function print_image_name($fname) { print "$fname\n"; } function print_page_navigation($thisPage, $lastPage, $currentParent) { $php_self = $_SERVER['PHP_SELF']; $printSomething = 1; if ($lastPage == 1) { $printSomething = 0; $left = ""; $right = ""; } else { if ($thisPage == 1) $left = "Prev Page"; else { $prevPage = $thisPage - 1; $target = "$php_self?parent_dir=$currentParent&page=$prevPage"; add_showdir_collapse_flag($target); add_sort_flags($target); add_annotation_state($target); $left = "Prev Page"; } if ($thisPage == $lastPage) $right = "Next Page"; else { $nextPage = $thisPage + 1; $target = "$php_self?parent_dir=$currentParent&page=$nextPage"; add_showdir_collapse_flag($target); add_sort_flags($target); add_annotation_state($target); $right = "Next Page"; } } if ($currentParent !== ".") { $printSomething = 1; $lastSlash = strrpos($currentParent, "/"); if ($lastSlash === false) $parent = "."; else { $parent = substr($currentParent, 0, $lastSlash); } $target = "$php_self?parent_dir=$parent"; add_showdir_collapse_flag($target); add_sort_flags($target); $center = "Up To Parent Folder"; } if ($printSomething) { print "\n"; print "\n"; print " \n"; print " \n"; print " \n"; print "\n"; print "
$left$center$right
\n"; } } function print_collapse_option($parent) { $php_self = $_SERVER['PHP_SELF']; $target = "$php_self?parent_dir=$parent&collapse=1"; if (isset($_REQUEST['show_dir'])) $target .= "&show_dir"; print "

Collapse Folders

"; } function print_rebuild_thumbnails() { $php_self = $_SERVER['PHP_SELF']; $target = "$php_self?remove_thumbs=1"; add_showdir_collapse_flag($target); add_sort_flags($target); add_debug_flag($target); print "

Rebuild Thumbnails

\n"; } function print_rebuild_rss() { $php_self = $_SERVER['PHP_SELF']; $target = "$php_self?remove_rss=1"; add_showdir_collapse_flag($target); add_sort_flags($target); add_debug_flag($target); print "

Rebuild RSS Files

\n"; } function print_preprocess() { global $gState; $php_self = $_SERVER['PHP_SELF']; $parent = $gState['parent']; $target = "$php_self?parent_dir=$parent&preprocess=1"; add_showdir_collapse_flag($target); add_sort_flags($target); add_debug_flag($target); print "

PreProcess Images

\n"; } function print_visit_imgdir() { $home = "http://www.berzerker.net/imgdir"; print "

Visit ImgDir Homepage

\n"; } function print_piclens_button() { print("

\n"); print("PicLens Slideshow\n"); print(" \"PicLens\"\n"); print("

\n"); } function print_stop_annotation() { $target = build_target_url(); $target .= "&annotate=0"; print "

Stop Annotating Images

\n"; } function print_description($parent, $fname) { $fullpath = "$parent/$fname"; if (!is_file($fullpath)) { return; } $fp = file($fullpath); print "
\n"; print ("

\n"); foreach ($fp as $line) { $line = trim($line); print (" $line
\n"); } print ("

\n"); print "
\n"; } function get_subdirs($parent_dir, $sfield, $sorder) { global $gOpt; $subdirs = find_subdirs($parent_dir, $gOpt['exclude']); if (count($subdirs) == 0) return NULL; foreach ($subdirs as $file) { $farray['fname'] = $file; $farray['fsize'] = 0; $farray['mtime'] = filemtime($file); $saved_files[] = $farray; } if (!isset($saved_files)) { return NULL; } /* Modified time */ if ($sfield == "mdate") { usort($saved_files, ($sorder == "descending") ? "mtime_rcmp" : "mtime_cmp"); } else if ($sfield == "fsize") { usort($saved_files, ($sorder == "descending") ? "fsize_rcmp" : "fsize_cmp"); } else if ($sfield == "fname") { usort($saved_files, ($sorder == "descending") ? "fname_rcmp" : "fname_cmp"); } else { usort($saved_files, "fname_cmp"); } return $saved_files; } // built in to php5 but not php4 function local_scandir($parent_dir) { $dh = opendir($parent_dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; } return $files; } function find_subdirs($parent_dir, $excludes) { $needs_path = ($parent_dir != "."); if (version_compare(phpversion(), "5.0.0", ">=")) $list = scandir($parent_dir); else $list = local_scandir($parent_dir); foreach ($list as $entry) { if ((substr($entry, 0, 1) == ".") || (isset($excludes) && is_excluded($entry, $excludes))) continue; if ($needs_path) $entry = "$parent_dir/$entry"; if (is_dir($entry)) $result[] = $entry; } return (isset($result) ? $result : NULL); } function find_files ($parent_dir, $extensions, $excludes) { //$result[] = NULL; $result = array(); $needs_path = ($parent_dir != "."); if (version_compare(phpversion(), "5.0.0", ">=")) $list = scandir($parent_dir); else $list = local_scandir($parent_dir); foreach ($list as $entry) { if ((substr($entry, 0, 1) == ".") || (!file_extension_in_list($entry, $extensions)) || (isset($excludes) && is_excluded($entry, $excludes))) continue; if ($needs_path) $entry = "$parent_dir/$entry"; if (is_file($entry)) $result[] = $entry; } return $result; } function fname_cmp($a, $b) { return (strcasecmp($a["fname"],$b["fname"])); } function fname_rcmp($a, $b) { return (strcasecmp($b["fname"],$a["fname"])); } function mtime_cmp($a, $b) { if ($a["mtime"] == $b["mtime"]) return 0; return ($a["mtime"] < $b["mtime"]) ? -1 : 1; } function mtime_rcmp($a, $b) { if ($a["mtime"] == $b["mtime"]) return 0; return ($a["mtime"] > $b["mtime"]) ? -1 : 1; } function fsize_cmp($a, $b) { // if ($a["fsize"] == $b["fsize"]) return 0; if ($a["fsize"] == $b["fsize"]) return (strcasecmp($a["fname"],$b["fname"])); return ($a["fsize"] < $b["fsize"]) ? -1 : 1; } function fsize_rcmp($a, $b) { // if ($a["fsize"] == $b["fsize"]) return 0; if ($a["fsize"] == $b["fsize"]) return (strcasecmp($a["fname"],$b["fname"])); return ($a["fsize"] > $b["fsize"]) ? -1 : 1; } function save_old_captions($parent, $pic_folder) { global $gWorkspace; if (!is_array($pic_folder->fname_list)) return; if ($parent == ".") $captions_file = "$gWorkspace/.captions/captions.txt"; else $captions_file = "$gWorkspace/.captions/$parent/captions.txt"; if (is_readable($captions_file)) { // Initialize captions foreach ($pic_folder->fname_list as $entry) { $fname = get_fname($entry); $captions["$fname"] = ""; } // Read old-style Captions $fp = file($captions_file); foreach ($fp as $line) { $line = trim($line); list ($key, $value) = explode(":", $line, 2); $captions[$key] = $value; } // Assign captions to CPic and save $count = $pic_folder->GetCount(); for ($ii = 0; $ii < $count; $ii++) { $pic = $pic_folder->GetInfo($ii); $fname = get_fname($pic->fname); $caption = $captions["$fname"]; if (isset($caption)) { $pic->UpdateCaption($caption); } } // Move .captions file $new_file = "$captions_file.bak"; rename($captions_file, $new_file); } return; } function add_all_subdirs($parent, $subdir_list) { global $gWorkspace; $end = count($subdir_list); $folder_icon = get_folder_icon(); $icons_avail = is_readable($folder_icon); if ($icons_avail) { for ($ii = $start; $ii < $end; $ii++) { add_subdir_entry($parent_dir, $subdirs[$ii]['fname'], $folder_icon); } } // Remove until we can figure out how to do icons as submit buttons. print("\n"); for ($ii = $start; $ii < $end; $ii++) { $fname = substr(strrchr($subdirs[$ii]['fname'], "/"), 1); if (!$fname) { $fname = $subdirs[$ii]['fname']; } if ($icons_avail) { print " $fname\n"; } else { $target = $_SERVER['PHP_SELF']; $subdir = $subdirs[$ii]['fname']; print " $fname\n"; } } print "\n"; //Alternate if we want labesl on files but not directory icons/buttons //print("\n"); //print " \n"; //print "\n"; } function add_subdir_row($parent_dir, $subdirs, $start, $pics_per_row, $max) { global $gWorkspace; $end = $start + $pics_per_row; if ($end > $max) $end = $max; $folder_icon = get_folder_icon(); $icons_avail = is_readable($folder_icon); if ($icons_avail) { print("\n"); for ($ii = $start; $ii < $end; $ii++) { add_subdir_entry($parent_dir, $subdirs[$ii]['fname'], $folder_icon); } print "\n"; } // Remove until we can figure out how to do icons as submit buttons. print("\n"); for ($ii = $start; $ii < $end; $ii++) { $fname = substr(strrchr($subdirs[$ii]['fname'], "/"), 1); if (!$fname) { $fname = $subdirs[$ii]['fname']; } if ($icons_avail) { print " $fname\n"; } else { $target = $_SERVER['PHP_SELF']; $subdir = $subdirs[$ii]['fname']; print " $fname\n"; } } print "\n"; //Alternate if we want labesl on files but not directory icons/buttons //print("\n"); //print " \n"; //print "\n"; } function add_image_row($parent_dir, $pic_folder, $start, $pics_per_row, $max) { global $gOpt; $end = $start + $pics_per_row; if ($end > $max) $end = $max; // gdg new to fix overflow if ($end > $pic_folder->GetCount()) $end = $pic_folder->GetCount(); // If for loop wouldn't execute, print nothing if ($start >= $end) return; // Get pic info for ($ii = $start; $ii < $end; $ii++) { $pic[$ii] = $pic_folder->GetInfo($ii); } // Print the thumbnail links row $rowwidth = ($gOpt['tsize'] + 8) * ($end - $start); printf ("
\n", $rowwidth); for ($ii = $start; $ii < $end; $ii++) { if ($pic[$ii]->IsMovie() || $pic[$ii]->IsTextFile()) printf("
\n", $gOpt['tsize']); else print("
\n"); $pic[$ii]->AddEntry($parent_dir, $ii); if (!isset($gOpt['compact']) || $gOpt['compact'] == 0) { $caption = $pic[$ii]->GetCaption(); print "$caption\n"; } print("
\n"); } print "
\n"; print "
\n"; } function add_subdir_entry ($parent_dir, $subdir, $icon) { global $gWorkspace; if (!is_dir($subdir) && !is_link($subdir)) { return; } // Create subdirectory for thumbnails for files within this subdir $thumb_link = "$gWorkspace/.thumbs/$subdir"; if (!is_dir($thumb_link)) { mkdir($thumb_link) or die("Unable to create $thumb_link
\n"); } // Create subdirectory for converted image files $converted_link = "$gWorkspace/.converted/$subdir"; if (!is_dir($converted_link)) { mkdir($converted_link) or die("Unable to create $converted_link
\n"); } // Create subdirectory for captions //$captions_link = "$gWorkspace/.captions/$subdir"; //if (!is_dir($captions_link)) { //mkdir($captions_link) or die("Unable to create $captions_link
\n"); //} // Create subdirectory for file info $info_link = "$gWorkspace/.info/$subdir"; if (!is_dir($info_link)) { mkdir($info_link) or die("Unable to create $info_link
\n"); } // Remove trailing slash from name $fname = substr(strrchr($subdir, "/"), 1); if (!$fname) { $fname = $subdir; } $target = $_SERVER['PHP_SELF']; $target .= "?parent_dir=$subdir"; add_showdir_collapse_flag($target); add_sort_flags($target); if (isset($icon)) { print " \"$fname\"\n"; } else { print " \n"; } } function make_subdir_folders ($subdir) { global $gWorkspace; global $gOpt; if (!is_dir($subdir) && !is_link($subdir)) { return; } // Create subdirectory for thumbnails for files within this subdir $thumb_link = "$gWorkspace/.thumbs/$subdir"; if (!is_dir($thumb_link)) { if ($gOpt['debug']) print("Creating folder $thumb_link
\n"); mkdir($thumb_link) or die("Unable to create $thumb_link
\n"); } // Create subdirectory for converted image files $converted_link = "$gWorkspace/.converted/$subdir"; if (!is_dir($converted_link)) { if ($gOpt['debug']) print("Creating folder $converted_link
\n"); mkdir($converted_link) or die("Unable to create $converted_link
\n"); } // Create subdirectory for file info $info_link = "$gWorkspace/.info/$subdir"; if (!is_dir($info_link)) { if ($gOpt['debug']) print("Creating folder $info_link
\n"); mkdir($info_link) or die("Unable to create $info_link
\n"); } } function get_folder_icon() { global $gOpt; global $gWorkspace; if (isset($gOpt['folder_icon']) && ($gOpt['folder_icon'] != "")) return $gOpt['folder_icon']; else return ("$gWorkspace/folder.gif"); } function get_textfile_icon() { global $gOpt; global $gWorkspace; if (isset($gOpt['textfile_icon']) && ($gOpt['textfile_icon'] != "")) return $gOpt['textfile__icon']; else return ("$gWorkspace/text.gif"); } function get_movie_icon() { global $gOpt; global $gWorkspace; if (isset($gOpt['movie_icon']) && ($gOpt['movie_icon'] != "")) return $gOpt['movie_icon']; else return ("$gWorkspace/movie.gif"); } function get_seperator() { global $gOpt; global $gWorkspace; if (isset($gOpt['seperator']) && ($gOpt['seperator'] != "")) return " " . $gOpt['seperator'] . " "; else return (" : "); } function get_fname($pathname) { // Remove everything before and including last slash $fname = substr(strrchr($pathname, "/"), 1); if (!$fname) return $pathname; else return $fname; } function preload_thumbnails($images) { global $gWorkspace; $count = count($images); if ($count <= 0) return; print ("\n"); } function preload($images) { $count = count($images); if ($count <= 0) return; print ("\n"); } function display_sort_links($form_handler, $parent_dir, $sfield, $sorder) { global $gWorkspace; // initialize new sort order to 'ascending' // For current sort field, toggle it's sort order $MNextOrder = "A"; $NNextOrder = "A"; $SNextOrder = "A"; if ($sfield == "fname") { $NNextOrder = ($sorder == "descending") ? "A" : "D"; } else if ($sfield == "mdate") { $MNextOrder = ($sorder == "descending") ? "A" : "D"; } else if ($sfield == "fsize") { $SNextOrder = ($sorder == "descending") ? "A" : "D"; } // Build first part of HTML string for specifying new sort type/order $sort_prefix = "

Filename

"; else $nsort = $sort_prefix."&C=N&O=$NNextOrder\">Filename"; if ($sfield == "mdate") $msort = $sort_prefix."&C=M&O=$MNextOrder\">Modified time"; else $msort = $sort_prefix."&C=M&O=$MNextOrder\">Modified time"; if ($sfield == "fsize") $ssort = $sort_prefix."&C=S&O=$SNextOrder\">File size"; else $ssort = $sort_prefix."&C=S&O=$SNextOrder\">File size"; if ($sorder == "descending") { $sorderName = "Descending"; } else { $sorderName = "Ascending "; } // Figure out which image to display for the sort order $nimage = "$gWorkspace/junk/blank.gif"; $mimage = "$gWorkspace/junk/blank.gif"; $simage = "$gWorkspace/junk/blank.gif"; if ($sfield == "fname") { $nimage = ($sorder == "descending") ? "$gWorkspace/junk/descending.gif" : "$gWorkspace/junk/ascending.gif"; } else if ($sfield == "mdate") { $mimage = ($sorder == "descending") ? "$gWorkspace/junk/descending.gif" : "$gWorkspace/junk/ascending.gif"; } else if ($sfield == "fsize") { $simage = ($sorder == "descending") ? "$gWorkspace/junk/descending.gif" : "$gWorkspace/junk/ascending.gif"; } // Display Links for changing sort order $sorthdr = "

Sort $sorderName by:

"; print "\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "\n"; // Display Images for indicating current sort field/order. if (is_readable($nimage) && is_readable($mimage) && is_readable($simage)) { print "\n"; print " \n"; print " \n"; print " \n"; print "\n"; } print "
$sorthdr$nsort$msort$ssort
\n"; } function get_convert_path() { global $gOpt; global $gDefaultsFile; if (isset($gOpt['convert_path']) && is_executable($gOpt['convert_path'])) return $gOpt['convert_path']; // Don't have valid path stored -- figure it out and save opt file if (is_executable("/usr/local/bin/convert")) $convert_path = "/usr/local/bin/convert"; else if (is_executable("/bin/convert")) $convert_path = "/bin/convert"; else if (is_executable("/usr/bin/convert")) $convert_path = "/usr/bin/convert"; else return; $gOpt['convert_path'] = $convert_path; return $convert_path; } function resize_image_square($in, $out, $dim) { global $gOpt; list($width, $height) = getimagesize($in); if ($width > $height) { $prog = get_convert_path(); $factor = $width / $height; $width = floor($factor * $dim); $height = $dim; resize_image($in, $out, $width, $height); $dw = ($width - $dim) / 2; $command = "$prog -crop $dim"."x"."$dim+$dw+0 \"$out\" \"$out\""; system($command, $stat); if (($stat != 0) && $gOpt['debug']) print ("resize_image_square: Cannot resize with:\n
$command\n
"); } else if ($width < $height) { $prog = get_convert_path(); $factor = $height / $width; $height = floor($factor * $dim); $width = $dim; resize_image($in, $out, $width, $height); $dh = ($height - $dim) / 2; $command = "$prog -crop $dim"."x"."$dim+0+$dh \"$out\" \"$out\""; system($command, $stat); if (($stat != 0) && $gOpt['debug']) print ("resize_image_square: Cannot resize with:\n
$command\n
"); } else { $stat = resize_image($in, $out, $dim , $dim); } return $stat; } function resize_image($in, $out, $width, $height) { global $gOpt; $prog = get_convert_path(); if (!isset($prog)) die ("resize_image: Cannot find image conversion program"); $s = $width . "x" . $height; $command = "$prog -size $s \"$in\" -resize $s +profile '*' \"$out\""; system($command, $stat); if (($stat != 0) && $gOpt['debug']) print ("resize_image: Cannot resize image with:\n
$command\n
"); return $stat; } function is_wrong_size($fname, $width, $height) { global $gOpt; list($imgWidth, $imgHeight) = getimagesize($fname); if ((abs($imgHeight - $height) > 1) || (abs($imgWidth - $width) > 1)) { if($gOpt['debug']) { print ("$fname is wrong size: ($imgWidth x $imgHeight) instead of ($width x $height
\n"); } return true; } else return false; } function is_excluded($fname, $excludes) { return (file_in_list($fname, $excludes)); } function is_movie($fname) { global $gOpt; return (file_extension_in_list($fname, $gOpt['videos'])); } function is_textfile($fname) { global $gOpt; return (file_extension_in_list($fname, $gOpt['textfiles'])); } function immediate_movie_access() { global $gOpt; return ($gOpt['immediate_movie_access']); } function file_extension_in_list($fname, $extString) { $fileExt = strrchr($fname, "."); $extArray = explode(",", $extString); foreach ($extArray as $ext) { if (strcasecmp( $fileExt, ".$ext") == 0) return 1; } return 0; } function file_in_list($fname, $entryString) { if (!isset($entryString)) return 0; $fileExt = strrchr($fname, "."); $entryArray = explode(",", $entryString); foreach ($entryArray as $entry) if (strcasecmp( $fname, $entry) == 0) return 1; return 0; } function get_icons($destination) { $icon[0]['url'] = "http://berzerker.net/imgdir/images/folder.gif"; $icon[0]['fname'] = "folder.gif"; $icon[1]['url'] = "http://berzerker.net/imgdir/images/ascending.gif"; $icon[1]['fname'] = "ascending.gif"; $icon[2]['url'] = "http://berzerker.net/imgdir/images/descending.gif"; $icon[2]['fname'] = "descending.gif"; $icon[3]['url'] = "http://berzerker.net/imgdir/images/blank.gif"; $icon[3]['fname'] = "blank.gif"; $icon[4]['url'] = "http://berzerker.net/imgdir/images/movie.gif"; $icon[4]['fname'] = "movie.gif"; $icon[5]['url'] = "http://berzerker.net/imgdir/images/text.gif"; $icon[5]['fname'] = "text.gif"; $icon[6]['url'] = "http://berzerker.net/imgdir/images/star_rating.gif"; $icon[6]['fname'] = "star_rating.gif"; $icon[7]['url'] = "http://berzerker.net/imgdir/images/piclens_badge.gif"; $icon[7]['fname'] = "piclens_badge.gif"; $count = 8; for ($ii = 0; $ii < $count; $ii++) { $fname = "$destination/".$icon[$ii]['fname']; if (!is_file($fname)) { $url = $icon[$ii]['url']; //copy($url, $fname); copy_url($url, $fname); } } } function copy_url($url, $fname) { // Open files $src_fp = @fopen($url, 'r') or die ("Cannot open $url for reading
\n"); $dest_fp = @fopen($fname, "w") or die ("Cannot open $fname for writing
\n"); // Copy files while ($buffer = fread($src_fp, 65536)) { fwrite($dest_fp, $buffer); } // Close files fclose($dest_fp); fclose($src_fp); } // Remove ".flist" files for given parent folder function remove_filelists($parent) { global $gOpt; if ($gOpt['debug']) print ("Removing existing Flists for $parent
\n"); if ($parent == ".") $fullparent = CPic::$infopath; else $fullparent = CPic::$infopath . "/$parent"; remove_files($fullparent, "flist", 0); } function remove_files($parent, $extensions, $recursive) { global $gOpt; global $gState; if (isset($recursive) && $recursive) { $subdirs = find_subdirs($parent, $gOpt['exclude']); foreach ($subdirs as $entry) remove_files($entry, $extensions, $recursive); } else if (version_compare(phpversion(), "5.0.0", ">=")) $list = scandir($parent); else $list = local_scandir($parent); foreach ($list as $entry) { if (file_extension_in_list($entry, $extensions)) { $entry = "$parent/$entry"; if (is_file($entry)) { print("  Removing $entry
\n"); unlink($entry); } } } } function remove_thumbs($location) { global $gOpt; if ($gOpt['debug']) print ("Removing thumbnails for $location
\n"); // See if it's there to delete if (!is_dir("$location/.thumbs")) { return; } // Delete it deldir("$location/.thumbs"); // Recreate empty one it mkdir("$location/.thumbs") or die("Unable to create $location/.thumbs
\n"); } function remove_rss($location) { global $gOpt; if ($gOpt['debug']) print ("Removing rss files for $location
\n"); // See if it's there to delete if (!is_dir("$location/.rss")) { return; } // Delete it deldir("$location/.rss"); // Recreate empty one it mkdir("$location/.rss") or die("Unable to create $location/.rss
\n"); } function deldir($dir) { $current_dir = opendir($dir); while($entryname = readdir($current_dir)) { if (is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")) { deldir("${dir}/${entryname}"); } elseif($entryname != "." and $entryname!="..") { unlink("${dir}/${entryname}") or die("Unable to remove ${dir}/${entryname}\n"); } } closedir($current_dir); rmdir(${dir}) or die("Unable to remove ${dir}\n"); } function read_defaults($default_file, &$param) { $fp = file($default_file); foreach ($fp as $line) { $line = trim($line); $token = explode(" ", $line, 2); if (count($token) == 1) $param[$token[0]] = NULL; else if (count($token) == 2) $param[$token[0]] = $token[1]; //list ($key, $value) = explode(" ", $line, 2); //$param[$key] = $value; } } function write_rss($pic_folder) { // Get rss filename $rss_file = $pic_folder->GetRSSFile(); // Exit if file already exists if (is_readable($rss_file)) return; $fp = fopen($rss_file, "w"); if ($fp) { fwrite($fp,"\n"); fwrite($fp,"\n"); fwrite($fp," \n"); add_rss_entries($fp, $pic_folder); fwrite($fp," \n"); fwrite($fp,"\n"); fclose($fp); } } function add_rss_entries($fp, $pic_folder) { $end_idx = $pic_folder->GetCount(); for ($ii = 0; $ii < $end_idx; $ii++) { $pic = $pic_folder->GetInfo($ii); $pic->AddRssEntry($fp); } } function write_defaults($default_file, &$param) { global $gVersion; // Set value of tsize to 120 for versions prior // to actually USING tsize -- 120 was the hardcoded // size in those prior versions, so that behavior and // ignores the value of 200 in the dflt file. if ((version_less_than_v2_3($param['dflt_version'])) && ($param['tsize'] == 200)) $param['tsize'] = 100; $param['dflt_version'] = $gVersion; if (!isset($param['method'])) { $param['method'] = "dir_file"; } if (!isset($param['tsize'])) { $param['tsize'] = 100; } if (!isset($param['per_row'])) { $param['per_row'] = 6; } if (!isset($param['sortby'])) { $param['sortby'] = "fname"; } if (!isset($param['order'])) { $param['order'] = "ascending"; } if (!isset($param['new_window'])) { $param['new_window'] = 0; } if (!isset($param['show_dir'])) { $param['show_dir'] = 1; } if (!isset($param['description_file'])) { $param['description_file'] = "imgdir.txt"; } if (!isset($param['image_cycle'])) { $param['image_cycle'] = 1; } if (!isset($param['per_page'])) { $param['per_page'] = 120; } if (!isset($param['collapse_folders'])) { $param['collapse_folders'] = 0; } if (!isset($param['collapse_row_count'])) { $param['collapse_row_count'] = 2; } if (!isset($param['images'])) { $param['images'] = "jpe,jpg,gif,bmp,jpeg"; } if (!isset($param['images_to_convert'])) { $param['images_to_convert'] = "jp2"; } if (!isset($param['videos'])) { $param['videos'] = "avi,mpg,mpeg,rm,wmv,mov"; } if (!isset($param['link_target'])) { $param['link_target'] = ""; } if (!isset($param['link_label'])) { $param['link_label'] = "Back to Home Page"; } if (!isset($param['title'])) { $param['title'] = ""; } if (!isset($param['sort_link_pic_count'])) { $param['sort_link_pic_count'] = 48; } $param['convert_path'] = get_convert_path(); if (!isset($param['imgsize'])) { $param['imgsize'] = 600; } if (!isset($param['compact'])) { $param['compact'] = 1; } if (!isset($param['immediate_movie_access'])) { $param['immediate_movie_access'] = 1; } if (!isset($param['passwd'])) { $param['passwd'] = ""; } if (!isset($param['debug'])) { $param['debug'] = 0; } if (!isset($param['textfiles'])) { $param['textfiles'] = "txt,log"; } if (!isset($param['exclude'])) { $param['exclude'] = "imgdir.txt"; } if (!isset($param['folder_icon'])) { $param['folder_icon'] = ""; } if (!isset($param['textfile_icon'])) { $param['textfile_icon'] = ""; } if (!isset($param['movie_icon'])) { $param['movie_icon'] = ""; } if (!isset($param['seperator'])) { $param['seperator'] = ":"; } if (!isset($param['include_header'])) { $param['include_header'] = ""; } if (!isset($param['minstars'])) { $param['minstars'] = 2; } if (!isset($param['fname_as_caption'])) { $param['fname_as_caption'] = 1; } if (!isset($param['show_preprocess_link'])) { $param['show_preprocess_link'] = 0; } if (!isset($param['show_rebuildthumb_link'])) { $param['show_rebuildthumb_link'] = 0; } if (!isset($param['show_rebuildrss_link'])) { $param['show_rebuildrss_link'] = 1; } if (!isset($param['five_star_tsize'])) { $param['five_star_tsize'] = $param['tsize']; } if (!isset($param['enable_rss'])) { $param['enable_rss'] = 0; } if (!isset($param['rss_video'])) { $param['rss_video'] = 0; } $fp = fopen($default_file, "w"); while (list($key, $value) = each ($param)) fwrite ($fp, "$key $value\n"); fclose($fp); } function version_less_than_v2_3($version) { $pos = strpos($version, "1."); if ($pos !== false) return true; $pos = strpos($version, "2."); if ($pos !== false) { $pos = strpos($version, ".1"); if ($pos !== false) return true; $pos = strpos($version, ".2"); if ($pos !== false) return true; } return false; } function print_array($array) { print_r($array); print "
"; } function build_target_url() { global $gState; $php_self = $_SERVER['PHP_SELF']; $parent = $gState['parent']; $idx = $gState['idx']; if (isset($gState['idx'])) $target = "$php_self?parent_dir=$parent&idx=$idx"; else $target = "$php_self?parent_dir=$parent"; return $target; } function print_hidden_post_variables($idx) { global $gOpt; global $gState; // WHY DOESN'T THIS SEEM TO SET POST VARIABLES? if ($gOpt['order'] == "descending") print "\n"; else if ($gOpt['order'] == "ascending") print "\n"; // WHY DOESN'T THIS SEEM TO SET POST VARIABLES? if ($gOpt['sortby'] == "fname") print "\n"; else if ($gOpt['sortby'] == "mdate") print "\n"; else if ($gOpt['sortby'] == "fsize") print "\n"; else if ($gOpt['sortby'] == "rating") print "\n"; // WHY DOESN'T THIS SEEM TO SET POST VARIABLES? if (isset($idx)) print "\n"; if (isset($_REQUEST['parent_dir'])) { $value = $_REQUEST['parent_dir']; print "\n"; } if ($gState['annotate']) { print "\n"; } } function print_state() { print("
\n"); print("
\n");
  print("GET:
"); print_r($_GET); print("
POST:
"); print_r($_POST); print("
\n"); print("
\n"); } function parse_args($argv, $argc) { if ($argc > 0) { for ($ii = 1; $ii < $argc; $ii++) { parse_str($argv[$ii], $tmp); $_REQUEST = array_merge($_REQUEST, $tmp); } } } function setup_workspace() { global $gWorkspace; // Set umask to 0 so any files created can be readily deleted by user umask(0); // Create .thumbs subdirectory if (!is_dir("$gWorkspace/.thumbs")) { mkdir("$gWorkspace/.thumbs") or die("Unable to create $gWorkspace/.thumbs
\n"); } // Create .converted subdirectory if (!is_dir("$gWorkspace/.converted")) { mkdir("$gWorkspace/.converted") or die("Unable to create $gWorkspace/.converted
\n"); } // Create .info subdirectory if (!is_dir("$gWorkspace/.info")) { mkdir("$gWorkspace/.info") or die("Unable to create $gWorkspace/.info
\n"); } // Create .rss subdirectory if (!is_dir("$gWorkspace/.rss")) { mkdir ("$gWorkspace/.rss") or die("Unable to create $gWorkspace/.rss
\n"); } // Get icons from www.berzerker.net if not present already get_icons($gWorkspace); } function set_sort_state() { global $gOpt; // Determine current sort order if (isset($_GET['O'])) { if ($_GET['O'] == "D") $gOpt['order'] = "descending"; else if ($_GET['O'] == "A") $gOpt['order'] = "ascending"; } else if (isset($_POST['O'])) { if ($_POST['O'] == "D") $gOpt['order'] = "descending"; else if ($_POST['O'] == "A") $gOpt['order'] = "ascending"; } else if (!isset($gOpt['order'])) $gOpt['order'] = "ascending"; // Determine current sort field if (isset($_REQUEST['C'])) { if ($_REQUEST['C'] == "N") $gOpt['sortby'] = "fname"; else if ($_REQUEST['C'] == "M") $gOpt['sortby'] = "mdate"; else if ($_REQUEST['C'] == "S") $gOpt['sortby'] = "fsize"; else if ($_REQUEST['C'] == "R") $gOpt['sortby'] = "rating"; } if (!isset($gOpt['sortby'])) $gOpt['sortby'] = "fname"; } function set_global_state_variables() { global $gOpt; global $gState; // Set Parent $gState['parent'] = set_parent(); // Set annotate state if (isset($_REQUEST['annotate']) && $_REQUEST['annotate']) $gState['annotate'] = 1; else $gState['annotate'] = 0; if (isset($_REQUEST['idx'])) $gState['idx'] = $_REQUEST['idx']; else $gState['idx'] = -1; // Determine if we are supposed to display folder names at top level or not if (isset($_REQUEST['show_dir'])) { $gState['show_dir'] = 1; } else if (isset($gOpt['show_dir'])) { $gState['show_dir'] = $gOpt['show_dir']; } else { $gState['show_dir'] = 1; } // Determine if we want to collapse folders if (isset($_REQUEST['collapse'])) { $gState['collapse'] = $_REQUEST['collapse']; } else if (isset($gOpt['collapse_folders'])) { $gState['collapse'] = $gOpt['collapse_folders']; } else { $gState['collapse'] = 0; } } function set_parent() { // Set value of parent directory if (isset($_REQUEST['parent_dir'])) { $parent = $_REQUEST['parent_dir']; } else { $parent = "."; } // Validate parent directory if ((($parent[0] == ".") && (strlen($parent) > 1)) || ($parent[0] == "/") || !is_dir($parent) || !is_readable($parent)) { print "$parent is not a valid directory
\n"; print "It is either non-existant, not a directory, a hidden
\n"; print "directory, a restricted directory, or is located outside of
\n"; print "this website.
\n"; exit; } return $parent; } function process_defaults_file() { global $gOpt; global $gDefaultsFile; global $gVersion; if (is_readable($gDefaultsFile)) { read_defaults($gDefaultsFile, $gOpt); if ($gOpt['dflt_version'] != $gVersion) write_defaults($gDefaultsFile, $gOpt); } else { write_defaults($gDefaultsFile, $gOpt); } } function display_setup_instructions_and_exit() { global $gWorkspace; $workspace = $gWorkspace; print "You are using imgdir.php to display your directory contents.
\n"; print "
\n"; print "In order for imgdir to work properly, it must have write-access
\n"; print "to a $workspace directory at the top level of this webpage.
\n"; print "
\n"; print "You may either open up the access to the webpage completely and the
\n"; print "program will create the $workspace directory for you:
\n"; print "
\n"; print "% chmod 777 /var/www/html/mywebsite
\n"; print "
\n"; print "or you can create the $workspace directory yourself and
\n"; print "only open up only it's access:
\n"; print "
\n"; print "% cd /var/www/html/mywebsite
\n"; print "% mkdir $workspace
\n"; print "% chmod 777 $workspace
\n"; print "
\n"; print "The latter method is the most secure.
\n"; print ""; exit; } function show_and_exit($target) { // Yhis function now does minimal checking of converted image i.e. if it // exists, it's displayed. The PreProcess function is used to validate // and verify the saved images. $pic = new CPic($target); if (!is_readable($pic->fname)) { print ("Could not read $pic->fname
\n"); exit; } $resizeIt = $pic->NeedsResizing($width, $height); $convertIt = $pic->NeedsConverting(); if ($convertIt || $resizeIt) { $no_ext = substr($pic->fname, 0, strrpos($pic->fname, ".")); $converted_link = "$gWorkspace/.converted/$no_ext".".jpg"; if (!is_file($converted_link)) { $pic->ConvertImage($converted_link); } header("Location: $converted_link"); exit; } header("Location: $pic->fname"); exit; } function remove_thumbs_and_exit() { global $gWorkspace; remove_thumbs($gWorkspace); if ($gOpt['debug']) { $php_self = $_SERVER['PHP_SELF']; $target = "Location: $php_self"; add_showdir_collapse_flag($target); //add_debug_flag($target); header($target); } exit; } function remove_rss_and_exit() { global $gWorkspace; remove_rss($gWorkspace); if ($gOpt['debug']) { $php_self = $_SERVER['PHP_SELF']; $target = "Location: $php_self"; add_showdir_collapse_flag($target); //add_debug_flag($target); header($target); } exit; } ?> "); } } ?> $opt) { if (isset($_POST[$key])) { $value = $_POST[$key]; print ("Assigning $key value of $value\n
"); $gOpt[$key] = $value; } else { print ("-- $key was not assigned a new value, keeping $gOpt[$key]\n
"); } } foreach ($gOpt as $key => $opt) { print ("== gOpt[$key] = $opt
\n"); } } function edit_settings_and_exit() { $php_self = $_SERVER['PHP_SELF']; print "
\n"; print "\n"; add_hidden("set", "1"); add_checkbox("Compact thumbnail view", "compact"); add_textbox("Thumbnail size (pixels)", "tsize"); add_textbox("5-Star Thumbnail size", "five_star_tsize"); add_textbox("Thumbnails per row", "per_row"); add_textbox("Thumbnails per page", "per_page"); add_space(); $sort_titles['fname'] = "Filename"; $sort_titles['fsize'] = "Filesize"; $sort_titles['mdate'] = "Modified Date"; add_menu("Sort by", $sort_titles, "sort"); $order_titles['descending'] = "Descending"; $order_titles['ascending'] = "Ascending"; add_radio_button("Sort order", $order_titles, "order"); add_space(); add_textbox("Link", "link_target"); add_textbox("Link title", "link_label"); add_textbox("Title", "title"); add_space(); add_checkbox("Open images in new window", "new_window"); add_checkbox("Hide sub-folders", "collapse_folders"); add_textbox("Auto-collapse row count", "collapse_row_count"); add_textbox("Minimum to display sort links ", "sort_link_pic_count"); add_textbox("Max image size", "imgsize"); add_password_box("Password", "passwd"); add_checkbox("Immediate movie access", "immediate_movie_access"); add_space(); add_textbox("Minimum Star rating to display", "minstar"); ?>

\n"); } function add_textbox($title, $key) { global $gOpt; $value = $gOpt[$key]; print("\n"); print(" $title\n"); print(" \n"); add_help($key); print("\n"); } function add_checkbox($title, $key) { global $gOpt; $value = $gOpt[$key]; $checked = $value ? "checked" : ""; print("\n"); print(" $title\n"); print(" \n"); add_help($key); print("\n"); } function add_password_box($title, $key) { print("\n"); print(" $title\n"); print(" \n"); add_help($key); print("\n"); } function add_menu($title, $labels, $name) { global $gOpt; $value = $gOpt[$name]; print("\n"); print(" $title\n"); print(" \n"); } print(" \n"); add_help($key); print("\n"); } function add_space() { } function add_help($key) { print(" \n"); print(" ?\n"); print(" \n"); } class CPicFolder { public $fname_list; public $finfo_list; public $parent; public $sorder; public $sfield; public $minRating; public function __construct($parent, $sfield, $sorder, $minRating) { $this->parent = $parent; $this->sfield = $sfield; $this->sorder = $sorder; $this->minRating = $minRating; $this->Init(); } // CPicFolder::GetFlistFname() public function GetFlistFname() { global $gWorkspace; if ($this->parent == ".") $fname = "$gWorkspace/.info"; else $fname = "$gWorkspace/.info/$this->parent"; $fname .= "/$this->sfield"; $fname .= "_$this->sorder"; if ($this->minRating != 0) $fname .= "_$this->minRating"; $fname .= ".flist"; return $fname; } // CPicFolder::Init() private function Init() { global $gOpt; $img_ext = array_merge(explode(",", $gOpt['images']), explode(",", $gOpt['images_to_convert']), explode(",", $gOpt['videos']), explode(",", $gOpt['textfiles'])); // If a filelist exists that is newer than the folder being indexed, use it $fname = $this->GetFlistFname(); if (is_readable($fname) && (filemtime($fname) > filemtime($this->parent))) { if ($gOpt['debug']) print("Reading existing flist for $this->parent: $fname
\n"); $this->ReadFnameList(); foreach ($this->fname_list as $file) $this->finfo_list[] = new CPic($file); } else { if ($gOpt['debug']) print("Creating new flist for $this->parent: $fname
\n"); $fname_list = find_files ($this->parent, implode(",", $img_ext), $gOpt['exclude']); foreach ($fname_list as $file) { $pic = new CPic($file); if ($pic->IsValid()) { $this->finfo_list[] = $pic; } } if (!isset($this->finfo_list)) return NULL; /* Modified time */ if ($this->sfield == "mdate") { usort($this->finfo_list, ($this->sorder == "descending") ? "MtimeRCmp" : "MtimeCmp"); } else if ($this->sfield == "fsize") { usort($this->finfo_list, ($this->sorder == "descending") ? "FsizeRCmp" : "FsizeCmp"); } else if ($this->sfield == "fname") { usort($this->finfo_list, ($this->sorder == "descending") ? "FnameRCmp" : "FnameCmp"); } else if ($this->sfield == "rating") { usort($this->finfo_list, ($this->sorder == "descending") ? "RateRCmp" : "RateCmp"); } else { usort($this->finfo_list, "FnameCmp"); } foreach ($this->finfo_list as $pic) $this->fname_list[] = $pic->fname; $this->WriteFnameList(); } } private function ReadFnameList() { $fname = $this->GetFlistFname(); $fp = file($fname); foreach ($fp as $line) $this->fname_list[] = trim($line); } private function WriteFnameList() { $fname = $this->GetFlistFname(); $fp = fopen($fname, "w"); foreach ($this->fname_list as $entry) fwrite ($fp, "$entry\n"); fclose($fp); } public function GetInfo($idx) { $finfo = new CPic($this->fname_list[$idx]); return $finfo; } public function GetCount() { return count($this->fname_list); } public function GetRSSFile() { global $gWorkspace; if ($this->parent == ".") $rss_file = "$gWorkspace/.rss/photos.rss"; else $rss_file = "$gWorkspace/.rss/photos_".$this->parent.".rss"; return $rss_file; } public static function PreProcessThumbnails($parent, $recursive, $force) { global $gWorkspace; global $gState; global $gOpt; if ($gOpt['debug']) print("
== Calling PreProcessThumbnails($parent)
\n"); if ($recursive) { $subdirs = find_subdirs($parent, $gOpt['exclude']); if (isset($subdirs)) { foreach ($subdirs as $entry) { make_subdir_folders ($entry); CPicFolder::PreProcessThumbnails($entry, $recursive); } } } $pics = new CPicFolder($parent, "fname", "ascending", 0); foreach ($pics->fname_list as $fname) { $pic = new CPic($fname); $is_image = (!$pic->IsMovie()) && (!$pic->IsTextfile()); if ($is_image) { if ($pic->numstars == 5) $tsize = $gOpt['five_star_tsize']; else $tsize = $gOpt['tsize']; $thumb_link = "$gWorkspace/.thumbs/$fname"; if ($force || !is_readable($thumb_link) || is_wrong_size($thumb_link, $tsize, $tsize) || $pic->IsNewerThan($thumb_link)) { if ($gOpt['debug']) print("Creating thumbnail for $fname
\n"); if (isset($gOpt['compact']) && $gOpt['compact']) { resize_image_square($fname, $thumb_link, $tsize); } else { resize_image($fname, $thumb_link, $tsize, $tsize); } } else { if ($gOpt['debug']) print("Keeping existing thumbnail for $fname
\n"); } } else { if ($gOpt['debug']) print("Skipping thumbnail creation for $fname
\n"); } } if ($gOpt['debug']) print("== Return from PreProcessThumbnails($parent)
\n"); } // Preprocess all image files for given parent. Specifically: // - Delete all .flist files recursively // - if $full is set, create all .flist types and create converted images // - otherwise, create only current .flist types and convert images public static function PreProcess($parent, $full, $recursive) { global $gOpt; global $gWorkspace; if ($gOpt['debug']) print("
== Calling CPicFolder::PreProcess($parent, $full)
\n"); if ($recursive) { $subdirs = find_subdirs($parent, $gOpt['exclude']); if (isset($subdirs)) { foreach ($subdirs as $entry) { make_subdir_folders ($entry); CPicFolder::PreProcess($entry, $full, $recursive); } } } // Remove all filelist files remove_filelists($parent); // Force creation of all info files if ($full) { $pics = new CPicFolder($parent, "fname", "ascending", 0); } else { $pics = new CPicFolder($parent, $gOpt['sortby'], $gOpt['order'], $gOpt['minstars']); } // Force creation of .converted images foreach ($pics->fname_list as $fname) { $pic = new CPic($fname); $pic->PreProcess(); } if ($full) { $pics1 = new CPicFolder($parent, "fname", "ascending", $gOpt['minstars']); $pics2 = new CPicFolder($parent, "fname", "descending", $gOpt['minstars']); $pics3 = new CPicFolder($parent, "mdate", "ascending", $gOpt['minstars']); $pics4 = new CPicFolder($parent, "mdate", "descending", $gOpt['minstars']); $pics5 = new CPicFolder($parent, "fsize", "ascending", $gOpt['minstars']); $pics6 = new CPicFolder($parent, "fsize", "descending", $gOpt['minstars']); } if ($gOpt['debug']) print("== Return from CPicFolder::PreProcess($parent)
\n"); } } // class CPicFolder class CPic { public static $thumbpath = ".imgdir/.thumbs"; public static $infopath = ".imgdir/.info"; public static $convertpath = ".imgdir/.converted"; public $fname; public $fsize; public $mtime; public $height; public $width; public $caption; public $numstars; public function CreateInfoFile($file, $caption, $numstars) { $finfo = CPic::$infopath; $finfo = "$finfo/$file.info"; $param['fsize'] = filesize($this->fname); $param['mtime'] = filemtime($this->fname); list($width, $height) = getimagesize($this->fname); $param['width'] = $width; $param['height'] = $height; if (isset($caption)) $param['caption'] = $caption; else $param['caption'] = ""; if (isset($numstars)) $param['numstars'] = $numstars; else $param['numstars'] = 0; $fp = fopen($finfo, "w"); while (list($key, $value) = each ($param)) fwrite ($fp, "$key $value\n"); fclose($fp); } // CPic:: public function ReadInfoFile() { $file = $this->fname; $finfo = CPic::$infopath; $finfo = "$finfo/$file.info"; if (!is_readable($finfo)) { $this->CreateInfoFile($file, "", 0); } if (!is_readable($finfo)) { print("Error: Couldn't read or create $finfo
\n"); return; } $fp = file($finfo); foreach ($fp as $line) { $line = trim($line); $token = explode(" ", $line, 2); if (count($token) == 1) $param[$token[0]] = NULL; else if (count($token) == 2) { if ($token[0] == 'fsize') $this->fsize = $token[1]; else if ($token[0] == 'mtime') $this->mtime = $token[1]; else if ($token[0] == 'width') $this->width = $token[1]; else if ($token[0] == 'height') $this->height = $token[1]; else if ($token[0] == 'caption') $this->caption = $token[1]; else if ($token[0] == 'numstars') $this->numstars = $token[1]; } } } // CPic:: public function UpdateInfoFile() { $this->ReadInfoFile(); $this->fsize = filesize($this->fname); $this->mtime = filemtime($this->fname); list($width, $height) = getimagesize($this->fname); $this->width = $width; $this->height = $height; $this->Save(); } // CPic:: public function UpdateCaption($caption) { if (isset($caption)) { $this->caption = $caption; $this->Save(); } } // CPic:: public function RateImage($rating) { if ((isset($rating)) && ($rating >= 0) && ($rating <= 5)) { $this->numstars = $rating; $this->Save(); } } // CPic:: public function UpdateMetaData($rating, $caption) { $save = false; if (isset($caption)) { $this->caption = $caption; $save = true; } if (isset($rating) && ($rating != $this->numstars) && ($rating >= 0) && ($rating <= 5)) { $this->numstars = $rating; $save = true; } if ($save) { if ($gOpt['debug']) print("Saving metadata for $this->fname
/n"); $this->Save(); } } // CPic:: public function Save() { $path = CPic::$infopath; $file = $this->fname; $finfo = "$path/$file.info"; if (is_writable($finfo)) { $param['fsize'] = $this->fsize; $param['mtime'] = $this->mtime; $param['width'] = $this->width; $param['height'] = $this->height; $param['caption'] = $this->caption; $param['numstars'] = $this->numstars; $fp = fopen($finfo, "w"); while (list($key, $value) = each ($param)) fwrite ($fp, "$key $value\n"); fclose($fp); } } // CPic::PreProcess() public function PreProcess() { global $gWorkspace; global $gOpt; $origPath = $this->fname; if (is_readable($origPath)) { if ($gOpt['debug']) print("Preprocessing $this->fname
\n"); // Update info file from image file, keeping any caption/rating intact $this->UpdateInfoFile(); $resizeIt = $this->NeedsResizing($width, $height); $convertIt = $this->NeedsConverting(); if ($convertIt || $resizeIt) { $extension = substr($origPath, -3); $no_ext = substr($origPath, 0, strrpos($origPath, ".")); $converted_link = "$gWorkspace/.converted/$no_ext".".jpg"; if (!is_file($converted_link) || is_wrong_size($converted_link, $width, $height) || $this->IsNewerThan($converted_link)) { if ($gOpt['debug']) print("  Converting $origPath to $converted_link
\n"); $this->ConvertImage($converted_link); } else { if ($gOpt['debug']) print("  Keeping already-converted $converted_link
\n"); } } else { if ($gOpt['debug']) print("  Skipping small-enough-image $origPath
\n"); } } } // CPic:: public function __construct($file) { $this->fname = $file; $this->ReadInfoFile(); return; } // CPic:: public static function FnameCmp($a, $b) { print("Called FnameCmp
\n"); return (strcasecmp($a->fname,$b->fname)); } // CPic:: public static function FnameRCmp($a, $b) { print("Called FnameRCmp
\n"); return (strcasecmp($b->fname,$a->fname)); } // CPic:: public static function RateCmp($a, $b) { print("Called FnameRate
\n"); return (strcasecmp($a->numstars,$b->numstars)); } // CPic:: public static function RateRCmp($a, $b) { print("Called FnameRRate
\n"); return (strcasecmp($b->numstars,$a->numstars)); } // CPic:: public static function MtimeCmp($a, $b) { print("Called MtimeCmp
\n"); if ($a->mtime == $b->mtime) return 0; return ($a->mtime < $b->mtime) ? -1 : 1; } // CPic:: public static function MtimeRCmp($a, $b) { print("Called MtimeRCmp
\n"); if ($a->mtime == $b->mtime) return 0; return ($a->mtime > $b->mtime) ? -1 : 1; } // CPic:: public static function FsizeCmp($a, $b) { print("Called FsizeCmp
\n"); // if ($a["fsize"] == $b["fsize"]) return 0; if ($a->fsize == $b->fsize) return (strcasecmp($a->fname,$b->fname)); return ($a->fsize < $b->fsize) ? -1 : 1; } // CPic:: public static function FsizeRCmp($a, $b) { print("Called FsizeRCmp
\n"); // if ($a["fsize"] == $b["fsize"]) return 0; if ($a->fsize == $b->fsize) return (strcasecmp($a->fname,$b->fname)); return ($a->fsize > $b->fsize) ? -1 : 1; } // CPic:: public function NeedsConverting() { global $gOpt; return (file_extension_in_list($this->fname, $gOpt['images_to_convert'])); } // CPic:: public function NeedsResizing(&$width, &$height) { global $gOpt; $width = $this->width; $height = $this->height; if (($gOpt['imgsize'] > 0) && (($width > $gOpt['imgsize']) || ($height > $gOpt['imgsize']))) { $widthRatio = $gOpt['imgsize'] / $width; $heightRatio = $gOpt['imgsize'] / $height; if ($widthRatio < $heightRatio) { $width = round($width * $widthRatio); $height = round($height * $widthRatio); } else { $width = round($width * $heightRatio); $height = round($height * $heightRatio); } return true; } else { return false; } } // CPic:: public function IsNewerThan($fname) { global $gOpt; if ($this->mtime > filemtime($fname)) { if ($gOpt['debug']) { print ("$this->fname is newer than $fname
\n"); } return true; } else { return false; } } // CPic:: public function IsMovie() { global $gOpt; return (file_extension_in_list($this->fname, $gOpt['videos'])); } // CPic:: public function IsTextfile() { global $gOpt; return (file_extension_in_list($this->fname, $gOpt['textfiles'])); } // CPic:: public function IsValid() { global $gOpt; global $gState; if (($this->fsize > 0) && ((isset($_REQUEST['annotate']) && ($_REQUEST['annotate'])) || ($this->numstars == 0) || ($this->numstars >= $gOpt['minstars']))) { return true; } else { return false; } } // CPic:: public function ConvertImage($out) { global $gOpt; if ($this->NeedsResizing($width, $height)) { // Resize the image (which converts it also) resize_image($this->fname, $out, $width, $height); } else { // Get convertion program $prog = get_convert_path(); if (!isset($prog)) die ("ConvertImage: Cannot find image conversion program"); // Convert image $command = "$prog \"$this->fname\" \"$out\""; system($command, $stat); if (($stat != 0) && $gOpt['debug']) print ("ConvertImage: Cannot convert image with:\n
$command\n
"); return $stat; } } // CPic:: public function GetCaption() { global $gOpt; if (isset($this->caption)) $caption = $this->caption; else $caption = ""; if (($caption == "") && ($gOpt['fname_as_caption'])) { $fname = get_fname($this->fname); $caption = $fname; } return $caption; } // CPic:: public function DisplayCaption($allowEdit, $idx) { global $gOpt; $form_target = build_target_url(); if (isset($allowEdit) && $allowEdit) { print("
\n"); // gdg print_hidden_post_variables($idx); // Display Caption print("Caption: caption\"/>\n"); print "\n"; print("
\n"); } else { if ($this->caption != "") print "$this->caption\n"; } } // CPic:: public function AddEntry ($parent_dir, $idx) { global $gWorkspace; global $gOpt; $image = $this->fname; $link = $image; if (!is_file($link)) { return; } // Remove everything before and including last slash $fname = get_fname($image); // Is file a JP2 file? $needs_converting = $this->NeedsConverting(); $is_movie = $this->IsMovie(); $is_textfile = $this->IsTextfile(); $is_image = (!$is_movie) && (!$is_textfile); // Figure out name of thumbnail if ($needs_converting) { $no_ext = substr($link, 0, strrpos($link, ".")); $thumb_link = "$gWorkspace/.thumbs/$no_ext".".jpg"; $border = (isset($gOpt['compact']) && $gOpt['compact']) ? 0 : 1; } else if ($is_movie) { $thumb_link = get_movie_icon(); $border = 0; } else if ($is_textfile) { $thumb_link = get_textfile_icon(); $border = 0; } else { $thumb_link = "$gWorkspace/.thumbs/$link"; $border = (isset($gOpt['compact']) && $gOpt['compact']) ? 0 : 1; } // Create thumbnail -- use minimal logic to validate for efficiency if ($is_image && !is_file($thumb_link)) { // Determing thumbnail size if ($this->numstars == 5) $tsize = $gOpt['five_star_tsize']; else $tsize = $gOpt['tsize']; // Create the thumbnail if (isset($gOpt['compact']) && $gOpt['compact']) { resize_image_square($link, $thumb_link, $gOpt['tsize']); } else { resize_image($link, $thumb_link, $tsize, $tsize); } } // Build the link that the thumbnail will activate global $gOpt; $php_self = $_SERVER['PHP_SELF']; if (($is_movie && immediate_movie_access()) || ($is_textfile && immediate_movie_access())) $fullLink = "$link"; else if ($gOpt['image_cycle']) $fullLink = "$php_self?parent_dir=$parent_dir&idx=$idx"; else $fullLink = "$php_self?show=$link"; // Add on various options to the link so they remain add_showdir_collapse_flag($fullLink); add_sort_flags($fullLink); add_annotation_state($fullLink); // Print the thumbnail and link print " \n"; if ($is_movie || $is_textfile) { print " \"$fname\"/\n"; } else { if (isset($gOpt['compact']) && $gOpt['compact']) { if ($this->numstars == 5) $tsize = $gOpt['five_star_tsize']; else $tsize = $gOpt['tsize']; $width = $tsize; $height = $tsize; } else { list($width, $height) = getimagesize($thumb_link); } if (isset($this->caption) && ($this->caption != "")) print " \"$fname\"caption\"/>\n"; else print " \"$fname\"\n"; } print " \n"; } // CPic:: public function AddRssEntry ($fp) { global $gWorkspace; global $gOpt; $image = $this->fname; if (!is_file($image)) { return; } $link = htmlspecialchars($image); // Remove everything before and including last slash $fname = htmlspecialchars(get_fname($image)); // Is file a JP2 file? $needs_converting = $this->NeedsConverting(); $is_movie = $this->IsMovie(); $is_textfile = $this->IsTextfile(); $is_image = (!$is_movie) && (!$is_textfile); // Skip certain file types if ($gOpt['rss_video']) { if ($is_textfile) return; } else { if (!$is_image) return; } // Figure out name of thumbnail if ($needs_converting) { $no_ext = substr($link, 0, strrpos($link, ".")); $thumb_link = "$gWorkspace/.thumbs/$no_ext".".jpg"; } else if ($is_movie) { $thumb_link = get_movie_icon(); } else if ($is_textfile) { $thumb_link = get_textfile_icon(); } else { $thumb_link = "$gWorkspace/.thumbs/$link"; } $caption = htmlspecialchars($this->GetCaption()); fwrite($fp," \n"); fwrite($fp," $fname\n"); fwrite($fp," $caption\n"); fwrite($fp," ../../$link\n"); fwrite($fp," \n"); fwrite($fp," \n"); fwrite($fp," \n"); } // CPic:: public function DisplayImage($parent, $idx) { global $gWorkspace; // Yhis function now does minimal checking of converted image i.e. if it // exists, it's displayed. The PreProcess function is used to validate // and verify the saved images. // Extract pathname to file and ensure it's readable $origPath = $this->fname; if (!is_readable($origPath)) { print ("Could not read $origPath
\n"); exit; } $resizeIt = $this->NeedsResizing($width, $height); $convertIt = $this->NeedsConverting(); if ($convertIt || $resizeIt) { $no_ext = substr($origPath, 0, strrpos($origPath, ".")); $converted_link = "$gWorkspace/.converted/$no_ext".".jpg"; if (!is_file($converted_link)) { $this->ConvertImage($converted_link); } $fullPath = $converted_link; } else { $fullPath = $origPath; } $fname = get_fname($origPath); $caption = $this->GetCaption(); if ($this->IsMovie()) { $php_self = $_SERVER['PHP_SELF']; $fullLink = "$php_self?show=$fullPath"; $thumb_link = get_movie_icon(); print ""; print "Click to View Movie
"; print "\"$fname\"/
"; print "$caption"; print "
\n"; } else if ($this->IsTextfile()) { $php_self = $_SERVER['PHP_SELF']; $fullLink = "$php_self?show=$fullPath"; $thumb_link = get_textfile_icon(); print ""; print "Click to View File
"; print "\"$fname\"/
"; print "$caption"; print "
\n"; } else { // This code displays image as link with 'tooltips' if ($resizeIt && !$convertIt) { print "\n"; } else { print "\n"; } print "\"$fname\"/
\n"; print "
\n"; if ((isset($_REQUEST['annotate'])) && ($_REQUEST['annotate'])) $allowEdit = true; else $allowEdit = false; $this->DisplayCaption($allowEdit, $idx); print_star_rating($allowEdit, $parent, $idx, $this); } } } // End of class CPic function FnameCmp($a, $b) { return (strcasecmp($a->fname,$b->fname)); } function FnameRCmp($a, $b) { return (strcasecmp($b->fname,$a->fname)); } function RateCmp($a, $b) { return (strcasecmp($a->numstars,$b->numstars)); } function RateRCmp($a, $b) { return (strcasecmp($b->numstars,$a->numstars)); } function MtimeCmp($a, $b) { if ($a->mtime == $b->mtime) return 0; return ($a->mtime < $b->mtime) ? -1 : 1; } function MtimeRCmp($a, $b) { if ($a->mtime == $b->mtime) return 0; return ($a->mtime > $b->mtime) ? -1 : 1; } function FsizeCmp($a, $b) { // if ($a["fsize"] == $b["fsize"]) return 0; if ($a->fsize == $b->fsize) return (strcasecmp($a->fname,$b->fname)); return ($a->fsize < $b->fsize) ? -1 : 1; } function FsizeRCmp($a, $b) { // if ($a["fsize"] == $b["fsize"]) return 0; if ($a->fsize == $b->fsize) return (strcasecmp($a->fname,$b->fname)); return ($a->fsize > $b->fsize) ? -1 : 1; } ?>