#!/usr/bin/php5 isAlbumName) { // C'est un sous-album $filename = $gallery . '/' . $albumitem->isAlbumName . '/' . 'album.dat'; $fd = fopen($filename, "r"); $contents = fread($fd, filesize($filename)); fclose($fd); $album_data = unserialize($contents); $n = sprintf("%02d %s %s", $index, ($albumitem->isHidden()!=0)?"#":"-", html_entity_decode($album_data->fields["title"])); $n = mb_convert_encoding($n, "UTF-8"); processGalleryAlbum($gallery, $albumitem->isAlbumName, $targetdir, $n); } elseif (($albumitem->image->name)) { // C'est une image if ($albumitem->caption) $n = sprintf("%02d %s %s - %s", $index, ($albumitem->isHidden()!=0)?"#":"-", $albumitem->image->name, $albumitem->caption); else $n = sprintf("%02d - %s", $index, $albumitem->image->name); $n = strip_tags($n); $n = str_replace('"',"'", $n); $n = str_replace(':'," ", $n); $n = str_replace('/'," ", $n); $n = str_replace('*',"-", $n); $n = str_replace('?'," ", $n); $n = str_replace("\n"," ", $n); $n = str_replace("\r"," ", $n); $n = substr($n, 0, 80); $n = mb_convert_encoding($n, "UTF-8"); // "ISO-8859-15" // $n = eregi_replace ("[^[:alnum:][:space:].,!çéàèëäïöâêîôüù'-*+§_\(\)\[\]{}&²%$=<>]*", " ", sprintf("%02d - %s - %s", $index, $albumitem->image->name, $albumitem->caption)); if ($display) print "[IMG] " . $album . '/' . $albumitem->image->name . "." . $albumitem->image->type . " -> " . $targetdir . "/" . $n. "\n"; $text = $albumitem->caption; if (array_key_exists('Description', $albumitem->extraFields)) if ($albumitem->extraFields['Description'] != '') $text .= "\n\n" . $albumitem->extraFields['Description']; // Apply modification $in = $gallery . '/' . $album . '/' . $albumitem->image->name . "." . $albumitem->image->type; $out = $targetdir . "/" . $n . "." . $albumitem->image->type; // With exiftool copy($in, $out); if(($text!="") && (!preg_match('/(mov|mpg|avi|wmv)$/i',$out))) { $tmpfname = tempnam("/tmp", "gallery2jpeg"); $handle = fopen($tmpfname, "w"); fwrite($handle, $text); fclose($handle); exec("exiftool -overwrite_original -Comment\<=$tmpfname \"$out\" "); unlink($tmpfname); } // ---- } $index++; } } function main($argc, $argv) { $gallery = $argv[1]; $album = $argv[2]; $targetdir = $argv[3]; if ($album == '.') { $filename = $gallery . '/' . 'albumdb.dat'; $fd = fopen($filename, "r"); $contents = fread($fd, filesize($filename)); fclose($fd); $data = unserialize($contents); foreach($data as $album) { $filename = $gallery . '/' . $album . '/' . 'album.dat'; $fd = fopen($filename, "r"); $contents = fread($fd, filesize($filename)); fclose($fd); $album_data = unserialize($contents); if (!$album_data->fields['parentAlbumName']) { processGalleryAlbum($gallery, $album, $targetdir); } } } else { processGalleryAlbum($gallery, $album, $targetdir); } } main($argc, $argv); ?>