Subversion Repositories eFlore/Applications.cel

Rev

Rev 999 | Rev 1001 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 999 Rev 1000
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
2
 
2
 
Line -... Line 3...
-
 
3
Class CelEfloreImages extends Cel {
-
 
4
	
3
Class CelEfloreImages extends Cel {
5
	private $formats_supportes = array('image/jpeg');
4
	
6
	
5
	function getElement($uid) {
7
	function getElement($uid) {
Line 6... Line 8...
6
		return getRessource();
8
		return getRessource();
Line 7... Line 9...
7
	}
9
	}
-
 
10
	
-
 
11
	function getRessource(){
8
	
12
	
Line -... Line 13...
-
 
13
		$parametres = $this->recupererParametresBruts();
9
	function getRessource(){
14
		$header = '';
10
	
15
	
11
		$parametres = $this->recupererParametresBruts();
-
 
Line 12... Line 16...
12
		$num_nom = $parametres['masque.nn'];
16
		if(!$erreurs = $this->parametresOntErreurs($parametres)) {
Line 13... Line 17...
13
		
17
		
14
		$retour = isset($parametres['retour']) ? $parametres['retour'] : 'image/jpeg';
18
			$num_nom = $parametres['masque.nn'];
-
 
19
			$retour = isset($parametres['retour']) ? $parametres['retour'] : 'image/jpeg';
-
 
20
			$format = isset($parametres['retour.format']) ? $parametres['retour.format'] : 'M';
-
 
21
			
-
 
22
			$id_image_a_renvoyer = $this->obtenirImageAuHasardPourNumNom($num_nom);
-
 
23
				
Line 15... Line -...
15
		$format = isset($parametres['retour.format']) ? $parametres['retour.format'] : 'M';
-
 
16
		$dimensions = $this->config['cel_db']['format_'.$format];
24
			$header = $id_image_a_renvoyer ? "HTTP/1.0 200 OK" : "HTTP/1.0 404 Not Found";
17
		
25
			$erreurs = $id_image_a_renvoyer ? false : 'Aucune image ne corespond au numéro numenclatural '.$num_nom."\n";
18
		$generateur_image = new ImageRecreation($this->config);
26
		} else {
Line 19... Line 27...
19
		
27
			$header = "HTTP/1.0 400 Bad Request";		
-
 
28
		}
-
 
29
		
-
 
30
		header($header);
Line -... Line 31...
-
 
31
		
-
 
32
		$erreurs ? $this->renvoyerTexteSimple($erreurs) : $this->renvoyerImageExistanteOuGeneree($id_image_a_renvoyer, $format);
-
 
33
		exit;
-
 
34
	}
20
		$id_image = $this->obtenirImageAuHasardPourNN($num_nom);
35
	
-
 
36
	private function renvoyerTexteSimple($erreurs) {
-
 
37
		header("Content-type: text/plain");
-
 
38
		echo $erreurs;
21
		$infos_image = $generateur_image->obtenirImageEtInfosPourId($id_image);
39
	}
-
 
40
	
22
		
41
	private function renvoyerImageExistanteOuGeneree($id_image, $format = 'M') {
-
 
42
		
-
 
43
		$generateur_image = new ImageRecreation($this->config);
-
 
44
		
23
		if(!$infos_image) {
45
		header("Content-type: image/jpeg");
-
 
46
		if ($this->estUnFormatDejaCree($format)) {
-
 
47
			$nom = $generateur_image->convertirIdBddVersNomFichier($id_image, $format);
-
 
48
			$dossier = $generateur_image->obtenirDossierPourFormat($id_image, $format);
Line 24... Line -...
24
			header('HTTP/1.0 404 Not Found');
-
 
25
			exit;
-
 
26
		}
49
			$chemin_image =  $dossier.'/'.$nom;
27
		
50
			echo file_get_contents($chemin_image);
28
		$image_generee = $generateur_image->creerMiniatureImageSelonFormat($infos_image, $format);
51
		} else {
29
		
52
			$infos_image = $generateur_image->obtenirImageEtInfosPourId($id_image);
30
		header('Content-type: '.$retour);
53
			$image_a_renvoyer = $generateur_image->creerMiniatureImageSelonFormat($infos_image, $format);
Line 43... Line 66...
43
					'WHERE ci.transmission = 1 '.
66
					'WHERE ci.transmission = 1 '.
44
					'	AND num_nom_sel = '.$this->proteger($numero_nomenclatural).
67
					'	AND num_nom_sel = '.$this->proteger($numero_nomenclatural).
45
					'	AND ci.identifiant = cim.ci_ce_utilisateur ';
68
					'	AND ci.identifiant = cim.ci_ce_utilisateur ';
Line 46... Line 69...
46
		
69
		
47
		$resultat_images = $this->executerRequete($requete);
-
 
48
		//TODO que faire si pas de résultat ?
70
		$resultat_images = $this->executerRequete($requete);
-
 
71
		$id_image_hasard = (is_array($resultat_images) && count($resultat_images) > 0) ? $resultat_images[array_rand($resultat_images)]['id_image'] : false;
49
		$id_image_hasard = $resultat_images[array_rand($resultat_images)]['id_image'];
72
		
50
		return $id_image_hasard;
73
		return $id_image_hasard;
Line 51... Line 74...
51
	}
74
	}
52
	
75
	
Line 74... Line 97...
74
		$parametres_bruts = $this->nettoyerParametres($parametres_bruts);
97
			$parametres_bruts = $this->nettoyerParametres($parametres_bruts);
75
		}
98
		}
76
		return $parametres_bruts;
99
		return $parametres_bruts;
77
	}
100
	}
Line -... Line 101...
-
 
101
	
-
 
102
	private function parametresOntErreurs($parametres) {
-
 
103
		$erreurs = false;
-
 
104
		if (!isset($parametres['masque.nn'])) {
-
 
105
			$erreurs .= 'Le paramètre masque.nn est obligatoire '."\n";
-
 
106
		} else {
-
 
107
			if(!is_numeric($parametres['masque.nn'])) {
-
 
108
				$erreurs .= 'Le paramètre masque.nn est mal formé '."\n";
78
	
109
			}
Line -... Line 110...
-
 
110
		}
-
 
111
		
-
 
112
		if (isset($parametres['retour']) && !$this->retourEstSupporte($parametres['retour'])) {
-
 
113
			$erreurs .= 'Le type de retour '.$parametres['retour'].' n\'est pas supporté  '."\n";
-
 
114
		}
-
 
115
		
-
 
116
		if(isset($parametres['retour.format']) && !$this->formatEstSupporte($parametres['retour.format'])) {
-
 
117
			$erreurs .= 'Le type de format '.$parametres['retour.format'].' n\'est pas supporté  '."\n";
-
 
118
		}
-
 
119
		
-
 
120
		return $erreurs;
-
 
121
	}
-
 
122
	
-
 
123
	private function getFormats() {
-
 
124
		$formats = array();
-
 
125
		
-
 
126
		foreach ($this->config['cel_db'] as $param_config => $valeur) {
-
 
127
			if(substr_count($param_config,'format_') != 0) {
-
 
128
				$formats[$param_config] = $valeur;
-
 
129
			}
-
 
130
		}
-
 
131
		
-
 
132
		return $formats;
-
 
133
	}
-
 
134
	
-
 
135
	private function retourEstSupporte($retour = 'image/jpeg') {
-
 
136
		return in_array($retour, $this->formats_supportes);
-
 
137
	}
-
 
138
	
-
 
139
	private function formatEstSupporte($format = 'M') {
-
 
140
		
-
 
141
		$format_supporte = true;
-
 
142
		
-
 
143
		// cas du format déjà existant (S, M, L etc...)
-
 
144
		$format_supporte = $this->estUnFormatDejaCree($format);
-
 
145
		
-
 
146
		//TODO: décommenter les lignes suivantes lorsque les formats "à la demande" seront implémentés
-
 
147
		// cas du coté maximal de l'image demandé
-
 
148
		//$format_supporte = is_numeric($format) ? true : false;
-
 
149
		// cas du format exact demande Lxl
-
 
150
		//$format_supporte = preg_match('/[0-9]*x[0-9]*/', $format) ? true : false;
-
 
151
 
-
 
152
		return $format_supporte;
-
 
153
	}
-
 
154
	
-
 
155
	private function estUnFormatDejaCree($format = 'M') {
-
 
156
		$formats = $this->getFormats();
-
 
157
		$format_supporte = isset($formats['format_'.$format]) ? true : false;
-
 
158
 
-
 
159
		return $format_supporte;
79
}
160
	}	
80
 
161
}