Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1149 gduche 1
<?php
2
 
3
class MigrationImages extends Cel {
4
 
5
	const bdd_cel_migration = 'cel';
6
	const bdd_utilisateurs = 'cel_old';
7
 
8
	const separateur_champs_metadonnees = ';';
9
	const separateur_valeurs_metadonnees = ':';
10
 
11
	private $id_cle_metadonnees = array();
12
 
13
	/** Tableau associatif permettant de stocker l'avancement dans une boucle.
14
	* La clé est un md5 du message à afficher au démarrage de la boucle.
15
	* @var array
16
	*/
17
	private static $avancement = array();
18
 
19
	const dry_run = true;
20
 
21
	private $tableau_utilisateurs = array();
22
	private $tableau_observations = array();
23
	private $tableau_mots_cles = array();
24
 
25
	private $tableau_nouveau_ancien = array(
26
		'id_image' => 'ci_id_image',
27
		'ordre' =>'ci_ordre',
28
		'ce_utilisateur' => 'traiterIdentifiantUtilisateur',
29
		'prenom_utilisateur' => 'traiterPrenomUtilisateur',
30
		'nom_utilisateur' => 'traiterNomUtilisateur',
31
		'courriel_utilisateur' => 'ci_ce_utilisateur',
32
		'hauteur' => 'ci_meta_height',
33
		'largeur' => 'ci_meta_width',
34
		'appareil_fabriquant' => 'ci_meta_make',
35
		'appareil_modele' => 'ci_meta_model',
36
		'date_prise_de_vue' => 'ci_meta_date_time',
37
		'note_qualite' => 'ci_note_image',
38
		'mots_cles_texte' => 'traiterMotsClesTexte',
39
		'commentaire' => 'ci_meta_comment',
40
		'nom_original' => 'ci_nom_original',
41
		'md5' => 'ci_md5',
42
		'meta_exif' => 'traiterExif',
43
		'meta_iptc' => 'traiterIptc',
44
		'meta_xmp' => 'traiterXmp',
45
		'meta_makernote' => 'traiterMakernote',
46
		'date_modification' => 'ci_meta_date',
47
		'date_creation' => 'ci_meta_date_ajout'
48
	);
49
 
50
	private $champs_exifs_non_gardes = array(
51
		'ci_meta_x_resolution',
52
		'ci_meta_y_resolution',
53
		'ci_meta_gps',
54
		'ci_meta_user_comment',
55
		'ci_meta_exif_exposure_time',
56
		'ci_meta_exif_f_number',
57
		'ci_meta_exif_exif_version',
58
		'ci_meta_exif_compressed_bits_per_pixel',
59
		'ci_meta_exif_shutter_speed_value',
60
		'ci_meta_exif_aperture_value',
61
		'ci_meta_exif_exposure_bias_value',
62
		'ci_meta_exif_max_aperture_value',
63
		'ci_meta_exif_metering_mode',
64
		'ci_meta_exif_light_source',
65
		'ci_meta_exif_flash',
66
		'ci_meta_exif_focal_length',
67
		'ci_meta_exif_flash_pix_version',
68
		'ci_meta_exif_color_space',
69
		'ci_meta_exif_interoperability_offset',
70
		'ci_meta_exif_focal_plane_x_resolution',
71
		'ci_meta_exif_focal_plane_y_resolution',
72
		'ci_meta_exif_focal_plane_resolution_unit',
73
		'ci_meta_exif_sensing_method',
74
		'ci_meta_exif_file_source',
75
		'ci_meta_exif_custom_rendered',
76
		'ci_meta_exif_exposure_mode',
77
		'ci_meta_exif_white_balance',
78
		'ci_meta_exif_digital_zoom_ratio',
79
		'ci_meta_exif_scene_capture_type',
80
		'ci_meta_exif_gain_control',
81
		'ci_meta_exif_contrast',
82
		'ci_meta_exif_saturation',
83
		'ci_meta_exif_sharpness',
84
		'ci_meta_exif_subject_distance_range'
85
	);
86
 
87
	private $champs_iptc_non_gardes = array(
88
		'ci_meta_iptc_category',
89
		'ci_meta_iptc_by_line',
90
		'ci_meta_iptc_by_line_title',
91
		'ci_meta_iptc_city',
92
		'ci_meta_iptc_sub_location',
93
		'ci_meta_iptc_province_state',
94
		'ci_meta_iptc_country_primary_location_code',
95
		'ci_meta_iptc_country_name',
96
		'ci_meta_iptc_headline',
97
		'ci_meta_iptc_credit',
98
		'ci_meta_iptc_copyright_notice',
99
		'ci_meta_iptc_contact'
100
	);
101
 
102
	private $champs_divers_non_gardes = array(
103
		'ci_publiable_eflore',
104
		'ci_meta_mots_cles'
105
	);
106
 
107
	/**
108
	* Utiliser cette méthode dans une boucle pour afficher un message suivi du nombre de tour de boucle effectué.
109
	* Vous devrez vous même gérer le retour à la ligne à la sortie de la boucle.
110
	*
111
	* @param string le message d'information.
112
	* @param int le nombre de départ à afficher.
113
	* @return void le message est affiché dans la console.
114
	*/
115
	protected function afficherAvancement($message, $depart = 0) {
116
	if (! isset(self::$avancement[$message])) {
117
	self::$avancement[$message] = $depart;
118
	echo "$message : ";
119
 
120
	$actuel =& self::$avancement[$message];
121
	echo $actuel++;
122
	} else {
123
	$actuel =& self::$avancement[$message];
124
 
125
		// Cas du passage de 99 (= 2 caractères) à 100 (= 3 caractères)
126
		$passage = 0;
127
		if (strlen((string) ($actuel - 1)) < strlen((string) ($actuel))) {
128
		$passage = 1;
129
	}
130
 
131
		echo str_repeat(chr(8), (strlen((string) $actuel) - $passage));
132
		echo $actuel++;
133
	}
134
	}
135
 
136
	/**
137
	 * Méthode appelée avec une requête de type GET.
138
	 */
139
	public function getElement($params) {
140
 
141
		$this->id_cle_metadonnees = array_merge($this->tableau_ids_tags_exif, $this->tableau_ids_tags_iptc);
142
 
143
		$this->getUtilisateurs();
144
		$this->getMotsCles();
145
		$this->getObservations();
146
 
147
		echo '|| Migration des images ||'."\n";
148
		//$this->migrerImages();
149
		echo "\n"."\n"."\n";
150
 
151
		echo '|| Migration des liaisons obs images ||'."\n";
152
		$this->migrerLiaisonsObsImages();
153
		echo "\n"."\n"."\n";
154
	}
155
 
156
	private function getUtilisateurs() {
157
 
158
		$requete_selection_utilisateurs = 'SELECT U_ID as id, U_MAIL as mail, U_NAME as nom, U_SURNAME as prenom FROM '.self::bdd_utilisateurs.'.annuaire_tela';
159
		$tableau_utilisateurs = $this->executerRequete($requete_selection_utilisateurs);
160
 
161
		foreach( $tableau_utilisateurs as &$utilisateur) {
162
			$this->tableau_utilisateurs[$utilisateur['mail']] = $utilisateur;
163
		}
164
 
165
	}
166
 
167
	private function getMotsCles() {
168
 
169
		$requete_selection_mots_cles = 'SELECT cmc_id_proprietaire as id_utilisateur, cmc_id_mot_cle_utilisateur as id_mot_cle, cmc_mot_cle as mot_cle FROM cel_mots_cles_images';
170
		$tableau_mots_cles = $this->executerRequete($requete_selection_mots_cles);
171
 
172
		foreach($tableau_mots_cles as &$mot_cle) {
173
			$this->tableau_mots_cles[$mot_cle['id_utilisateur']][$mot_cle['id_mot_cle']] = $mot_cle;
174
		}
175
	}
176
 
177
	private function getObservations() {
178
		$pas = 5000;
179
 
180
		$nObs = "SELECT COUNT(*) AS nb FROM cel_inventory";
181
		$resultatNbObs = $this->executerRequete($nObs);
182
		$nbObs = $resultatNbObs[0]['nb'];
183
 
184
		for ($i = 0; $i < 230000; $i += $pas ) {
185
			$requete_selection_observations = 'SELECT id, ordre, identifiant FROM cel_inventory LIMIT '.$i.", $pas";
186
			$tableau_observations = $this->executerRequete($requete_selection_observations);
187
			foreach($tableau_observations as &$obs) {
188
				$this->tableau_observations[$obs['identifiant']][$obs['ordre']] = $obs['id'];
189
			}
190
 
191
			//$this->afficherAvancement('Selection des observations (par '.$pas.' )', $i);
192
			echo "\n obs : ".$i;
193
		}
194
 
195
 
196
 
197
	}
198
 
199
	public function executerRequeteSimple($requete) {
200
		// Fonction de commodité pour afficher les requetes au lieu de les executer
201
		if (self::dry_run) {
202
			echo str_replace('),','),'."\n", $requete)."\n";
203
			return true;
204
		} else {
205
			return parent::executerRequeteSimple($requete);
206
		}
207
	}
208
 
209
	private function migrerImages() {
210
 
211
		$debut = 0;
212
		$pas = 200;
213
		$fin = 150000;
214
 
215
		for ($i = $debut; $i <= $fin ; $i += $pas) {
216
			$requete_selection_images = 'SELECT * FROM cel_images '.
217
											'ORDER BY ci_id_image ASC LIMIT '.$i.','.$pas;
218
 
219
			$images = $this->requeter($requete_selection_images);
220
 
221
			$requete_insertion_images = 'INSERT INTO '.self::bdd_cel_migration.'.cel_images (';
222
			foreach ($this->tableau_nouveau_ancien as $nouveau_champ => $ancien_champ) {
223
				$requete_insertion_images .= $nouveau_champ.',';
224
			}
225
			$requete_insertion_images = rtrim($requete_insertion_images, ',');
226
 
227
			$requete_insertion_images = $requete_insertion_images.') VALUES ';
228
 
229
			if (is_array($images)) {
230
 
231
				$nb_images_a_traiter = count($images);
232
 
233
				foreach($images as $image) {
234
 
235
					$nouvelle_image = $this->traiterLigneImage($image);
236
 
237
					$nouvelle_image = array_map(array($this,'proteger'),$nouvelle_image);
238
					$requete_insertion_images .= '('.join(',',array_values($nouvelle_image)).'),';
239
				}
240
 
241
				$requete_insertion_images = rtrim($requete_insertion_images, ',');
242
				$migration_images = $this->executer($requete_insertion_images);
243
 
244
				if (!$migration_images) {
245
					echo 'la migration des images '.$i.' à '.($i+$nb_images_a_traiter).' a échoué '."\n";
246
				} else {
247
					echo 'migration des images '.$i.' à '.($i+$nb_images_a_traiter).' effectuée '."\n";
248
				}
249
			}
250
 
251
			if(count($images) < $pas) {
252
				echo 'Fin de la migration des images '."\n";
253
				return;
254
			}
255
		}
256
	}
257
 
258
	private function migrerLiaisonsObsImages() {
259
		$debut = 0;
260
		$pas = 200;
261
		$fin = 50000;
262
 
263
		for ($i = $debut; $i <= $fin ; $i += $pas) {
264
			$requete_selection_liaisons = 'SELECT * FROM cel_obs_images LIMIT '.$i.','.$pas;
265
			$tableau_liaisons = $this->executerRequete($requete_selection_liaisons);
266
 
267
			$requete_migration_liaison = 'INSERT INTO '.self::bdd_cel_migration.'.cel_obs_images '.
268
											'(ce_image, ce_utilisateur, ce_observation, date_liaison) '.
269
											'VALUES ';
270
 
271
			$sous_requete_insertion = '';
272
 
273
			foreach($tableau_liaisons as &$liaison) {
274
 
275
				$mail_utilisateur = $liaison['coi_ce_utilisateur'];
276
				$utilisateur = $mail_utilisateur;
277
 
278
				if (isset($this->tableau_utilisateurs[$mail_utilisateur])) {
279
					$utilisateur =  $this->tableau_utilisateurs[$mail_utilisateur]['id'];
280
				}
281
 
282
				$id_obs = $liaison['coi_ce_observation'];
283
 
284
				if (isset($this->tableau_observations[$mail_utilisateur][$id_obs])) {
285
					$id_obs =  $this->tableau_observations[$mail_utilisateur][$id_obs];
286
 
287
					$sous_requete_insertion .= '('.$this->proteger($liaison['coi_ce_image']).','.
288
						$this->proteger($utilisateur).','.
289
						$this->proteger($id_obs).','.
290
						$this->proteger($liaison['coi_date_liaison']).
291
					'),';
292
				} else {
293
					echo 'l\'obs '.$id_obs.' n\'existe pas pour l\'utilisateur '.$mail_utilisateur."\n";
294
				}
295
			}
296
 
297
			$sous_requete_insertion = rtrim($sous_requete_insertion,',');
298
			$requete_migration_liaison = $requete_migration_liaison.$sous_requete_insertion;
299
 
300
			$migration_liaison = $this->executerRequeteSimple($requete_migration_liaison);
301
 
302
			if (!$migration_liaison) {
303
				echo 'la migration des liaisons obs images a échoué ! ';
304
			} else {
305
				echo 'migration des liaisons obs images réussie ';
306
			}
307
		}
308
	}
309
 
310
	private function traiterLigneImage($image) {
311
 
312
		$nouvelle_image = array();
313
 
314
		foreach ($this->tableau_nouveau_ancien as $nouveau_champ_image => $ancien_champ_image) {
315
 
316
			if ($this->estUnChampATraiter($ancien_champ_image)) {
317
				if (method_exists($this,$ancien_champ_image)) {
318
					$nouvelle_image[$nouveau_champ_image] = $this->$ancien_champ_image($image);
319
				} else {
320
					echo 'methode manquante : '.$ancien_champ_image."\n";
321
					$nouvelle_image[$nouveau_champ_image] = '';
322
				}
323
 
324
			} else {
325
				$nouvelle_image[$nouveau_champ_image] = $image[$ancien_champ_image];
326
			}
327
		}
328
 
329
		return $nouvelle_image;
330
	}
331
 
332
	private function estUnChampATraiter($champ) {
333
 
334
		return strpos($champ, 'traiter') !== false;
335
	}
336
 
337
	private function traiterMotsClesTexte($ligne_image) {
338
 
339
		$mail_image = $ligne_image['ci_ce_utilisateur'];
340
		$retour = $ligne_image['ci_meta_mots_cles'];
341
 
342
		if (isset($this->tableau_mots_cles[$mail_image])) {
343
 
344
			$mots_cles_tableau = $this->parserMotsCles($mail_image, $ligne_image['ci_meta_mots_cles'], ',');
345
			$retour =  join(';',$mots_cles_tableau);
346
			$retour = ltrim($retour,';;') ;
347
		}
348
 
349
		return $retour;
350
	}
351
 
352
	private function parserMotsCles($utilisateur, $mot_cles, $separateur = ',') {
353
 
354
		$tableau_mots_cles = explode($separateur,$mot_cles);
355
		$tableau_mots_cles_formates = array();
356
 
357
		foreach($tableau_mots_cles as $mot_cle) {
358
 
359
			$mot_cle = str_replace($separateur.$separateur,'',$mot_cle);
360
			$mot_cle = str_replace('null','',$mot_cle);
361
 
362
			if ($this->estUnIdentifiantMotCle($mot_cle)) {
363
 
364
				// certains mots clés mal formatés contiennent des virgules
365
				if (strpos($mot_cle,',') !== false) {
366
					$tab_mot_cle_mal_formate = explode(',',$mot_cle);
367
 
368
					foreach ($tab_mot_cle_mal_formate as $mot_cle_mal_formate) {
369
						if ($this->estUnIdentifiantMotCle($mot_cle_mal_formate)) {
370
							$tableau_mots_cles_formates[$mot_cle_mal_formate] = $this->tableau_mots_cles[$utilisateur][$mot_cle_mal_formate]['mot_cle'];
371
						}
372
					}
373
				} else {
374
					// on met le mot clé dans sa propre case afin d'éviter
375
					// facilement les doublons provoqués par de mauvais formatages
376
					$tableau_mots_cles_formates[$mot_cle] = $this->tableau_mots_cles[$utilisateur][$mot_cle]['mot_cle'];
377
				}
378
 
379
			}
380
		}
381
 
382
		return $tableau_mots_cles_formates;
383
	}
384
 
385
	private function estUnIdentifiantMotCle($chaine) {
386
		return trim($chaine) != '' && preg_match('/[0-9A-Z]+\.[0-9A-Z]+/i', $chaine) ;
387
	}
388
 
389
	private function traiterIdentifiantUtilisateur($ligne_image) {
390
 
391
		$mail_image = $ligne_image['ci_ce_utilisateur'];
392
		$retour = $mail_image;
393
 
394
		if (isset($this->tableau_utilisateurs[$mail_image])) {
395
			$retour =  $this->tableau_utilisateurs[$mail_image]['id'];
396
		}
397
 
398
		return $retour;
399
	}
400
 
401
	private function traiterPrenomUtilisateur($ligne_image) {
402
 
403
		$mail_image = $ligne_image['ci_ce_utilisateur'];
404
		$retour = $mail_image;
405
 
406
		if (isset($this->tableau_utilisateurs[$mail_image])) {
407
			$retour =  $this->tableau_utilisateurs[$mail_image]['prenom'];
408
		}
409
 
410
		return $retour;
411
	}
412
 
413
	private function traiterNomUtilisateur($ligne_image) {
414
 
415
		$mail_image = $ligne_image['ci_ce_utilisateur'];
416
		$retour = $mail_image;
417
 
418
		if (isset($this->tableau_utilisateurs[$mail_image])) {
419
			$retour =  $this->tableau_utilisateurs[$mail_image]['nom'];
420
		}
421
 
422
		return $retour;
423
	}
424
 
425
	private function decoderTableauMetaDonnees($chaine) {
426
 
427
		$tableau_valeurs_decodees = array();
428
 
429
		if (trim($chaine) != '') {
430
			$tableau_meta = explode(self::separateur_champs_metadonnees,$chaine);
431
			foreach ($tableau_meta as &$chaine_meta) {
432
 
433
				$cle_valeur = explode(self::separateur_valeurs_metadonnees, $chaine_meta);
434
				if (is_array($cle_valeur) && count($cle_valeur) == 2) {
435
					$cle = ltrim($cle_valeur[0],' ');
436
					$tableau_valeurs_decodees[$cle] = $cle_valeur[1];
437
				}
438
			}
439
		}
440
 
441
		return $tableau_valeurs_decodees;
442
	}
443
 
444
	private function convertirTableauMetadonneesEnXml($tableau) {
445
 
446
		$xml = '';
447
 
448
		/*foreach($tableau as $cle => $valeur) {
449
 
450
			$cle = str_replace('ci_meta_exif_','',$cle);
451
			$cle = str_replace('ci_meta_iptc_','',$cle);
452
			$cle = str_replace('ci_meta_','',$cle);
453
			$cle = str_replace('_',' ',$cle);
454
			$cle = str_replace(' ','',ucwords($cle));
455
			$valeur = str_replace("\0",'',$valeur);
456
			$xml .= '<'.$cle.' id="'.$this->id_cle_metadonnees[$cle].'">'.$valeur.'</'.$cle.'>'."\n";
457
		}*/
458
 
459
		return $xml;
460
	}
461
 
462
	private function peutUtiliserExifTool() {
463
		return file_exists('/usr/bin/exiftool') && is_executable('/usr/bin/exiftool');
464
	}
465
 
466
	private function decoderMetadonnees($chemin_image) {
467
 
468
		$res = '';
469
 
470
		if($this->peutUtiliserExifTool()) {
471
			$res = $this->decoderMetadonneesExifTool($chemin_image);
472
 
473
			$xml_meta = '<?xml version="1.0" encoding="UTF-8" ?>';
474
			$xml_meta .= '<exif>';
475
 
476
			foreach($res['EXIF'] as $prop => $valeur) {
477
				$xml_meta .= '    <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
478
			}
479
			$xml_meta .= '</exif>'."\n";
480
 
481
			$xml_meta .= '<iptc>';
482
			foreach($res['IPTC'] as $prop => $valeur) {
483
				$xml_meta .= '    <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
484
			}
485
			$xml_meta .= '</iptc>'."\n";
486
 
487
			$xml_meta .= '<xmp>';
488
			foreach($res['XMP'] as $prop => $valeur) {
489
				$xml_meta .= '    <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
490
			}
491
			$xml_meta .= '</xmp>'."\n";
492
		} else {
493
 
494
		}
495
 
496
		return $xml_meta;
497
	}
498
 
499
	private function decoderMetadonneesExifTool($chemin_image) {
500
		$metadata = array();
501
		$res = exec('/usr/bin/exiftool -g -D '.$chemin_image, $metadata);
502
 
503
		$metadata_decodees = array();
504
 
505
		$categorie = '';
506
		foreach($metadata as &$data) {
507
			if($this->estUnSeparateurCategorieExifTool($data)) {
508
				$categorie = trim(str_replace('----','',$data));
509
			} else {
510
				$data_decodee = $this->parserValeurMetadonneeExifTool($data);
511
				$cle_metadonnee = str_replace(' ', '', $data_decodee['cle']);
512
				$metadata_decodees[$categorie][$cle_metadonnee] = $data_decodee;
513
				$this->id_cle_metadonnees[$cle_metadonnee] = $data_decodee['id'];
514
			}
515
		}
516
 
517
		return $metadata_decodees;
518
	}
519
 
520
	private function estUnSeparateurCategorieExifTool($data) {
521
		return preg_match('^---- (.)* ----^',$data);
522
	}
523
 
524
	private function parserValeurMetadonneeExifTool($data) {
525
		$cle_valeur = explode(':',$data);
526
 
527
		$valeur = '';
528
		if(count($cle_valeur) == 2) {
529
			$valeur	= trim($cle_valeur[1]);
530
		}
531
 
532
		$id_cle = explode(' ',trim($cle_valeur[0]),2);
533
 
534
		$id_cle[1] = str_replace(array('-','/'),'',$id_cle[1]);
535
 
536
		$cle_id_valeur = array('cle' => $id_cle[1], 'id' => str_replace('-','',$id_cle[0]), 'valeur' => $valeur);
537
		return $cle_id_valeur;
538
	}
539
 
540
	private function traiterExif($ligne_image) {
541
 
542
		$metadonnees_autres = $this->decoderTableauMetaDonnees($ligne_image['ci_meta_exif_autres']);
543
		$metadonnees = array_intersect_key($ligne_image, array_flip($this->champs_exifs_non_gardes))+$metadonnees_autres;
544
 
545
		$xml_meta = '<?xml version="1.0" encoding="UTF-8" ?>';
546
		$xml_meta .= '<exif>';
547
		$xml_meta .= $this->convertirTableauMetadonneesEnXml($metadonnees);
548
		$xml_meta .= '</exif>';
549
 
550
		return $xml_meta;
551
	}
552
 
553
	private function traiterIptc($ligne_image) {
554
 
555
		$metadonnees_autres = $this->decoderTableauMetaDonnees($ligne_image['ci_meta_iptc_autres']);
556
		$metadonnees = array_intersect_key($ligne_image, array_flip($this->champs_iptc_non_gardes))+$metadonnees_autres;
557
 
558
		$xml_meta = '<?xml version="1.0" encoding="UTF-8" ?>';
559
		$xml_meta .= '<iptc>';
560
		$xml_meta .= $this->convertirTableauMetadonneesEnXml($metadonnees);
561
		$xml_meta .= '</iptc>';
562
 
563
		return $xml_meta;
564
	}
565
 
566
	private function traiterXmp($ligne_image) {
567
 
568
		$chemin = $this->obtenirCheminImageOriginale($ligne_image['ci_id_image']);
569
		//$res = $this->decoderMetadonneesExifTool($chemin);
570
		$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
571
		$xml .= '<xmp>';
572
		if (isset($res['XMP'])) {
573
			foreach ($res['XMP'] as $prop => $valeur) {
574
				$xml .= '    <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
575
			}
576
		}
577
		$xml .= '</xmp>';
578
 
579
		return $xml;
580
	}
581
 
582
	private function traiterMakernote($ligne_image) {
583
 
584
		$chemin = $this->obtenirCheminImageOriginale($ligne_image['ci_id_image']);
585
		//$res = $this->decoderMetadonneesExifTool($chemin);
586
		$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
587
		$xml .= '<makernote>';
588
		if (isset($res['MAKERNOTE'])) {
589
			foreach ($res['MAKERNOTE'] as $prop => $valeur) {
590
				$xml .= '    <'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
591
			}
592
		}
593
		$xml .= '</makernote>';
594
 
595
		return '';
596
	}
597
 
598
	public function obtenirCheminImageOriginale($id_image) {
599
		$nom = $this->convertirIdBddVersNomFichier($id_image, 'O');
600
		$dossier = $this->obtenirDossierPourFormat($id_image,'O');
601
 
602
		return $dossier.'/'.$nom;
603
	}
604
 
605
	public function convertirIdBddVersNomFichier($id, $format, $extension = 'jpg') {
606
		// creation du format original
607
		$id_avec_zeros = sprintf('%09s', $id) ;
608
		$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
609
 
610
		$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
611
 
612
		return $nom_fichier;
613
	}
614
 
615
	public function obtenirDossierPourFormat($id, $format) {
616
		$chemin_base = $this->config['cel']['chemin_images'];
617
 
618
		$chemin_sur_serveur = $chemin_base;
619
 
620
		$id = sprintf('%09s', $id);
621
		$id = wordwrap($id, 3 , '_', true);
622
 
623
		list($dossierNiveau1, $dossierNiveau2) = explode('_', $id);
624
 
625
		$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
626
 
627
		return $chemin_sur_serveur_final;
628
	}
629
 
630
	private $tableau_ids_tags_exif = array('InteropIndex' => '1',
631
		'InteropVersion' => '2',
632
		'ProcessingSoftware' => '11',
633
		'SubfileType' => '254',
634
		'OldSubfileType' => '255',
635
		'ImageWidth' => '256',
636
		'ImageHeight' => '257',
637
		'BitsPerSample' => '258',
638
		'Compression' => '259',
639
		'PhotometricInterpretation' => '262',
640
		'Thresholding' => '263',
641
		'CellWidth' => '264',
642
		'CellLength' => '265',
643
		'FillOrder' => '266',
644
		'DocumentName' => '269',
645
		'ImageDescription' => '270',
646
		'Make' => '271',
647
		'Model' => '272',
648
		'StripOffsets' => '273',
649
		'Orientation' => '274',
650
		'SamplesPerPixel' => '277',
651
		'RowsPerStrip' => '278',
652
		'StripByteCounts' => '279',
653
		'MinSampleValue' => '280',
654
		'MaxSampleValue' => '281',
655
		'XResolution' => '282',
656
		'YResolution' => '283',
657
		'PlanarConfiguration' => '284',
658
		'PageName' => '285',
659
		'XPosition' => '286',
660
		'YPosition' => '287',
661
		'FreeOffsets' => '288',
662
		'FreeByteCounts' => '289',
663
		'GrayResponseUnit' => '290',
664
		'GrayResponseCurve' => '291',
665
		'T4Options' => '292',
666
		'T6Options' => '293',
667
		'ResolutionUnit' => '296',
668
		'PageNumber' => '297',
669
		'ColorResponseUnit' => '300',
670
		'TransferFunction' => '301',
671
		'Software' => '305',
672
		'ModifyDate' => '306',
673
		'Artist' => '315',
674
		'HostComputer' => '316',
675
		'Predictor' => '317',
676
		'WhitePoint' => '318',
677
		'PrimaryChromaticities' => '319',
678
		'ColorMap' => '320',
679
		'HalftoneHints' => '321',
680
		'TileWidth' => '322',
681
		'TileLength' => '323',
682
		'TileOffsets' => '324',
683
		'TileByteCounts' => '325',
684
		'BadFaxLines' => '326',
685
		'CleanFaxData' => '327',
686
		'ConsecutiveBadFaxLines' => '328',
687
		'SubIFD' => '330',
688
		'InkSet' => '332',
689
		'InkNames' => '333',
690
		'NumberofInks' => '334',
691
		'DotRange' => '336',
692
		'TargetPrinter' => '337',
693
		'ExtraSamples' => '338',
694
		'SampleFormat' => '339',
695
		'SMinSampleValue' => '340',
696
		'SMaxSampleValue' => '341',
697
		'TransferRange' => '342',
698
		'ClipPath' => '343',
699
		'XClipPathUnits' => '344',
700
		'YClipPathUnits' => '345',
701
		'Indexed' => '346',
702
		'JPEGTables' => '347',
703
		'OPIProxy' => '351',
704
		'GlobalParametersIFD' => '400',
705
		'ProfileType' => '401',
706
		'FaxProfile' => '402',
707
		'CodingMethods' => '403',
708
		'VersionYear' => '404',
709
		'ModeNumber' => '405',
710
		'Decode' => '433',
711
		'DefaultImageColor' => '434',
712
		'T82Options' => '435',
713
		'JPEGTables' => '437',
714
		'JPEGProc' => '512',
715
		'ThumbnailOffset' => '513',
716
		'ThumbnailLength' => '514',
717
		'JPEGRestartInterval' => '515',
718
		'JPEGLosslessPredictors' => '517',
719
		'JPEGPointTransforms' => '518',
720
		'JPEGQTables' => '519',
721
		'JPEGDCTables' => '520',
722
		'JPEGACTables' => '521',
723
		'YCbCrCoefficients' => '529',
724
		'YCbCrSubSampling' => '530',
725
		'YCbCrPositioning' => '531',
726
		'ReferenceBlackWhite' => '532',
727
		'StripRowCounts' => '559',
728
		'ApplicationNotes' => '700',
729
		'USPTOMiscellaneous' => '999',
730
		'RelatedImageFileFormat' => '4096',
731
		'RelatedImageWidth' => '4097',
732
		'RelatedImageHeight' => '4098',
733
		'Rating' => '18246',
734
		'XP_DIP_XML' => '18247',
735
		'StitchInfo' => '18248',
736
		'RatingPercent' => '18249',
737
		'ImageID' => '32781',
738
		'WangTag1' => '32931',
739
		'WangAnnotation' => '32932',
740
		'WangTag3' => '32933',
741
		'WangTag4' => '32934',
742
		'Matteing' => '32995',
743
		'DataType' => '32996',
744
		'ImageDepth' => '32997',
745
		'TileDepth' => '32998',
746
		'Model2' => '33405',
747
		'CFARepeatPatternDim' => '33421',
748
		'CFAPattern2' => '33422',
749
		'BatteryLevel' => '33423',
750
		'KodakIFD' => '33424',
751
		'Copyright' => '33432',
752
		'ExposureTime' => '33434',
753
		'FNumber' => '33437',
754
		'MDFileTag' => '33445',
755
		'MDScalePixel' => '33446',
756
		'MDColorTable' => '33447',
757
		'MDLabName' => '33448',
758
		'MDSampleInfo' => '33449',
759
		'MDPrepDate' => '33450',
760
		'MDPrepTime' => '33451',
761
		'MDFileUnits' => '33452',
762
		'PixelScale' => '33550',
763
		'AdventScale' => '33589',
764
		'AdventRevision' => '33590',
765
		'UIC1Tag' => '33628',
766
		'UIC2Tag' => '33629',
767
		'UIC3Tag' => '33630',
768
		'UIC4Tag' => '33631',
769
		'IPTC-NAA' => '33723',
770
		'IntergraphPacketData' => '33918',
771
		'IntergraphFlagRegisters' => '33919',
772
		'IntergraphMatrix' => '33920',
773
		'INGRReserved' => '33921',
774
		'ModelTiePoint' => '33922',
775
		'Site' => '34016',
776
		'ColorSequence' => '34017',
777
		'IT8Header' => '34018',
778
		'RasterPadding' => '34019',
779
		'BitsPerRunLength' => '34020',
780
		'BitsPerExtendedRunLength' => '34021',
781
		'ColorTable' => '34022',
782
		'ImageColorIndicator' => '34023',
783
		'BackgroundColorIndicator' => '34024',
784
		'ImageColorValue' => '34025',
785
		'BackgroundColorValue' => '34026',
786
		'PixelIntensityRange' => '34027',
787
		'TransparencyIndicator' => '34028',
788
		'ColorCharacterization' => '34029',
789
		'HCUsage' => '34030',
790
		'TrapIndicator' => '34031',
791
		'CMYKEquivalent' => '34032',
792
		'SEMInfo' => '34118',
793
		'AFCP_IPTC' => '34152',
794
		'PixelMagicJBIGOptions' => '34232',
795
		'ModelTransform' => '34264',
796
		'WB_GRGBLevels' => '34306',
797
		'LeafData' => '34310',
798
		'PhotoshopSettings' => '34377',
799
		'ExifOffset' => '34665',
800
		'ICC_Profile' => '34675',
801
		'TIFF_FXExtensions' => '34687',
802
		'MultiProfiles' => '34688',
803
		'SharedData' => '34689',
804
		'T88Options' => '34690',
805
		'ImageLayer' => '34732',
806
		'GeoTiffDirectory' => '34735',
807
		'GeoTiffDoubleParams' => '34736',
808
		'GeoTiffAsciiParams' => '34737',
809
		'ExposureProgram' => '34850',
810
		'SpectralSensitivity' => '34852',
811
		'GPSInfo' => '34853',
812
		'ISO' => '34855',
813
		'Opto-ElectricConvFactor' => '34856',
814
		'Interlace' => '34857',
815
		'TimeZoneOffset' => '34858',
816
		'SelfTimerMode' => '34859',
817
		'SensitivityType' => '34864',
818
		'StandardOutputSensitivity' => '34865',
819
		'RecommendedExposureIndex' => '34866',
820
		'ISOSpeed' => '34867',
821
		'ISOSpeedLatitudeyyy' => '34868',
822
		'ISOSpeedLatitudezzz' => '34869',
823
		'FaxRecvParams' => '34908',
824
		'FaxSubAddress' => '34909',
825
		'FaxRecvTime' => '34910',
826
		'LeafSubIFD' => '34954',
827
		'ExifVersion' => '36864',
828
		'DateTimeOriginal' => '36867',
829
		'CreateDate' => '36868',
830
		'ComponentsConfiguration' => '37121',
831
		'CompressedBitsPerPixel' => '37122',
832
		'ShutterSpeedValue' => '37377',
833
		'ApertureValue' => '37378',
834
		'BrightnessValue' => '37379',
835
		'ExposureCompensation' => '37380',
836
		'MaxApertureValue' => '37381',
837
		'SubjectDistance' => '37382',
838
		'MeteringMode' => '37383',
839
		'LightSource' => '37384',
840
		'Flash' => '37385',
841
		'FocalLength' => '37386',
842
		'FlashEnergy' => '37387',
843
		'SpatialFrequencyResponse' => '37388',
844
		'Noise' => '37389',
845
		'FocalPlaneXResolution' => '37390',
846
		'FocalPlaneYResolution' => '37391',
847
		'FocalPlaneResolutionUnit' => '37392',
848
		'ImageNumber' => '37393',
849
		'SecurityClassification' => '37394',
850
		'ImageHistory' => '37395',
851
		'SubjectArea' => '37396',
852
		'ExposureIndex' => '37397',
853
		'TIFF-EPStandardID' => '37398',
854
		'SensingMethod' => '37399',
855
		'CIP3DataFile' => '37434',
856
		'CIP3Sheet' => '37435',
857
		'CIP3Side' => '37436',
858
		'StoNits' => '37439',
859
		'MakerNoteCanon' => '37500',
860
		'UserComment' => '37510',
861
		'SubSecTime' => '37520',
862
		'SubSecTimeOriginal' => '37521',
863
		'SubSecTimeDigitized' => '37522',
864
		'MSDocumentText' => '37679',
865
		'MSPropertySetStorage' => '37680',
866
		'MSDocumentTextPosition' => '37681',
867
		'ImageSourceData' => '37724',
868
		'XPTitle' => '40091',
869
		'XPComment' => '40092',
870
		'XPAuthor' => '40093',
871
		'XPKeywords' => '40094',
872
		'XPSubject' => '40095',
873
		'FlashpixVersion' => '40960',
874
		'ColorSpace' => '40961',
875
		'ExifImageWidth' => '40962',
876
		'ExifImageHeight' => '40963',
877
		'RelatedSoundFile' => '40964',
878
		'InteropOffset' => '40965',
879
		'FlashEnergy' => '41483',
880
		'SpatialFrequencyResponse' => '41484',
881
		'Noise' => '41485',
882
		'FocalPlaneXResolution' => '41486',
883
		'FocalPlaneYResolution' => '41487',
884
		'FocalPlaneResolutionUnit' => '41488',
885
		'ImageNumber' => '41489',
886
		'SecurityClassification' => '41490',
887
		'ImageHistory' => '41491',
888
		'SubjectLocation' => '41492',
889
		'ExposureIndex' => '41493',
890
		'TIFF-EPStandardID' => '41494',
891
		'SensingMethod' => '41495',
892
		'FileSource' => '41728',
893
		'SceneType' => '41729',
894
		'CFAPattern' => '41730',
895
		'CustomRendered' => '41985',
896
		'ExposureMode' => '41986',
897
		'WhiteBalance' => '41987',
898
		'DigitalZoomRatio' => '41988',
899
		'FocalLengthIn35mmFormat' => '41989',
900
		'SceneCaptureType' => '41990',
901
		'GainControl' => '41991',
902
		'Contrast' => '41992',
903
		'Saturation' => '41993',
904
		'Sharpness' => '41994',
905
		'DeviceSettingDescription' => '41995',
906
		'SubjectDistanceRange' => '41996',
907
		'ImageUniqueID' => '42016',
908
		'OwnerName' => '42032',
909
		'SerialNumber' => '42033',
910
		'LensInfo' => '42034',
911
		'LensMake' => '42035',
912
		'LensModel' => '42036',
913
		'LensSerialNumber' => '42037',
914
		'GDALMetadata' => '42112',
915
		'GDALNoData' => '42113',
916
		'Gamma' => '42240',
917
		'ExpandSoftware' => '44992',
918
		'ExpandLens' => '44993',
919
		'ExpandFilm' => '44994',
920
		'ExpandFilterLens' => '44995',
921
		'ExpandScanner' => '44996',
922
		'ExpandFlashLamp' => '44997',
923
		'PixelFormat' => '48129',
924
		'Transformation' => '48130',
925
		'Uncompressed' => '48131',
926
		'ImageType' => '48132',
927
		'ImageWidth' => '48256',
928
		'ImageHeight' => '48257',
929
		'WidthResolution' => '48258',
930
		'HeightResolution' => '48259',
931
		'ImageOffset' => '48320',
932
		'ImageByteCount' => '48321',
933
		'AlphaOffset' => '48322',
934
		'AlphaByteCount' => '48323',
935
		'ImageDataDiscard' => '48324',
936
		'AlphaDataDiscard' => '48325',
937
		'OceScanjobDesc' => '50215',
938
		'OceApplicationSelector' => '50216',
939
		'OceIDNumber' => '50217',
940
		'OceImageLogic' => '50218',
941
		'Annotations' => '50255',
942
		'PrintIM' => '50341',
943
		'USPTOOriginalContentType' => '50560',
944
		'DNGVersion' => '50706',
945
		'DNGBackwardVersion' => '50707',
946
		'UniqueCameraModel' => '50708',
947
		'LocalizedCameraModel' => '50709',
948
		'CFAPlaneColor' => '50710',
949
		'CFALayout' => '50711',
950
		'LinearizationTable' => '50712',
951
		'BlackLevelRepeatDim' => '50713',
952
		'BlackLevel' => '50714',
953
		'BlackLevelDeltaH' => '50715',
954
		'BlackLevelDeltaV' => '50716',
955
		'WhiteLevel' => '50717',
956
		'DefaultScale' => '50718',
957
		'DefaultCropOrigin' => '50719',
958
		'DefaultCropSize' => '50720',
959
		'ColorMatrix1' => '50721',
960
		'ColorMatrix2' => '50722',
961
		'CameraCalibration1' => '50723',
962
		'CameraCalibration2' => '50724',
963
		'ReductionMatrix1' => '50725',
964
		'ReductionMatrix2' => '50726',
965
		'AnalogBalance' => '50727',
966
		'AsShotNeutral' => '50728',
967
		'AsShotWhiteXY' => '50729',
968
		'BaselineExposure' => '50730',
969
		'BaselineNoise' => '50731',
970
		'BaselineSharpness' => '50732',
971
		'BayerGreenSplit' => '50733',
972
		'LinearResponseLimit' => '50734',
973
		'CameraSerialNumber' => '50735',
974
		'DNGLensInfo' => '50736',
975
		'ChromaBlurRadius' => '50737',
976
		'AntiAliasStrength' => '50738',
977
		'ShadowScale' => '50739',
978
		'SR2Private' => '50740',
979
		'MakerNoteSafety' => '50741',
980
		'RawImageSegmentation' => '50752',
981
		'CalibrationIlluminant1' => '50778',
982
		'CalibrationIlluminant2' => '50779',
983
		'BestQualityScale' => '50780',
984
		'RawDataUniqueID' => '50781',
985
		'AliasLayerMetadata' => '50784',
986
		'OriginalRawFileName' => '50827',
987
		'OriginalRawFileData' => '50828',
988
		'ActiveArea' => '50829',
989
		'MaskedAreas' => '50830',
990
		'AsShotICCProfile' => '50831',
991
		'AsShotPreProfileMatrix' => '50832',
992
		'CurrentICCProfile' => '50833',
993
		'CurrentPreProfileMatrix' => '50834',
994
		'ColorimetricReference' => '50879',
995
		'PanasonicTitle' => '50898',
996
		'PanasonicTitle2' => '50899',
997
		'CameraCalibrationSig' => '50931',
998
		'ProfileCalibrationSig' => '50932',
999
		'ProfileIFD' => '50933',
1000
		'AsShotProfileName' => '50934',
1001
		'NoiseReductionApplied' => '50935',
1002
		'ProfileName' => '50936',
1003
		'ProfileHueSatMapDims' => '50937',
1004
		'ProfileHueSatMapData1' => '50938',
1005
		'ProfileHueSatMapData2' => '50939',
1006
		'ProfileToneCurve' => '50940',
1007
		'ProfileEmbedPolicy' => '50941',
1008
		'ProfileCopyright' => '50942',
1009
		'ForwardMatrix1' => '50964',
1010
		'ForwardMatrix2' => '50965',
1011
		'PreviewApplicationName' => '50966',
1012
		'PreviewApplicationVersion' => '50967',
1013
		'PreviewSettingsName' => '50968',
1014
		'PreviewSettingsDigest' => '50969',
1015
		'PreviewColorSpace' => '50970',
1016
		'PreviewDateTime' => '50971',
1017
		'RawImageDigest' => '50972',
1018
		'OriginalRawFileDigest' => '50973',
1019
		'SubTileBlockSize' => '50974',
1020
		'RowInterleaveFactor' => '50975',
1021
		'ProfileLookTableDims' => '50981',
1022
		'ProfileLookTableData' => '50982',
1023
		'OpcodeList1' => '51008',
1024
		'OpcodeList2' => '51009',
1025
		'OpcodeList3' => '51022',
1026
		'NoiseProfile' => '51041',
1027
		'Padding' => '59932',
1028
		'OffsetSchema' => '59933',
1029
		'OwnerName' => '65000',
1030
		'SerialNumber' => '65001',
1031
		'Lens' => '65002',
1032
		'KDC_IFD' => '65024',
1033
		'RawFile' => '65100',
1034
		'Converter' => '65101',
1035
		'WhiteBalance' => '65102',
1036
		'Exposure' => '65105',
1037
		'Shadows' => '65106',
1038
		'Brightness' => '65107',
1039
		'Contrast' => '65108',
1040
		'Saturation' => '65109',
1041
		'Sharpness' => '65110',
1042
		'Smoothness' => '65111',
1043
		'MoireFilter' => '65112',
1044
	);
1045
 
1046
	private $tableau_ids_tags_iptc = array('ApplicationRecordVersion' => '0',
1047
		'ObjectTypeReference' => '3',
1048
		'ObjectAttributeReference' => '4',
1049
		'ObjectName' => '5',
1050
		'EditStatus' => '7',
1051
		'EditorialUpdate' => '8',
1052
		'Urgency' => '16',
1053
		'SubjectReference' => '18',
1054
		'Category' => '21',
1055
		'SupplementalCategories' => '32',
1056
		'FixtureIdentifier' => '34',
1057
		'Keywords' => '37',
1058
		'ContentLocationCode' => '38',
1059
		'ContentLocationName' => '39',
1060
		'ReleaseDate' => '48',
1061
		'ReleaseTime' => '53',
1062
		'ExpirationDate' => '55',
1063
		'ExpirationTime' => '56',
1064
		'SpecialInstructions' => '64',
1065
		'ActionAdvised' => '66',
1066
		'ReferenceService' => '69',
1067
		'ReferenceDate' => '71',
1068
		'ReferenceNumber' => '80',
1069
		'DateCreated' => '85',
1070
		'TimeCreated' => '96',
1071
		'DigitalCreationDate' => '98',
1072
		'DigitalCreationTime' => '99',
1073
		'OriginatingProgram' => '101',
1074
		'ProgramVersion' => '112',
1075
		'ObjectCycle' => '117',
1076
		'By-line' => '128',
1077
		'By-lineTitle' => '133',
1078
		'City' => '144',
1079
		'Sub-location' => '146',
1080
		'Province-State' => '149',
1081
		'Country-PrimaryLocationCode' => '256',
1082
		'Country-PrimaryLocationName' => '257',
1083
		'OriginalTransmissionReference' => '259',
1084
		'Headline' => '261',
1085
		'Credit' => '272',
1086
		'Source' => '277',
1087
		'CopyrightNotice' => '278',
1088
		'Contact' => '280',
1089
		'Caption-Abstract' => '288',
1090
		'LocalCaption' => '289',
1091
		'Writer-Editor' => '290',
1092
		'RasterizedCaption' => '293',
1093
		'ImageType' => '304',
1094
		'ImageOrientation' => '305',
1095
		'LanguageIdentifier' => '309',
1096
		'AudioType' => '336',
1097
		'AudioSamplingRate' => '337',
1098
		'AudioSamplingResolution' => '338',
1099
		'AudioDuration' => '339',
1100
		'AudioOutcue' => '340',
1101
		'JobID' => '388',
1102
		'MasterDocumentID' => '389',
1103
		'ShortDocumentID' => '390',
1104
		'UniqueDocumentID' => '391',
1105
		'OwnerID' => '392',
1106
		'ObjectPreviewFileFormat' => '512',
1107
		'ObjectPreviewFileVersion' => '513',
1108
		'ObjectPreviewData' => '514',
1109
		'Prefs' => '545',
1110
		'ClassifyState' => '549',
1111
		'SimilarityIndex' => '552',
1112
		'DocumentNotes' => '560',
1113
		'DocumentHistory' => '561',
1114
		'ExifCameraInfo' => '562',
1115
		'CatalogSets' => '597',
1116
	);
1117
}