getHeader(); // wrap options in an object so they can be passed around easily $options = new Options($svOptions, $bgOptions); print '
( buildgallery.php version 1.9, running under php version '.phpversion().', GD library version '.$options->gdVersion.')
'; // collect data about image files in the $imageFiles object $imageFiles = new ImageFiles($options); $fileNames = $imageFiles->getFileNames(); // attempt to create xml file $galleryXml = new GalleryXml($fileNames, $options); // attempt to create thumbnails $thumbnails = new Thumbnails($fileNames, $options); // close html tags print 'buildgallery script complete
'; print $page->getFooter(); // ----------------------------------------------------------------------------------------------- // Class Options // contains options for simpleviewer and buildgallery class Options { // array svOptions simpleviewer options var $svOptions; // array bgOptions buildgallery options var $bgOptions; // string gdVersion version number of GD library var $gdVersion; // floating point number gdVersionNumber version number of GD library expressed as a number // contents of $gdVersion after the second decimal point will be lost // function Options constructs Options pre-processes path data and gets GD version function Options($svOptions, $bgOptions) { $this->svOptions = $svOptions; $this->bgOptions = $bgOptions; $this->bgOptions['imagePath'] = $this->getPath('imagePath', $this->svOptions['imagePath']); $this->bgOptions['thumbPath'] = $this->getPath('thumbPath', $this->svOptions['thumbPath']); $this->gdVersion = $this->getGDVersion(); $this->gdVersionNumber = (float)$this->gdVersion; } // function getPath extracts image or thumb path from simpleviewer options function getPath($pathName, $path) { // handle default path if ($path == '' && $pathName == 'imagePath') {return 'images';} if ($path == '' && $pathName == 'thumbPath') {return 'thumbs';} // handle correctly formatted path with trailing / $lastChar = substr($path, -1); if ($lastChar == '/') { return substr($path, 0, -1); } return $path; } // function getGDVersion // returns string $gd_version_number // Use output buffering to get results from phpinfo() // without disturbing the page we're in. Output // buffering is "stackable" so we don't even have to // worry about previous or encompassing buffering. function getGDversion() { static $gd_version_number = null; if ($gd_version_number === null) { ob_start(); phpinfo(8); $module_info = ob_get_contents(); ob_end_clean(); if (preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info,$matches)) { $gd_version_number = $matches[1]; } else { $gd_version_number = 0; } } return $gd_version_number; } } // Class ImageFiles // Extracts information about the files in the designated image directory class ImageFiles { // array $fileNames names and dates of files in images directory var $fileNames; // function ImageFiles constructs ImageFiles // parameter object $options simpleviewer and buildgallery options function ImageFiles($options) { $this->fileNames = array(); $imageDir = $options->bgOptions['imagePath']; if (!is_dir($imageDir)) { die('Error: the image directory '.$imageDir.' cannot be found
'); } $folder = @opendir($imageDir); if ($folder === false) { die('Cannot open the '.$imageDir.' directory – check the file permissions.
'); } $jpgCount = 0; $sortMessage = ''; while(false !== ($fileName = readdir($folder))) { if (!$this->isImage($fileName)) {continue;} if ($options->bgOptions['sortImagesByDate']) { $this->fileNames[$fileName] = filemtime($imageDir.'/'.$fileName); $sortMessage = 'Sorting images by date. '; } else { $this->fileNames[$fileName] = $fileName; $sortMessage = 'Sorting images by file name. '; } $jpgCount ++; } if ($jpgCount == 0) { print 'Warning: no jpg images found in '.$imageDir.' folder.
'; return; } else { print ''.$jpgCount.' jpg images found in '.$imageDir.' folder.
'; } // now sort by date modified if ($options->bgOptions['sortInReverseOrder']) { $sortMessage .= 'Sort in reverse order.'; arsort($this->fileNames); } else { $sortMessage .= 'Sort in forward order.'; asort($this->fileNames); } closedir($folder); print ''.$sortMessage.'
'; print 'Cannot open XML document: $file. Change permissions to 0777 for $file and parent directory.
'; } elseif (!@fwrite($file_handle, $this->xml)) { print 'Cannot write to XML document: $file. Change permissions to 0777 for file and parent directory.
'; } else { print '
Successfully created XML document: '.$file.'
'; } @fclose($file_handle); // attempt to change file permissions for later editing by user @chmod($file, 0777); } // function getXmlOptions formats simpleviewer options as an xml tag function getXmlOptions($options) { $xmlOptions = 'Warning: the GD imaging library was not found on this server or it is an old version that does not support jpeg images. Thumbnails will not be created. Either upgrade to a later version of GD or create the thumbnails yourself in a graphics application such as Photoshop.
'; return; } elseif ($options->gdVersionNumber < 2) { print 'Warning: the GD imaging library on this server is version '.$options->gdVersion.'. Thumbnails will be of lower quality. You might want to upgrade to a later version of GD or create the thumbnails yourself in a graphics application such as Photoshop.
'; } elseif ($options->bgOptions['useCopyResized']) { print 'Warning: the useCopyResized setting has been set to true. Thumbnails will be of lower quality. You might want to create the thumbnails yourself in a graphics application such as Photoshop.
'; } print 'Attempting to create thumbnails in '.$thumbDir.' folder:
'; $thumbCount = 0; $thumbList = '