Version: gallery 2.0.0 *Contributors* Original Author - Stefan Jahn Rewritten for PmWiki 2.0.beta26 by Jeffrey W Barke - jbarke@emergencydigital.com *License* You can redistribute this file and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or at your option) any later version. http://www.gnu.org/licenses/gpl.html GNU General Public License *Description* Adds a picture viewer with thumbnails preview and automatically generated thumbnails to a PmWiki installation. *Installation* Simply copy this file into the 'cookbook/' subdirectory or some other suitable place and then add: include_once('cookbook/gallery.php'); *Use* Upload the images you want in your gallery to PmWiki. Make sure all images have the prefix "gallery_". To display the gallery, add the directive (:Gallery:) to any wiki page within the group you uploaded the images to. *Attention* This script works only with PmWiki 2.0! */ // Turn EXIF- and IPTC-Functions on (TRUE) and off (FALSE). SDV($gallery_exif, FALSE); SDV($gallery_iptc, FALSE); // Text Variables SDV($gallery_nouploads, "No attachments in this group."); SDV($gallery_nopictures, 'No pictures found.  This could be because the directory contains no pictures or because the pictures were not saved with the prefix "gallery_"'); SDV($gallery_picturename, "Picture #"); SDV($gallery_of, "of"); SDV($gallery_content, "Overview"); SDV($gallery_upload, "Upload picture"); SDV($gallery_originalpicture, "original picture"); SDV($gallery_city, "City"); SDV($gallery_country, "Country"); SDV($gallery_titlestart, '

'); SDV($gallery_titleend, '

'); // Main gallery function function gallery() { global $pagename; global $UploadDir; global $UploadUrlFmt; global $gallery_nouploads; global $gallery_nopictures; global $gallery_upload; // Determine path $server = "http://".$_SERVER['SERVER_NAME']."/"; $directory = str_replace($server, "", $UploadUrlFmt); $directory = str_replace($UploadDir, "", $directory); $script = $_SERVER['PHP_SELF']; $pic = $_GET['pic']; // Wiki-Werte einlesen $array = explode(".", $pagename); $page = $array[1]; $path = $UploadDir."/".$array[0]; $url = $UploadUrlFmt."/".$array[0]."/"; $name = strtolower($array[1]); $suffix = $name."_"; // Test to see if directory exists if (!is_dir($path)) { $ErrMessage = $gallery_nouploads."
"; if ($gallery_upload != "") { $ErrMessage .= ''.$gallery_upload.''."
"; } return $ErrMessage; } $path .= "/"; // Read the specified directory $array = gallery_readdir($path, $suffix); $image = $array[1]; $thumbnail = $array[2]; $original = $array[3]; // Count of images $max = count($image); // Test whether pictures are available if ($max == 0) { $ErrMessage = $gallery_nopictures."
"; if ($gallery_upload != "") { $ErrMessage .= ''.$gallery_upload.''."\n"; } return $ErrMessage; } // Test parameter if (isset($pic)) { if ($pic > $max) $pic = $max; if ($pic < 1) $pic = 1; } // Indicate gallery or single picture. if (!isset($pic)) { $DisplayBlock = gallery_displaythumbnails($thumbnail, $image, $directory, $suffix, $max); } else { $DisplayBlock = gallery_displayimage($image, $directory, $suffix, $max, $pic, $original); } return $DisplayBlock; } //Thumbnail Production Function // param string $image Filename of the image // param string $thumbnail Filename of the thumbnail function gallery_createthumbnail($image, $thumbnail) { // Get information about image $info = getimagesize($image); $width = $info[0]; $height = $info[1]; $type = $info[2]; // Generate thumbnail if ($type == 1) { $new = imagecreatefromgif($image); } elseif ($type == 2) { $new = imagecreatefromjpeg($image); } elseif ($type == 3) { $new = imagecreatefrompng($image); } $newwidth = 100; $newheight = $height/($width/$newwidth); $newimage = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newimage, $new, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); if ($type == 1) imagegif($newimage, $thumbnail); elseif ($type == 2) imagejpeg($newimage, $thumbnail); elseif ($type == 3) imagepng($newimage, $thumbnail); } // Navigation Builder // param integer $pic Current image // param integer $max Total number of images function gallery_navigation($pic, $max) { global $gallery_picturename; global $gallery_content; global $pagename; $script = $_SERVER['PHP_SELF']; $array = explode(".", $pagename); $page = $array[1]; if ($pic > 1) { $DisplayBlock .= '<< '."\n"; $DisplayBlock .= '< '."\n"; } else { $DisplayBlock .= "<< "."\n"; $DisplayBlock .= "< "."\n"; } $DisplayBlock .= ''.$gallery_content.' '."\n"; if ($pic < $max) { $DisplayBlock .= '> '."\n"; $DisplayBlock .= '>>'."\n"; } else { $DisplayBlock .= "> "."\n"; $DisplayBlock .= ">>"."\n"; } flush(); return $DisplayBlock; } // Directory reading function // param string $path Path to the upload directory // param string $suffix Title ? // Return array function gallery_readdir($path, $suffix) { $dir = dir($path); while ($file = $dir->read()) { $filename = $file; if (!stristr($filename, 'thumb_') and stristr($filename, $suffix) and !stristr($filename, 'original_')) { if (stristr($filename, '.jpg')) { $image[] = $path.$filename; $thumbnail[] = $path.'thumb_'.$filename; $original[] = $path.'original_'.$filename; } if (stristr($filename, '.png')) { $image[] = $path.$filename; $thumbnail[] = $path.'thumb_'.$filename; $original[] = $path.'original_'.$filename; } if (stristr($filename, '.gif')) { $image[] = $path.$filename; $thumbnail[] = $path.'thumb_'.$filename; $original[] = $path.'original_'.$filename; } } } $dir->close(); // Inhaltsverzeichnis sort if (isset($image)) { sort($image); sort($thumbnail); sort($original); } $array[1] = $image; $array[2] = $thumbnail; $array[3] = $original; return $array; } // Display Thumbnails function // param array $thumbnail Filenames of the thumbnails // param array $image Filenames of the images // param array $directory Wiki-Verzeichnis // param string $suffix Title ? // param integer $max Total number of images function gallery_displaythumbnails($thumbnail, $image, $directory, $suffix, $max) { global $gallery_picturename; global $gallery_upload; global $gallery_iptc; global $pagename; $script = $_SERVER['PHP_SELF']; $array = explode(".", $pagename); $page = $array[1]; $DisplayBlock = '
'."\n"; for ($i = 0; $i < $max; $i++) { // Produce thumbnail if it is not available if (!file_exists($thumbnail[$i])) { gallery_createthumbnail($image[$i], $thumbnail[$i]); } $size = getimagesize($thumbnail[$i]); getimagesize($image[$i], $info); // Determine IPTC data if (isset($info["APP13"]) and $gallery_iptc) { $iptc = iptcparse($info['APP13']); $iptc_caption = htmlentities($iptc['2#120'][0]); if ($iptc_caption != '') $iptc_caption = ' - '.$iptc_caption; } else { unset($iptc_caption); } // Thumbnail anzeigen $DisplayBlock .= ''.$gallery_picturename.($i+1).$iptc_caption.''."\n"; } $DisplayBlock .= "

"; if ($gallery_upload != "") { $DisplayBlock .= '
'."\n"; $DisplayBlock .= ''.$gallery_upload.''."\n"; $DisplayBlock .= "
"."\n"; } return $DisplayBlock; } // Bild anzeigen // param array $image Filenames of the images // param array $directory Wiki-Verzeichnis // param string $suffix Title ? // param integer $max Total number of images // param integer $pic Nummer des aktuellen Bildes // param array $image Dateinamen der original Bilder function gallery_displayimage($image, $directory, $suffix, $max, $pic, $original) { global $gallery_picturename; global $gallery_of; global $gallery_titlestart; global $gallery_titleend; global $gallery_originalpicture; global $gallery_city; global $gallery_country; global $gallery_exif; global $gallery_iptc; $size = getimagesize($image[$pic-1], $info); // If $gallery_exif is true, determine EXIF-Data if ($gallery_exif) { $exif = exif_read_data($image[$pic-1]); $exif_date = htmlentities($exif['DateTime']); $exif_make = htmlentities($exif['MAKE'][0]); $exif_camera = htmlentities($exif['MODEL'][0]); } // If $gallery_iptc is true, determine IPTC-Data if (isset($info["APP13"]) and $gallery_iptc) { $iptc = iptcparse ($info['APP13']); $iptc_program = htmlentities($iptc['2#065'][0]); $iptc_jobid = htmlentities($iptc['2#022'][0]); $iptc_status = htmlentities($iptc['2#007'][0]); $iptc_copyright = htmlentities($iptc['2#116'][0]); $iptc_specialinstructions = htmlentities($iptc['2#040'][0]); $iptc_headline = htmlentities($iptc['2#105'][0]); $iptc_captionwriter = htmlentities($iptc['2#122'][0]); $iptc_caption = htmlentities($iptc['2#120'][0]); $iptc_originaltransmissionreference = htmlentities($iptc['2#103'][0]); $iptc_countrycode = htmlentities($iptc['2#100'][0]); $iptc_country = htmlentities($iptc['2#101'][0]); $iptc_state = htmlentities($iptc['2#095'][0]); $iptc_sublocation = htmlentities($iptc['2#092'][0]); $iptc_city = htmlentities($iptc['2#090'][0]); $iptc_objectname = htmlentities($iptc['2#005'][0]); $iptc_source = htmlentities($iptc['2#115'][0]); $iptc_credit = htmlentities($iptc['2#110'][0]); $iptc_bylinetitle = htmlentities($iptc['2#085'][0]); $iptc_byline = htmlentities($iptc['2#080'][0]); } else { unset($iptc_program); unset($iptc_jobid); unset($iptc_status); unset($iptc_copyright); unset($iptc_specialinstructions); unset($iptc_headline); unset($iptc_captionwriter); unset($iptc_caption); unset($iptc_originaltransmissionreference); unset($iptc_countrycode); unset($iptc_country); unset($iptc_state); unset($iptc_sublocation); unset($iptc_city); unset($iptc_objectname); unset($iptc_source); unset($iptc_credit); unset($iptc_bylinetitle); unset($iptc_byline); } $DisplayBlock = $gallery_titlestart.$gallery_picturename.($pic).' '.$gallery_of.' '.$max.$gallery_titleend."\n"; // Show image $DisplayBlock .= '
'."\n"; $DisplayBlock .= ''.$gallery_picturename.($pic).' '.$gallery_of.' '.$max.''."\n"; $DisplayBlock .= '
'."\n"; // Show image description if ($exif_date != "" and $gallery_exif) { $DisplayBlock .= $exif_date."\n"; $DisplayBlock .= "
"."\n"; } if ($gallery_iptc) { if ($iptc_caption != "") { $DisplayBlock .= $iptc_caption."\n"; $DisplayBlock .= "
"."\n"; } if ($iptc_city != "") { $DisplayBlock .= $gallery_city.": ".$iptc_city; if ($iptc_country != '') $DisplayBlock .= ", ".$iptc_country; $DisplayBlock .= "
"."\n"; } elseif ($iptc_country != '') { $DisplayBlock .= $gallery_country.': '.$iptc_country."\n"; $DisplayBlock .= '
'."\n"; } if ($iptc_sublocation != '') { $DisplayBlock .= $iptc_sublocation."\n"; $DisplayBlock .= '
'."\n"; } } $DisplayBlock .= "
"."\n"; // Show Navigation $DisplayBlock .= gallery_navigation($pic, $max); if (file_exists($original[$pic-1])) { $DisplayBlock .= '
'."\n"; $DisplayBlock .= ''.$gallery_originalpicture.''."\n"; } $DisplayBlock .= "
"."\n"; return $DisplayBlock; } Markup("embeddedgallery", "directives", "/\\(:Gallery:\\)/e", "gallery()"); ?>