'DateTimeOriginal' ); // $conf['use_iptc'] set to true if you want to use IPTC informations of the // element according to get_sync_iptc_data function mapping, otherwise, set // to false $conf['use_iptc'] = false; // use_iptc_mapping : in which IPTC fields will PhpWebGallery find image // information ? This setting is used during metadata synchronisation. It // associates a phpwebgallery_images column name to a IPTC key $conf['use_iptc_mapping'] = array( 'keywords' => '2#025', 'date_creation' => '2#055', 'author' => '2#122', 'name' => '2#005', 'comment' => '2#120' ); // +-----------------------------------------------------------------------+ // | functions | // +-----------------------------------------------------------------------+ /** * returns informations from IPTC metadata, mapping is done at the beginning * of the function * * @param string $filename * @return array */ function get_iptc_data($filename, $map) { $result = array(); // Read IPTC data $iptc = array(); $imginfo = array(); getimagesize($filename, $imginfo); if (isset($imginfo['APP13'])) { $iptc = iptcparse($imginfo['APP13']); if (is_array($iptc)) { $rmap = array_flip($map); foreach (array_keys($rmap) as $iptc_key) { if (isset($iptc[$iptc_key][0])) { if ($iptc_key == '2#025') { $value = implode(',', array_map('clean_iptc_value',$iptc[$iptc_key])); } else { $value = clean_iptc_value($iptc[$iptc_key][0]); } foreach (array_keys($map, $iptc_key) as $pwg_key) { $result[$pwg_key] = $value; } } } } } return $result; } /** * return a cleaned IPTC value * * @param string value * @return string */ function clean_iptc_value($value) { // strip leading zeros (weird Kodak Scanner software) while ($value[0] == chr(0)) { $value = substr($value, 1); } // remove binary nulls $value = str_replace(chr(0x00), ' ', $value); return htmlentities($value); } function get_sync_iptc_data($file) { global $conf; $map = $conf['use_iptc_mapping']; $datefields = array('date_creation', 'date_available'); $iptc = get_iptc_data($file, $map); foreach ($iptc as $pwg_key => $value) { if (in_array($pwg_key, $datefields)) { if ( preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches)) { $iptc[$pwg_key] = $matches[1].'-'.$matches[2].'-'.$matches[3]; } } } if (isset($iptc['keywords'])) { // official keywords separator is the comma $iptc['keywords'] = preg_replace('/[.;]/', ',', $iptc['keywords']); $iptc['keywords'] = preg_replace('/^,+|,+$/', '', $iptc['keywords']); } $iptc['keywords'] = implode( ',', array_unique( explode( ',', $iptc['keywords'] ) ) ); return $iptc; } /** * returns a float value coresponding to the number of seconds since the * unix epoch (1st January 1970) and the microseconds are precised : * e.g. 1052343429.89276600 * * @return float */ function get_moment() { $t1 = explode(' ', microtime()); $t2 = explode('.', $t1[0]); $t2 = $t1[1].'.'.$t2[1]; return $t2; } /** * returns the number of seconds (with 3 decimals precision) between the * start time and the end time given. * * @param float start * @param float end * @return void */ function get_elapsed_time($start, $end) { return number_format($end - $start, 3, '.', ' ').' s'; } /** * returns an array with all picture files according to $conf['file_ext'] * * @param string $dir * @return array */ function get_pwg_files($dir) { global $conf; $pictures = array(); if ($opendir = opendir($dir)) { while ($file = readdir($opendir)) { if (in_array(get_extension($file), $conf['file_ext'])) { array_push($pictures, $file); if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $file)) { echo 'PWG-WARNING-2: "'.$file.'" : '; echo 'The name of the file should be composed of '; echo 'letters, figures, "-", "_" or "." ONLY'; echo "\n"; } } } } return $pictures; } /** * returns an array with all thumbnails according to $conf['picture_ext'] * and $conf['prefix_thumbnail'] * * @param string $dir * @return array */ function get_thumb_files($dir) { global $conf; $prefix_length = strlen($conf['prefix_thumbnail']); $thumbnails = array(); if ($opendir = @opendir($dir.'/thumbnail')) { while ($file = readdir($opendir)) { if (in_array(get_extension($file), $conf['picture_ext']) and substr($file,0,$prefix_length) == $conf['prefix_thumbnail']) { array_push($thumbnails, $file); } } } return $thumbnails; } /** * returns an array with representative picture files of a directory * according to $conf['picture_ext'] * * @param string $dir * @return array */ function get_representative_files($dir) { global $conf; $pictures = array(); if ($opendir = @opendir($dir.'/pwg_representative')) { while ($file = readdir($opendir)) { if (in_array(get_extension($file), $conf['picture_ext'])) { array_push($pictures, $file); } } } return $pictures; } /** * returns an array with high quality/resolution picture files of a directory * according to $conf['picture_ext'] * * @param string $dir * @return array */ function get_high_files($dir) { global $conf; $pictures = array(); if ($opendir = @opendir($dir.'/pwg_high')) { while ($file = readdir($opendir)) { if (in_array(get_extension($file), $conf['picture_ext'])) { array_push($pictures, $file); } } } return $pictures; } /** * search in $basedir the sub-directories and calls get_pictures * * @return void */ function get_dirs($basedir, $indent, $level) { $fs_dirs = array(); $dirs = ""; if ($opendir = opendir($basedir)) { while ($file = readdir($opendir)) { if ($file != '.' and $file != '..' and $file != '.svn' and $file != 'thumbnail' and $file != 'pwg_high' and $file != 'pwg_representative' and is_dir ($basedir.'/'.$file)) { array_push($fs_dirs, $file); if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $file)) { echo 'PWG-WARNING-1: "'.$file.'" : '; echo 'The name of the directory should be composed of '; echo 'letters, figures, "-", "_" or "." ONLY'; echo "\n"; } } } } // write of the dirs foreach ($fs_dirs as $fs_dir) { $dirs.= "\n".$indent.'
'; switch ($page['action']) { case 'generate' : { $start = get_moment(); $listing = ''."\n"; $listing.= get_dirs('.', '', 0); if ($fp = @fopen("./listing.xml","w")) { fwrite($fp, $listing); fclose($fp); echo 'PWG-INFO-1: listing.xml created in '; echo get_elapsed_time($start, get_moment()); echo "\n"; } else { echo "PWG-ERROR-2: I can't write the file listing.xml"."\n"; } break; } case 'test' : { if (isset($_GET['version'])) { if ($_GET['version'] != $conf['version']) { echo 'PWG-ERROR-4: PhpWebGallery versions differs'."\n"; } else { echo 'PWG-INFO-2: test successful'."\n"; } } else { echo 'PWG-INFO-2: test successful'."\n"; } break; } case 'clean' : { if( @unlink('./listing.xml')) { echo 'PWG-INFO-3 : listing.xml file deleted'."\n"; } else { echo 'PWG-ERROR-3 : listing.xml does not exist'."\n"; } break; } default : { // Menu de lancement pour la mise à jour manuel des sites distant echo '
'; } } echo ''; ?>