$v) { $tmpArray[] = $v; } return array('Number' => $dirCounter, 'List' => $tmpArray); } // }}} // {{{ printSummary() /** * Print the summary table that displays all images of an album. * * @param string $album Name of the album tp print * the summary from. * @access public * @author Christian Machmeier */ function printSummary($album) { global $simpleViewer; if (empty($album)) { return false; } $i = 0; $xmlData = array(); $sourceData = parseXML($_SESSION['currentDir'] . 'imageData.xml'); foreach ($sourceData as $k => $v) { if ($v['tag'] == 'NAME') { $xmlData[$i]['name'] = $v['value']; } if ($v['tag'] == 'CAPTION') { $xmlData[$i]['caption'] = (!empty($v['value']) ? $v['value'] : ''); $i++; } } $numberOfImages = count($xmlData); echo "\n\n\n"; if ($numberOfImages == 0) { echo ''; } else { $cellCounter = 1; foreach ($xmlData as $k => $v) { echo "\n "; if (($cellCounter % 5) == 0) { echo "\n"; $cellCounter = 0; } $cellCounter++; } if ($cellCounter != 1) { for ($i = 0; $i <= 5 - $cellCounter; $i++) { echo "\n"; } } } echo "\n
This album contains no images.\n
\n"; // Display the "backward" button for every image execpt the first. if ($k != 0) { echo "
"; } // Display the "forward" button for every image execpt the last. if ($k != $numberOfImages-1) { echo "
"; } echo "
\"\"
\"Edit
 
\n"; } // }}} // {{{ convertStr() /** * Convert a string to a non-ambigious string. * * @param string $str String to convert * @return string $str Converted string * @access public * @author Christian Machmeier */ function convertStr($str = null, $markup = false, $albumCreation = false) { if (empty($str)) { return $str; } $str = utf8_decode($str); // The "$markup" parameter is set, when a caption is to be stored. if ($markup) { $str = strip_tags($str, ',
,,,,'); // So this parameter isn't set, when an album is created, therefore // the album name may neither contain any special characters, nor any // markup. } else { $str = strip_tags($str); } // Array to cover all special letters from ISO-8859-1, used for captions and album titles. $replaceChars = array( '&' => '&', '¡' => '¡', '¢' => '¢', '£' => '£', '¤' => '¤', '¥' => '¥', '¦' => '¦', '§' => '§', '¨' => '¨', '©' => '©', 'ª' => 'ª', '«' => '«', '¬' => '¬', '­' => '­', '®' => '®', '¯' => '¯', '°' => '°', '±' => '±', '²' => '²', '³' => '³', '´' => '´', 'µ' => 'µ', '¶' => '¶', '·' => '·', '¸' => '¸', '¹' => '¹', 'º' => 'º', '»' => '»', '¼' => '¼', '½' => '½', '¾' => '¾', '¿' => '¿', 'À' => 'À', 'Á' => 'Á', 'Â' => 'Â', 'Ã' => 'Ã', 'Ä' => 'Ä', 'Å' => 'Å', 'Æ' => 'Æ', 'Ç' => 'Ç', 'È' => 'È', 'É' => 'É', 'Ê' => 'Ê', 'Ë' => 'Ë', 'Ì' => 'Ì', 'Í' => 'Í', 'Î' => 'Î', 'Ï' => 'Ï', 'Ð' => 'Ð', 'Ñ' => 'Ñ', 'Ò' => 'Ò', 'Ó' => 'Ó', 'Ô' => 'Ô', 'Õ' => 'Õ', 'Ö' => 'Ö', '×' => '×', 'Ø' => 'Ø', 'Ù' => 'Ù', 'Ú' => 'Ú', 'Û' => 'Û', 'Ü' => 'Ü', 'Ý' => 'Ý', 'Þ' => 'Þ', 'ß' => 'ß', 'à' => 'à', 'á' => 'á', 'â' => 'â', 'ã' => 'ã', 'ä' => 'ä', 'å' => 'å', 'æ' => 'æ', 'ç' => 'ç', 'è' => 'è', 'é' => 'é', 'ê' => 'ê', 'ë' => 'ë', 'ì' => 'ì', 'í' => 'í', 'î' => 'î', 'ï' => 'ï', 'ð' => 'ð', 'ñ' => 'ñ', 'ò' => 'ò', 'ó' => 'ó', 'ô' => 'ô', 'õ' => 'õ', 'ö' => 'ö', '÷' => '÷', 'ø' => 'ø', 'ù' => 'ù', 'ú' => 'ú', 'û' => 'û', 'ü' => 'ü', 'ý' => 'ý', 'þ' => 'þ', 'ÿ' => 'ÿ' ); if ($albumCreation) { // Array mapping all invalid characters for the directory name. $replaceChars = array ( ' ' => '_', '!' => '', '"' => '', '$' => '', '%' => '', '&' => '', '/' => '', '(' => '', ')' => '', '=' => '', '?' => '', '#' => '', '{' => '', '[' => '', ']' => '', '}' => '', '+' => '', '*' => '', '-' => '', '~' => '', ':' => '', ',' => '', ';' => '', '<' => '', '>' => '', '|' => '', '@' => '', '€' => '', '\\' => '', '^' => '', '°' => '', '¡' => '', '¢' => '', '£' => '', '¤' => '', '¥' => '', '¦' => '', '§' => '', '¨' => '', '©' => '', 'ª' => '', '«' => '', '¬' => '', '­' => '', '®' => '', '¯' => '', '°' => '', '±' => '', '²' => '', '³' => '', '´' => '', 'µ' => '', '¶' => '', '·' => '', '¸' => '', '¹' => '', 'º' => '', '»' => '', '¼' => '', '½' => '', '¾' => '', '¿' => '', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'Ae', 'Å' => 'A', 'Æ' => 'Ae', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'i', 'Í' => 'i', 'Î' => 'i', 'Ï' => 'i', 'Ð' => '', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'Oe', '×' => '', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'Ue', 'Ý' => 'Y', 'Þ' => '', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'ae', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => '', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'oe', '÷' => '', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'ue', 'ý' => 'y', 'þ' => '', 'ÿ' => 'y', "'" => '' ); } // Either which one of the above arrays is specified to be processed, the // given string of characters will now be converted and returned afterwards. foreach ($replaceChars as $k => $v) { $str = str_replace($k, $v, $str); } if ($markup) { utf8_encode($str); } return $str; } // }}} // {{{ deMarkup() /** * Takes a string, converts its markup. * * @param string $str String to convert * @return string $str converted string * @access public * @author Christian Machmeier */ function deMarkup($str=null) { $str = str_replace('<', '<', $str); $str = str_replace('>', '>', $str); $str = str_replace('"', '"', $str); return $str; } // }}} // {{{ setCurrentDir() /** * Sets the current directory after approval as working directory. * * @param string $name Name of the directory to set. * @access public * @author Christian Machmeier */ function setCurrentDir($name) { $_SESSION['currentDir'] = './'; if (!empty($name)) { if (!preg_match('/\.{1,2}/', $name)) { if (!stristr($_SESSION['currentDir'], $name)) { $_SESSION['currentDir'] = './' . $name . '/'; } } } } // }}} // {{{ addItem() /** * Display the form to store and handle the logic of the storage of an * item (album or image) in the file system. * * @param string $mode Item is an image or an album. * @param string $name New/existing image/album. * @access public * @author Christian Machmeier */ function addItem($mode = 'album', $name = null) { global $simpleViewer; $gdInfo = checkGD(); // The form was submitted if (isset($_POST['save'])) { // Convert the album name and create the corresponding directories. if ($mode == 'album') { $old_umask = @umask(0); $albumDirName = convertStr($_POST['name'], false, true); $albumRealName = convertStr($_POST['name'], true, false); if (@mkdir($_SESSION['currentDir'] . $albumDirName, 0777)) { @mkdir($_SESSION['currentDir'] . $albumDirName . '/images', 0777); @mkdir($_SESSION['currentDir'] . $albumDirName . '/thumbs', 0777); $_SESSION['statusMsg'][] = 'The album ' . $albumRealName . ' was created.'; // Attempt to create the XML file. if (!$fileHandle = @fopen($_SESSION['currentDir'] . $albumDirName . '/imageData.xml', 'w')) { $_SESSION['statusMsg'][] = 'Cannot open XML file.'; } // Replace the two empty attributes (imagePath and thumbPath) with their valued twins. $xmlTemplate = $simpleViewer['basicXMLTemplate']; $xmlTemplate = str_replace('imagePath=""', 'imagePath="' . $_SESSION['currentDir'] . $albumDirName . '/images/"', $xmlTemplate); $xmlTemplate = str_replace('thumbPath=""', 'thumbPath="' . $_SESSION['currentDir'] . $albumDirName . '/thumbs/"', $xmlTemplate); $xmlTemplate = str_replace('title=""', 'title="' . $albumRealName . '"', $xmlTemplate); // Write the basic template to the opened file. if (@fwrite($fileHandle, $xmlTemplate) === false) { $_SESSION['statusMsg'][] = 'Cannot write to XML file.'; } // Write the file to disk. @fclose($fileHandle); } else { $_SESSION['statusMsg'][] = 'Could not create the requested directory structure.'; } @umask($old_umask); // Save the image into the corresponding album directory. } else { // The submitted file could be found in memory. if (!empty($_FILES['file']['name'])) { $imageName = convertStr($_FILES['file']['name'], false, true); // Check for GD's availability. if ($gdInfo == false) { $_SESSION['statusMsg'][] = ' Necessary GD image functions are not available.
You will waste harddisk capacity due to non thumbnail creation. Your original image is instead simply copied as preview image. But beware: using this inadvisable approach causes that your image preview within your albums will be very slow. '; // Copy image to its destination if (@copy($_FILES['file']['tmp_name'], $_SESSION['currentDir'] . 'images/' . $imageName)) { $_SESSION['statusMsg'][] = 'The image was saved.'; } else { $_SESSION['statusMsg'][] = 'Could not save the image.'; } // Copy the original image instead as thumbnail. if (@copy($_FILES['file']['tmp_name'], $_SESSION['currentDir'] . 'thumbs/' . $imageName)) { $_SESSION['statusMsg'][] = 'The preview image was saved.'; $captionText = $_POST['name']; if (!empty($_POST['autoCaption'])) { $captionText = '
Open image in new window'; } // Update the XML file. saveImageToXML($_SESSION['currentDir'] . 'images/' . $imageName, $captionText); } else { $_SESSION['statusMsg'][] = 'Could not save the preview image.'; } // The necessary GD functions are available. } else { // Check the uploaded image's file type. if (stristr($_FILES['file']['type'], 'image')) { $format = ''; $errorImage = false; if (stristr($_FILES['file']['type'], 'gif') && $gdInfo['formats']['gif'] == 1) { $format = 'gif'; $destFile = $_SESSION['currentDir'] . 'images/' . str_replace($format , 'jpg', $imageName); } else if (stristr($_FILES['file']['type'], 'jpeg') && $gdInfo['formats']['jpg'] == 1) { $format = 'jpg'; $destFile = $_SESSION['currentDir'] . 'images/' . str_replace($format , 'jpg', $imageName); } else if (stristr($_FILES['file']['type'], 'png') && $gdInfo['formats']['png'] == 1) { $format = 'png'; $destFile = $_SESSION['currentDir'] . 'images/' . str_replace($format , 'jpg', $imageName); } else { $errorImage = true; } // No error occured no upload. if (!$errorImage) { // Create the image. if (createImage($_FILES['file']['tmp_name'], $format, 'images', $destFile)) { $_SESSION['statusMsg'][] = 'The image was saved.'; // Create the thumbnail. if (createImage($_FILES['file']['tmp_name'], $format, 'thumbs', str_replace('images', 'thumbs', $destFile))) { $_SESSION['statusMsg'][] = 'The preview thumbnail was created.'; $captionText = $_POST['name']; if (!empty($_POST['autoCaption'])) { $captionText = 'Open image in new window'; } // Update the XML file. saveImageToXML($_SESSION['currentDir'] . 'images/' . $imageName, $captionText); } else { $_SESSION['statusMsg'][] = 'The preview thumbnail could not be created.'; } // The image could be created. } else { $_SESSION['statusMsg'][] = 'Could not save the image.'; } // The uploaded image was of the wrong file type. } else { $_SESSION['statusMsg'][] = 'Images of type ' . $_FILES['file']['type'] . ' cannot be handled.'; } // The uploaded file was of the wrong file type. } else { $_SESSION['statusMsg'][] = ' Files of type "' . (!empty($_FILES['file']['type']) ? $_FILES['file']['type'] : 'unknown') . '" cannot be processed.'; } } // The submitted file could not be found in memory. } else { $_SESSION['statusMsg'][] = 'Give me an image you want to upload.'; } } } // Display the form. echo '
'; if ($mode == 'image') { echo ' '; } echo '

Add ' . ($mode == 'image' ? $mode : 'an ' . $mode) . '

Name '; if ($mode == 'album') { echo '

"Please click the submit button only once."

'; } else { echo '
Caption
Autolink image '; } echo '
 
Note: '; if ($gdInfo == false) { echo 'You can only upload non-progressive JPEG images.'; } else { echo 'You can upload the following file formats: '; $i = 0; foreach ($gdInfo['formats'] as $k => $v) { if ($v == 1) { if ($i != 0) { echo ', '; } echo '.' . $k; $i++; } } } echo '
'; } // }}} // {{{ deleteItem() /** * Display the form to delete and handle the logic of the deletion of an * item (album or image) in the file system. * * @param string $mode Item is an image or an album. * @param string $name New/existing image/album. * @return boolean * @access public * @author Christian Machmeier */ function deleteItem($mode = 'album', $name = null) { $error = false; // The form was submitted if (isset($_POST['delete'])) { // Delete the album directory recursively. if ($mode == 'album') { if (@deleteDir($_SESSION['currentDir'])) { $_SESSION['statusMsg'][] = "The album " . $_GET['name'] . " was deleted successfully."; } else { $_SESSION['statusMsg'][] = "Couldn't delete the album " . $_GET['name']; } // Delete the image from the corresponding album directory. } else { if (@unlink($_SESSION['currentDir'] . 'images/' . $name) && @unlink($_SESSION['currentDir'] . 'thumbs/' . $name)) { $_SESSION['statusMsg'][] = "The image " . $name . " was deleted successfully."; // Update the XML file. saveImageToXML($_SESSION['currentDir'] . 'images/' . $name, ''); } else { $_SESSION['statusMsg'][] = "Couldn't delete the image " . $name; } } // Display the form. } else { echo '

Delete ' . $mode . '

 


'; } } // }}} // {{{ deleteDir() /** * Delete a directory and the files it's containing recursively. * * @param string $dir Name of directory to delete. * @return boolean * @access public * @author Christian Machmeier */ function deleteDir($dir) { if (empty($dir)) { return false; } $handle = @opendir($dir); while (false !== ($FolderOrFile = @readdir($handle))) { if($FolderOrFile != '.' && $FolderOrFile != '..') { if(is_dir($dir . '/' . $FolderOrFile)) { @deleteDir($dir . '/' . $FolderOrFile); } else { @unlink($dir . '/' . $FolderOrFile); } } } @closedir($handle); if(@rmdir($dir)) { return true; } } // }}} // {{{ renameItem() /** * Display the form to rename/move and handle the logic of the renaming of * an item (album or image) in the file system. * * @param string $mode Item is an image or an album. * @param string $name New/existing image/album. * @return boolean * @access public * @author Christian Machmeier */ function renameItem($mode = 'album', $name) { $error = false; // Rename the album directory. if ($mode == 'album') { if (!empty($name)) { if (!empty($_GET['name']) && (convertStr($name, false, true) == $_GET['name'])) { return true; } if (!is_dir(convertStr($name, false, true))) { if (rename(substr($_SESSION['currentDir'], 0, -1), './' . convertStr($name, false, true))) { setCurrentDir(convertStr($name, false, true)); return true; } else { $_SESSION['statusMsg'][] = "Couldn't rename the album " . $_GET['name']; return false; } } else { return false; } } else { $_SESSION['statusMsg'][] = "You should give me a new name to rename the album " . $_GET['name'] . "."; return false; } // Rename the image in the corresponding album directory. } else { /* * @todo insert useful code here. ;) */ return false; } } // }}} // {{{ gd_info() /** * The function "gd_info()" is available as of PHP version 4.3.0. * The redefinition here does essentially the same as the native function. * * @return mixed array * @access public * @author Christian Machmeier */ if (!function_exists('gd_info')) { function gd_info() { $array = array ( 'GD Version' => '', 'FreeType Support' => 0, 'FreeType Support' => 0, 'FreeType Linkage' => '', 'T1Lib Support' => 0, 'GIF Read Support' => 0, 'GIF Create Support' => 0, 'JPG Support' => 0, 'PNG Support' => 0, 'WBMP Support' => 0, 'XBM Support' => 0 ); $gif_support = 0; ob_start(); phpinfo(8); $info = ob_get_contents(); ob_end_clean(); foreach (explode("\n", $info) as $line) { if (strpos($line, 'GD Version') !== false) { $array['GD Version'] = trim(str_replace('GD Version', '', strip_tags($line))); } if (strpos($line, 'FreeType Support') !== false) { $array['FreeType Support'] = trim(str_replace('FreeType Support', '', strip_tags($line))); } if (strpos($line, 'FreeType Linkage') !== false) { $array['FreeType Linkage'] = trim(str_replace('FreeType Linkage', '', strip_tags($line))); } if( strpos($line, 'T1Lib Support') !== false) { $array['T1Lib Support'] = trim(str_replace('T1Lib Support', '', strip_tags($line))); } if (strpos($line, 'GIF Read Support') !== false) { $array['GIF Read Support'] = trim(str_replace('GIF Read Support', '', strip_tags($line))); } if (strpos($line, 'GIF Create Support') !== false) { $array['GIF Create Support'] = trim(str_replace('GIF Create Support', '', strip_tags($line))); } if (strpos($line, 'GIF Support') !== false) { $gif_support = trim(str_replace('GIF Support', '', strip_tags($line))); } if (strpos($line, 'JPG Support') !== false) { $array['JPG Support'] = trim(str_replace('JPG Support', '', strip_tags($line))); } if (strpos($line, 'PNG Support') !== false) { $array['PNG Support'] = trim(str_replace('PNG Support', '', strip_tags($line))); } if (strpos($line, 'WBMP Support') !== false) { $array['WBMP Support'] = trim(str_replace('WBMP Support', '', strip_tags($line))); } if (strpos($line, 'XBM Support') !== false) { $array['XBM Support'] = trim(str_replace('XBM Support', '', strip_tags($line))); } } if ($gif_support === 'enabled') { $array['GIF Read Support'] = 1; $array['GIF Create Support'] = 1; } if ($array['FreeType Support'] === 'enabled') { $array['FreeType Support'] = 1; } if ($array['T1Lib Support'] === 'enabled') { $array['T1Lib Support'] = 1; } if ($array['GIF Read Support'] === 'enabled') { $array['GIF Read Support'] = 1; } if ($array['GIF Create Support'] === 'enabled') { $array['GIF Create Support'] = 1; } if ($array['JPG Support'] === 'enabled') { $array['JPG Support'] = 1; } if ($array['PNG Support'] === 'enabled') { $array['PNG Support'] = 1; } if ($array['WBMP Support'] === 'enabled') { $array['WBMP Support'] = 1; } if ($array['XBM Support'] === 'enabled') { $array['XBM Support'] = 1; } return $array; } } // }}} // {{{ checkGD() /** * Checks, if the required GD library is available. Returns false on error, * else returns the value of the installed GD version. * * @return mixed * @see gd_info() * @see createImage() * @access public * @author Christian Machmeier */ function checkGD() { $error = false; $gd = array(); $gd['version'] = 0; $gd['formats']['gif'] = 0; $gd['formats']['jpg'] = 0; $gd['formats']['png'] = 0; if (!extension_loaded('gd')) { if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { if (!dl('php_gd.dll')) { $error = true; } } else { if (!dl('gd.so')) { $error = true; } } } if (!$error) { $gdInfo = gd_info(); $gd['version'] = stristr($gdInfo['GD Version'], '2.') ? 2 : 1; $gd['formats']['gif'] = $gdInfo['GIF Read Support']; $gd['formats']['jpg'] = $gdInfo['JPG Support']; $gd['formats']['png'] = $gdInfo['PNG Support']; } return $gd; } // }}} // {{{ createImage() /** * Create a squared thumbnail from an existing image. * * @param string $file Location and name where the file is stored . * @return boolean * @access public * @author Christian Machmeier */ function createImage($file, $format, $mode, $fileDest) { // Get information about the installed GD. $gdInfo = checkGD(); $gdVersion = $gdInfo['version']; if ($gdInfo == false) { return false; } // Ensure the given format is supported. if ($gdInfo['formats'][$format] != 1) { return false; } // Get the image dimensions. $dimensions = @getimagesize($file); $width = $dimensions[0]; $height = $dimensions[1]; // images mode. if ($mode == 'images') { $deltaX = 0; $deltaY = 0; $portionX = $outputX = $width; $portionY = $outputY = $height; $quality = 100; } // thumbs mode. if ($mode == 'thumbs') { $outputX = 45; $outputY = 45; $quality = 85; // The image is of vertical shape. if ($width < $height) { $deltaX = 0; $deltaY = ($height - $width) / 2; $portionX = $width; $portionY = $width; // The image is of horizontal shape. } else if ($width > $height) { $deltaX = ($width - $height) / 2; $deltaY = 0; $portionX = $height; $portionY = $height; // The image is of squared shape. } else { $deltaX = 0; $deltaY = 0; $portionX = $width; $portionY = $height; } } // Get the source image in gif format. if ($format == 'gif') { $imageSrc = @imagecreatefromgif($file); } // Get the source image in jpg format. if ($format == 'jpg') { $imageSrc = @imagecreatefromjpeg($file); } // Get the source image in png format. if ($format == 'png') { $imageSrc = @imagecreatefrompng($file); } // The thumbnail creation with GD1.x functions does the job. if ($gdVersion == 1) { // Create an empty thumbnail image. $imageDest = @imagecreate($outputX, $outputY); // Try to create the thumbnail from the source image. if (@imagecopyresized($imageDest, $imageSrc, 0, 0, $deltaX, $deltaY, $outputX, $outputY, $portionX, $portionY)) { // save the thumbnail image into a file. @imagejpeg($imageDest, $fileDest, $quality); // Delete both image resources. @imagedestroy($imageSrc); @imagedestroy($imageDest); return true; } } // The recommended approach is the usage of the GD2.x functions. if ($gdVersion == 2) { // Create an empty thumbnail image. $imageDest = @imagecreatetruecolor($outputX, $outputY); // Try to create the thumbnail from the source image. if (@imagecopyresampled($imageDest, $imageSrc, 0, 0, $deltaX, $deltaY, $outputX, $outputY, $portionX, $portionY)) { // save the thumbnail image into a file. @imagejpeg($imageDest, $fileDest, $quality); // Delete both image resources. @imagedestroy($imageSrc); @imagedestroy($imageDest); return true; } } return false; } // }}} // {{{ parseXML() /** * Function to actually perform parsing * * @param string $file name of XML file to be parsed. * @access public * @author Christian Machmeier */ function parseXML($xmlFile) { // Of course the XMl file is mandatory. if (empty($xmlFile)) { die('Give me an XML file to read.'); } // Open the XML file for reading. if (!($fileHandle = @fopen($xmlFile, 'r'))) { die("Can't read file: " . $xmlFile); } // Read the XML file. $data = ''; while ($chunk = @fread($fileHandle, 4096)) { $data .= $chunk; } // Initialize the SAX parser. $xmlParser = @xml_parser_create(); // Control the parser behaviour. @xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, false); @xml_parser_set_option($xmlParser, XML_OPTION_SKIP_WHITE, true); // Parse the XML file. $elementArray = array(); $frequencyArray = array(); if (!xml_parse_into_struct($xmlParser, $data, $elementArray, $frequencyArray)) { die('XML Parser error: ' . xml_error_string(xml_get_error_code($xmlParser))); } // All done, clean up! @xml_parser_free($xmlParser); return $elementArray; } // }}} // {{{ saveImageToXML() /** * Save the image name and its caption to the XML file in * the according album directory. * * @param string $image Path to and name of the current image. * @param string $caption Caption of the image to save. * @access public * @author Christian Machmeier */ function saveImageToXML($image, $caption = '') { // Get the image data from the XML file. $imageData = array(); $i = 0; foreach (parseXML($_SESSION['currentDir'] . 'imageData.xml') as $k => $v) { if ($v['tag'] == 'NAME') { $imageData[$i]['name'] = $v['value']; } if ($v['tag'] == 'CAPTION') { $imageData[$i]['caption'] = (!empty($v['value']) ? $v['value'] : ''); $i++; } } // Parse/Create the opening XML tag. $xmlData = ' $v) { $xmlData .= ' ' . $k . '="' . (($k == 'title') ? ((isPhpOfVersion(5) == -1) ? convertStr($v, true, false) : convertStr($v, true, false)) : convertStr($v, true, false)) . '"'; } $xmlData .= '>'; // Get the list of image file from the current album directory. $fileList = getDirList($_SESSION['currentDir'] . 'images/', '', false, 'files'); // Synchronize the filelist with the imageData. $tmpArray = array(); $tmpFileList = $fileList['List']; foreach ($imageData as $xmlKey => $xmlValue) { foreach ($tmpFileList as $key => $imageName) { if ($xmlValue['name'] == $imageName) { $tmpArray[] = $imageName; unset($tmpFileList[$key]); } } } // There might be some files in the directory that weren't added to the // imageData file yet. foreach ($tmpFileList as $tmpKey => $tmpValue) { $tmpArray[] = $tmpValue; } // Get a copy of the synchronized file list. $fileList['List'] = $tmpArray; stripslashes($caption); // Process the file list. foreach ($fileList['List'] as $k => $v) { $noCaption = true; // Write the opening IMAGE tag and store the name of the Image file. $xmlData .= "\n\t\n\t\t" . $v . "\n"; // Check the caption for each image name from the directory and compare // it with the image name found in the XML file. foreach ($imageData as $xmlKey => $xmlValue) { // The image name from the XML file is the same as the one from the // current directory listing. if ($xmlValue['name'] == $v) { $xmlData .= "\t\t"; $noCaption = false; } } // Write the submitted caption for each new image that was just uploaded. if ($noCaption) { $xmlData .= "\t\t"; } $xmlData .= "\n\t\n"; } // Write the closing XML root tag. $xmlData .= ''; // Attempt to create/write the XML file. if (!$fileHandle = @fopen($_SESSION['currentDir'] . 'imageData.xml', 'w')) { $_SESSION['statusMsg'][] = 'Cannot open XML file.'; } // Write the basic XML template to the opened file. if (@fwrite($fileHandle, $xmlData) === false) { $_SESSION['statusMsg'][] = 'Cannot write to XML file.'; } // Write the XML file to disk. @fclose($fileHandle); } // }}} // {{{ getConfig() /** * Load the configuration part of an XML file. * * @param string $xmlFile Name of the configuration file to parse. * @return array * @see parseXML() * @access public * @author Christian Machmeier */ function getConfig($xmlFile) { // Of course the XMl file is mandatory. if (empty($xmlFile)) { die('Give me an XML file to read.'); } // Read and parse the config file. $configData = parseXML($xmlFile); // Return the configuration part of the parsed XML struct. return $configData[0]['attributes']; } // }}} // {{{ configure() /** * Displays a configuration interface. * * @param string $mode gallery or album? * @see getConfig() * @access public * @author Christian Machmeier */ function configure($mode, $renameSuccess = true) { $imageData = ''; if ($mode == 'gallery') { $filestr = 'SimpleViewerConfig.xml'; } else { $filestr = $_SESSION['currentDir'] . 'imageData.xml'; $sourceData = parseXML($filestr); $xmlData = array(); $i = 0; foreach ($sourceData as $k => $v) { if ($v['tag'] == 'NAME') { $xmlData[$i]['name'] = $v['value']; } if ($v['tag'] == 'CAPTION') { $xmlData[$i]['caption'] = (!empty($v['value']) ? $v['value'] : ''); $i++; } } foreach ($xmlData as $k => $v) { $imageData .= "\n\t\n\t\t" . $v['name'] . "\n\t\t\n\t\n"; } } // The form was submitted. if (isset($_POST['saveConfiguration'])) { $error = false; // Check the configData's validity. foreach ($_POST['configData'] as $k => $v) { if (!isset($v)) { $error = true; } } if ($error) { $_SESSION['statusMsg'][] = 'Cannot write configuration file.
Some configuration values have been left empty.'; } else { if ($renameSuccess) { // Read the configuration data and generate the XML file. $simpleViewerConfig = "\n $v) { if ($k == 'imagePath') { $simpleViewerConfig .= ' ' . $k . '="' . $_SESSION['currentDir'] . 'images/"'; } else if ($k == 'thumbPath') { $simpleViewerConfig .= ' ' . $k . '="' . $_SESSION['currentDir'] . 'thumbs/"'; } else if ($k == 'title') { $simpleViewerConfig .= ' ' . $k . '="' . ((isPhpOfVersion(5) == -1) ? convertStr($v, true, false) : convertStr($v, true, false)) . '"'; } else { $simpleViewerConfig .= ' ' . $k . '="' . ( ($k == 'adminPassword') ? strstr($v[2], $v[1]) ? $v[2] : md5($v[1]) : $v) . '"'; } } $simpleViewerConfig .= ">"; $simpleViewerConfig .= $imageData . ""; // Attempt to create the XML file. if (!$fileHandle = @fopen($filestr, 'w')) { $_SESSION['statusMsg'][] = 'Cannot open configuration file.'; } else { // Write the basic template to the opened file. if (@fwrite($fileHandle, $simpleViewerConfig) === false) { $_SESSION['statusMsg'][] = 'Cannot save the configuration.'; } $_SESSION['statusMsg'][] = 'Configuration saved.'; // Write the file to disk. @fclose($fileHandle); } } else { $_SESSION['statusMsg'][] = 'Cannot write configuration file.
Your suggested album name already exists.'; } } } // Display the gallery configuration form. echo '
'; foreach (getConfig($filestr) as $k => $v) { if ($k == 'adminTitle' || $k == 'version' || $k == 'imagePath' || $k == 'thumbPath' || $k == 'emergency') { echo '' . " \n"; } else if ($k == 'maxImageDimension' || $k == 'textColor' || $k == 'frameColor' || $k == 'frameWidth' || $k == 'stagePadding' || $k == 'thumbnailColumns' || $k == 'thumbnailRows' || $k == 'navPosition' || $k == 'navDirection' || $k == 'galleryWidth' || $k == 'galleryHeight') { if ($mode == 'gallery') { echo '' . " \n"; } } } echo ' ' . (($mode == 'album') ? '' : ''); // Process the configuration options. foreach (getConfig($filestr) as $k => $v) { if ($k == 'adminTitle' || $k == 'version' || $k == 'imagePath' || $k == 'thumbPath' || $k == 'emergency') { echo ''; } else if ($k == 'adminUsername') { echo ' '; } else if ($k == 'adminPassword') { echo ' '; } else if ($k == 'maxImageDimension' || $k == 'textColor' || $k == 'frameColor' || $k == 'frameWidth' || $k == 'stagePadding' || $k == 'thumbnailColumns' || $k == 'thumbnailRows' || $k == 'navPosition' || $k == 'navDirection' || $k == 'galleryWidth' || $k == 'galleryHeight') { if ($mode == 'gallery') { echo ''; } else { echo ' '; } } else { echo ' '; } } // Display the rest of the configuration form. echo '

Edit album configuration

' . $k . '
' . $k . '
' . $k . '
' . $k . '
 


'; } // }}} // {{{ moveImage() /** * Read the contents of the album's XML file and move the requested image * forwards or backwards. * * @see printSummary() * @access public * @author Christian Machmeier */ function moveImage() { if (isset($_POST['imageforward_x']) || isset($_POST['imagebackward_x'])) { if (isset($_POST['imageforward_x'])) { $currentKey = $_POST['imagekey']; $newKey = $currentKey + 1; } if (isset($_POST['imagebackward_x'])) { $currentKey = $_POST['imagekey']; $newKey = $currentKey - 1; } $i = 0; $xmlData = array(); $baseArray = array(); $insertArray = array(); $sourceData = parseXML($_SESSION['currentDir'] . 'imageData.xml'); foreach ($sourceData as $k => $v) { if ($v['tag'] == 'NAME') { $xmlData[$i]['name'] = $v['value']; } if ($v['tag'] == 'CAPTION') { $xmlData[$i]['caption'] = (!empty($v['value']) ? $v['value'] : ''); $i++; } } $insertArray[$newKey] = $xmlData[$currentKey]; unset($xmlData[$currentKey]); foreach ($xmlData as $k => $v) { if ($k == $newKey) { $baseArray[$currentKey] = $v; } else { $baseArray[$k] = $v; } } foreach ($insertArray as $k => $v) { $baseArray[$k] = $v; } ksort($baseArray); // Parse/Create the opening XML tag. $xmlData = ' $v) { $xmlData .= ' ' . $k . '="' . (($k == 'title') ? convertStr($v, true, false) : convertStr($v, true, false)) . '"'; } $xmlData .= '>'; // Process the file list. foreach ($baseArray as $k => $v) { // Write the opening IMAGE tag and store the name of the Image file. $xmlData .= "\n\t\n\t\t" . $v['name'] . "\n"; $xmlData .= "\t\t"; $xmlData .= "\n\t"; } // Write the closing XML root tag. $xmlData .= "\n"; // Attempt to create/write the XML file. if (!$fileHandle = @fopen($_SESSION['currentDir'] . 'imageData.xml', 'w')) { $_SESSION['statusMsg'][] = 'Cannot open XML file.'; } // Write the basic XML template to the opened file. if (@fwrite($fileHandle, $xmlData) === false) { $_SESSION['statusMsg'][] = 'Cannot write to XML file.'; } // Write the XML file to disk. @fclose($fileHandle); } } // }}} // {{{ makeSeed() /** * Generate the seed for PHP's built-in function "rand()". * * @access public * @author Christian Machmeier */ function makeSeed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } // }}} // {{{ makeColorVariant() /** * Convert a hexadecimal value, increment oder decrement it, and reconvert it. * * @param int $hex Hexadecimal value. * @param int $step Decimal value. * @return int The modified color. * @access public * @author Christian Machmeier */ function makeColorVariant($hex, $step) { // If the step is zero, there's nothing to do, so exit here. if ($step == 0) { return $hex; } // Set the boundaries for the incrementation/decrementation. $boundary = 255; if ($step < 0) { $boundary = 0; } // Remove the hex-prefix, if any. $hex = (stristr($hex, '0x') ? str_replace('0x', '', $hex) : $hex); // Get the 'red' value, convert it to its decimal counterpart, and add the // '$step' value. $r = hexdec(substr($hex, 0, 2)) + $step; // Convert the decimal value back to its hexadecimal representation, after // checking the value obeys the given boundaries. $r = dechex((($boundary == 0) ? (($r < $boundary) ? $boundary : $r) : (($r > $boundary) ? $boundary : $r))); $r = (('0x' . $r < 0x10) ? '0' . $r : $r); // Same as above, just for the 'green' value. $g = hexdec(substr($hex, 2, 2)) + $step; $g = dechex((($boundary == 0) ? (($g < $boundary) ? $boundary : $g) : (($g > $boundary) ? $boundary : $g))); $g = (('0x' . $g < 0x10) ? '0' . $g : $g); // Same as above, just for the 'blue' value. $b = hexdec(substr($hex, 4, 2)) + $step; $b = dechex((($boundary == 0) ? (($b < $boundary) ? $boundary : $b) : (($b > $boundary) ? $boundary : $b))); $b = (('0x' . $b < 0x10) ? '0' . $b : $b); return $r . $g . $b; } // }}} ?>