= strlen(CFG_THUMBNAIL_FILENAME_SUFFIX)) { if (substr($filename_base, strlen($filename_base) - strlen(CFG_THUMBNAIL_FILENAME_SUFFIX)) == CFG_THUMBNAIL_FILENAME_SUFFIX) return FALSE; } //Looks good. return TRUE; } //-------------------------------------------------------------------------------- //As a function of the file name, creates the file name for the thumbnail. function file_name_to_thumbnail_name($in_filename) { $extension_start = strrpos($in_filename, "."); //Find position of last "." in string. This should precede the //file extension. if ($extension_start === FALSE) { //"." not found. Should not happen. Filenames were checked in advance. echo "Fatal internal error at line " . __LINE__ . "\n"; exit(1); } $filename_prefix = substr($in_filename, 0, $extension_start); $filename_extension = substr($in_filename, $extension_start); $rv = $filename_prefix . CFG_THUMBNAIL_FILENAME_SUFFIX . $filename_extension; return $rv; } //-------------------------------------------------------------------------------- //Writes the index file preamble to the index file. This is very much //dependent on how the thumbnails will be used. This is currently customized //for what Dave Ashley does. function write_index_file_preamble($handle, $idstring) { fwrite($handle, "<" . "?" . "php\n"); fwrite($handle, "require_once(\"style/std/stdwpstyle.inc\");\n"); fwrite($handle, "?" . ">" . "\n"); fwrite($handle, "<" . "?" . "php\n"); fwrite($handle, " $" . "thispage = new StdWpStyle();\n"); fwrite($handle, "\n"); fwrite($handle, " $" . "thispage->static_page_header_title_std(\"" . $idstring . "\",\n"); fwrite($handle, " \"" . $idstring . "\",\n"); fwrite($handle, " \"\");\n"); fwrite($handle, " $" . "thispage->static_page_photo_thumbnail_explanation(TRUE, TRUE);\n"); fwrite($handle, "?" . ">" . "\n"); for ($i = 0; $i < CFG_INDEX_PARAGRAPH_INDENT; $i++) { fwrite($handle, " "); } fwrite($handle, "\n

\n"); } //-------------------------------------------------------------------------------- //Writes the index file postamble to the index file. This is very much //dependent on how the thumbnails will be used. This is currently customized //for what Dave Ashley does. function write_index_file_postamble($handle) { for ($i = 0; $i < CFG_INDEX_PARAGRAPH_INDENT; $i++) { fwrite($handle, " "); } fwrite($handle, "

\n\n"); fwrite($handle, "<" . "?" . "php\n"); fwrite($handle, " $" . "thispage->static_page_footer_std();\n"); fwrite($handle, "?" . ">" . "\n"); } //-------------------------------------------------------------------------------- //Writes a line to the index file corresponding to a linked larger picture //reprsented by a thumbnail. function write_index_line( $handle, $filename, $thumbnailname, $filename_filesize, $filename_xdim, $filename_ydim, $thumbnailname_filesize, $thumbnailname_xdim, $thumbnailname_ydim) { //dscn1258.jpg (4932338 bytes) //Indent. for ($i = 0; $i < CFG_INDEX_LINK_INDENT; $i++) { fwrite($handle, " "); } fwrite($handle, "\"");"); fwrite($handle, "\n"); } //-------------------------------------------------------------------------------- //Write introductory message. hor_line_thick(); echo CFG_PROGNAME . ", Copyright (c) 2016 David T. Ashley\n"; echo "This program comes with ABSOLUTELY NO WARRANTY; and is licensed under the\n"; echo "MIT License. A copy of this license is provided in the source code\n"; echo "of this program.\n"; hor_line_thin(); //----------------------------------------------------------------------------- //Get the date, time, and PID strings that will be used for the rest of the //script. $scr_datestring = date("Ymd_His"); $scr_pid = getmypid(); if ($scr_pid === FALSE) $scr_pid = 0; //----------------------------------------------------------------------------- //If the index file exists, rename it out of the way. This is to prevent //the loss of information. if (file_exists(CFG_INDEXFILE_NAME)) { rename(CFG_INDEXFILE_NAME, $scr_datestring . "_" . $scr_pid . ".php"); } //----------------------------------------------------------------------------- //Open the index file and write the preamble. $indexfile_handle = fopen(CFG_INDEXFILE_NAME, "w"); if ($indexfile_handle === FALSE) { echo "FATAL: unable to open index file.\n"; exit(1); } write_index_file_preamble($indexfile_handle, $scr_datestring . "_" . $scr_pid); //----------------------------------------------------------------------------- //Get and emit the names of everything in the directory. $file_list = get_file_names_in_dir(); if ($file_list === FALSE) { echo "List of files from PHP function scandir() is empty.\n"; echo "Serious internal error, or nothing to do. Script cannot continue.\n"; hor_line_thick(); exit(1); } else { echo "Files in working directory (unsorted, unfiltered, " . count($file_list) . " files):\n"; for ($i = 0; $i < count($file_list); $i++) echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . "\n"; } hor_line_thin(); //----------------------------------------------------------------------------- //Remove the standard directory entries "." and ".." from the list, and //remove any directories. $temp_list = $file_list; unset($file_list); $n = 0; for ($i = 0; $i < count($temp_list); $i++) { //echo "Checking " . $temp_list[$i] . "\n"; if (strcmp($temp_list[$i], ".") == 0) { //. entry, not a file. } else if (strcmp($temp_list[$i], "..") == 0) { //.. entry, not a file. } else if (is_file($temp_list[$i])) { //This is a regular file. $file_list[] = $temp_list[$i]; $n++; } } if ($n == 0) $file_list = FALSE; unset($n); unset($temp_list); //----------------------------------------------------------------------------- //If there is nothing to do, end the script. if ($file_list === FALSE) { echo "No files to process.\n"; hor_line_thick(); exit(0); } //----------------------------------------------------------------------------- //Sort the list. This is a non-event. The only rationale for sorting is that //it ensures that the same set of files will be processed in the same order, //regardless of the order provided by the underlying OS internals. sort($file_list); //----------------------------------------------------------------------------- //Emit the names we now have. echo "Files in working directory (directory entries removed, sorted, " . count($file_list) . " files):\n"; for ($i = 0; $i < count($file_list); $i++) echo " " . sprintf("[%5d]", $i) . " " . $file_list[$i] . "\n"; hor_line_thin(); //----------------------------------------------------------------------------- //For each file in the list, process it. There are different processing //actions for each one. for ($i = 0; $i < count($file_list); $i++) { if (is_full_sized_image_file_name($file_list[$i])) { $thumbnail_name = file_name_to_thumbnail_name($file_list[$i]); $image_data = getimagesize($file_list[$i]); $thumbnail_data = getimagesize($thumbnail_name); write_index_line( $indexfile_handle, $file_list[$i], $thumbnail_name, filesize($file_list[$i]), $image_data[0], $image_data[1], filesize($thumbnail_name), $thumbnail_data[0], $thumbnail_data[1]); } } //----------------------------------------------------------------------------- //Complete and close up the index file. write_index_file_postamble($indexfile_handle); fclose($indexfile_handle); //-------------------------------------------------------------------------------- echo CFG_PROGNAME . " execution ends.\n"; hor_line_thick(); //-------------------------------------------------------------------------------- //End of File //-------------------------------------------------------------------------------- ?>