| Line 9... |
Line 9... |
| 9 |
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
|
9 |
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
|
| 10 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
10 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
| 11 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
11 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
| 12 |
* @version $Id$
|
12 |
* @version $Id$
|
| 13 |
*/
|
13 |
*/
|
| 14 |
class ExtracteurMeta extends Cel {
|
14 |
class ExtracteurMeta {
|
| Line -... |
Line 15... |
| - |
|
15 |
|
| - |
|
16 |
const DROIT = 0705;
|
| - |
|
17 |
|
| - |
|
18 |
public $config;
|
| - |
|
19 |
public $bdd;
|
| - |
|
20 |
|
| - |
|
21 |
private $idImg = null;
|
| - |
|
22 |
private $metaComplet = null;
|
| - |
|
23 |
private $exif = null;
|
| - |
|
24 |
private $iptc = null;
|
| - |
|
25 |
private $xmp = null;
|
| - |
|
26 |
private $makerNotes = null;
|
| - |
|
27 |
private $metaAutres = null;
|
| - |
|
28 |
|
| - |
|
29 |
|
| - |
|
30 |
public function __construct($config, Conteneur $conteneur = null) {
|
| - |
|
31 |
// Tableau contenant la config de Jrest
|
| - |
|
32 |
$this->config = $config;
|
| - |
|
33 |
|
| - |
|
34 |
$conteneur = is_null($conteneur) ? new Conteneur($this->config) : $conteneur;
|
| - |
|
35 |
$this->bdd = $conteneur->getBdd();
|
| - |
|
36 |
}
|
| 15 |
|
37 |
|
| 16 |
public function executer() {
|
38 |
public function executer($arguments) {
|
| 17 |
try {
|
39 |
$this->idImg = $arguments[0];
|
| 18 |
echo "EXTRACTION des MÉTADONNÉES\n";
|
40 |
echo "EXTRACTION des MÉTADONNÉES\n";
|
| - |
|
41 |
echo "Vérification config : ".$this->verifierConfig()."\n";
|
| - |
|
42 |
|
| - |
|
43 |
$cheminImage = $this->obtenirCheminImageOriginale($this->idImg);
|
| - |
|
44 |
$cmd = "exiftool -X -file:comment $cheminImage";
|
| 19 |
echo "Vérification config : ".$this->verifierConfig();
|
45 |
$metaFile = $this->executerCommandeSysteme($cmd);
|
| 20 |
|
46 |
|
| - |
|
47 |
$remplacement = 'NON';
|
| 21 |
} catch (Exception $e) {
|
48 |
if ($this->neccessiterRemplacement($metaFile) === true) {
|
| - |
|
49 |
$remplacement = 'OUI';
|
| - |
|
50 |
|
| - |
|
51 |
$cmd = "exiftool -X -D -U -b -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -All $cheminImage";
|
| - |
|
52 |
$this->metaComplet = $this->executerCommandeSysteme($cmd);
|
| - |
|
53 |
|
| - |
|
54 |
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -exif:all $cheminImage";
|
| - |
|
55 |
$this->exif = $this->executerCommandeSysteme($cmd);
|
| - |
|
56 |
|
| - |
|
57 |
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -iptc:all $cheminImage";
|
| - |
|
58 |
$this->iptc = $this->executerCommandeSysteme($cmd);
|
| - |
|
59 |
|
| - |
|
60 |
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -xmp:all $cheminImage";
|
| - |
|
61 |
$this->xmp = $this->executerCommandeSysteme($cmd);
|
| - |
|
62 |
|
| - |
|
63 |
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' -makernotes:all $cheminImage";
|
| - |
|
64 |
$this->makerNotes = $this->executerCommandeSysteme($cmd);
|
| - |
|
65 |
|
| - |
|
66 |
$cmd = "exiftool -X -D -c '%.6f' -d '%Y-%m-%d %H:%M:%S' --exif:all --iptc:all --xmp:all --makernotes:all $cheminImage";
|
| - |
|
67 |
$this->metaAutres = $this->executerCommandeSysteme($cmd);
|
| 22 |
$code = $e->getCode();
|
68 |
|
| 23 |
$message = $e->getMessage();
|
69 |
$this->ecrireFichierRdf();
|
| 24 |
die("\n$code : $message\n");
|
70 |
$this->mettreAJourBdd();
|
| - |
|
71 |
}
|
| 25 |
}
|
72 |
echo "Remplacement : $remplacement \n";
|
| Line 26... |
Line 73... |
| 26 |
}
|
73 |
}
|
| 27 |
|
74 |
|
| 28 |
private function verifierConfig() {
|
75 |
private function verifierConfig() {
|
| 29 |
if (empty($this->config['cel']['chemin_images'])) {
|
76 |
if (empty($this->config['cel']['chemin_images'])) {
|
| - |
|
77 |
$message = "Vous devez indiquer le dossier contenant la hiérarchie des images dans le paramètre : ".
|
| 30 |
$message = "Vous devez indiquer le dossier contenant la hiérarchie des images dans le paramètre : ".
|
78 |
"[cel] chemin_images";
|
| 31 |
"[cel] chemin_images";
|
79 |
$code = (string) E_USER_ERROR;
|
| 32 |
throw new Exception($message, E_USER_ERROR);
|
80 |
throw new Exception($message);
|
| 33 |
}
|
81 |
}
|
| Line 34... |
Line 82... |
| 34 |
return 'OK';
|
82 |
return 'OK';
|
| 35 |
}
|
- |
|
| 36 |
|
- |
|
| 37 |
private function extraireMetadonneesExifTool($cheminImage) {
|
- |
|
| 38 |
$metadata = array();
|
83 |
}
|
| 39 |
$res = exec('/usr/bin/exiftool -g -D '.$chemin_image, $metadata);
|
- |
|
| 40 |
|
84 |
|
| 41 |
$metadata_decodees = array();
|
85 |
private function executerCommandeSysteme($commande) {
|
| 42 |
|
- |
|
| 43 |
$categorie = '';
|
86 |
$handle = popen($commande, 'r');
|
| 44 |
foreach($metadata as &$data) {
|
- |
|
| 45 |
if($this->estUnSeparateurCategorieExifTool($data)) {
|
- |
|
| 46 |
$categorie = trim(str_replace('----','',$data));
|
- |
|
| 47 |
} else {
|
- |
|
| 48 |
$data_decodee = $this->parserValeurMetadonneeExifTool($data);
|
- |
|
| 49 |
$cle_metadonnee = str_replace(' ', '', $data_decodee['cle']);
|
- |
|
| 50 |
$metadata_decodees[$categorie][$cle_metadonnee] = $data_decodee;
|
87 |
$metaXml = '';
|
| - |
|
88 |
while (!feof($handle)) {
|
| - |
|
89 |
$metaXml .= fread($handle, 8192);
|
| - |
|
90 |
}
|
| 51 |
$this->id_cle_metadonnees[$cle_metadonnee] = $data_decodee['id'];
|
91 |
fclose($handle);
|
| - |
|
92 |
return $metaXml;
|
| 52 |
}
|
93 |
}
|
| 53 |
}
|
94 |
|
| Line 54... |
Line 95... |
| 54 |
|
95 |
private function obtenirCheminImageRDF($id_image) {
|
| - |
|
96 |
return $this->obtenirCheminImage($id_image, 'RDF', 'xml');
|
| - |
|
97 |
}
|
| - |
|
98 |
|
| - |
|
99 |
private function obtenirCheminImageOriginale($id_image) {
|
| 55 |
return $metadata_decodees;
|
100 |
return $this->obtenirCheminImage($id_image, 'O');
|
| 56 |
}
|
101 |
}
|
| - |
|
102 |
|
| - |
|
103 |
private function obtenirCheminImage($id_image, $format, $extension = 'jpg') {
|
| - |
|
104 |
$nom = $this->convertirIdBddVersNomFichier($id_image, $format, $extension);
|
| 57 |
|
105 |
$cheminDossier = $this->obtenirDossierPourFormat($id_image, $format);
|
| 58 |
public function obtenirCheminImageOriginale($id_image) {
|
106 |
if (file_exists($cheminDossier) === false) {
|
| Line 59... |
Line 107... |
| 59 |
$nom = $this->convertirIdBddVersNomFichier($id_image, 'O');
|
107 |
$this->creerDossier($cheminDossier);
|
| 60 |
$dossier = $this->obtenirDossierPourFormat($id_image,'O');
|
108 |
}
|
| 61 |
return $dossier.'/'.$nom;
|
109 |
return $cheminDossier.'/'.$nom;
|
| 62 |
}
|
110 |
}
|
| 63 |
|
111 |
|
| 64 |
public function convertirIdBddVersNomFichier($id, $format, $extension = 'jpg') {
|
112 |
private function convertirIdBddVersNomFichier($id, $format, $extension) {
|
| Line 65... |
Line 113... |
| 65 |
$id_avec_zeros = sprintf('%09s', $id) ;
|
113 |
$id_avec_zeros = sprintf('%09s', $id) ;
|
| 66 |
$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
|
114 |
$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
|
| 67 |
$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
|
115 |
$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
|
| Line 68... |
Line 116... |
| 68 |
return $nom_fichier;
|
116 |
return $nom_fichier;
|
| 69 |
}
|
117 |
}
|
| 70 |
|
118 |
|
| Line 71... |
Line 119... |
| 71 |
public function obtenirDossierPourFormat($id, $format) {
|
119 |
private function obtenirDossierPourFormat($id, $format) {
|
| 72 |
$chemin_base = $this->config['cel']['chemin_images'];
|
120 |
$chemin_base = $this->config['cel']['chemin_images'];
|
| 73 |
$chemin_sur_serveur = $chemin_base;
|
121 |
$chemin_sur_serveur = $chemin_base;
|
| - |
|
122 |
|
| - |
|
123 |
$id = sprintf('%09s', $id);
|
| - |
|
124 |
$id = wordwrap($id, 3 , '_', true);
|
| - |
|
125 |
list($dossierNiveau1, $dossierNiveau2) = explode('_', $id);
|
| - |
|
126 |
|
| - |
|
127 |
$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
|
| - |
|
128 |
return $chemin_sur_serveur_final;
|
| - |
|
129 |
}
|
| - |
|
130 |
|
| - |
|
131 |
private function creerDossier($cheminDossier) {
|
| - |
|
132 |
umask(0);
|
| - |
|
133 |
if (mkdir($cheminDossier, self::DROIT, true) === false) {
|
| - |
|
134 |
$message = "Problème durant la création du dossier '$cheminDossier'.";
|
| - |
|
135 |
throw new Exception($message);
|
| - |
|
136 |
}
|
| - |
|
137 |
}
|
| - |
|
138 |
|
| - |
|
139 |
private function neccessiterRemplacement($metaXml) {
|
| - |
|
140 |
$meta = new SimpleXMLElement($metaXml);
|
| - |
|
141 |
$rdf = $meta->children('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
|
| - |
|
142 |
$file = $rdf->children('http://ns.exiftool.ca/File/1.0/');
|
| - |
|
143 |
return strpos($file->Comment, "CREATOR: gd-jpeg") === false ? true : false;
|
| - |
|
144 |
}
|
| - |
|
145 |
|
| - |
|
146 |
private function ecrireFichierRdf() {
|
| - |
|
147 |
$cheminRdf = $this->obtenirCheminImageRDF($this->idImg);
|
| - |
|
148 |
file_put_contents($cheminRdf, $this->metaComplet);
|
| 74 |
|
149 |
}
|
| 75 |
$id = sprintf('%09s', $id);
|
150 |
|
| 76 |
$id = wordwrap($id, 3 , '_', true);
|
151 |
private function mettreAJourBdd() {
|