Subversion Repositories eFlore/Applications.cel

Rev

Rev 524 | Rev 528 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 524 Rev 525
1
<?php
1
<?php
2
/**
2
/**
3
 * Service fournissant des informations concernant les images du CEL au format RSS1, RSS2 ou ATOM.
3
 * Service fournissant des informations concernant les images du CEL au format RSS1, RSS2 ou ATOM.
4
 * Encodage en entrée : utf8
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
5
 * Encodage en sortie : utf8
6
 * 
6
 * 
7
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
7
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
9
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
9
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
10
 * @version $Id$
10
 * @version $Id$
11
 * @copyright 2010
11
 * @copyright 2010
12
 */
12
 */
13
class CelSyndicationImage extends Cel {
13
class CelSyndicationImage extends Cel {
14
	
14
	
15
	private $format = null;
15
	private $format = null;
16
	private $service = null;
16
	private $service = null;
17
	private $squelette = null;
17
	private $squelette = null;
18
	private $squelette_dossier = null;
18
	private $squelette_dossier = null;
19
	private $flux = array();
19
	private $flux = array();
20
	
20
	
21
	private $format_image = 'L';
21
	private $format_image = 'L';
22
	
22
	
23
	/**
23
	/**
24
	 * Méthode appelée avec une requête de type GET.
24
	 * Méthode appelée avec une requête de type GET.
25
	 */
25
	 */
26
	public function getElement($params = array()) {
26
	public function getElement($params = array()) {
27
		// Initialisation des variables
27
		// Initialisation des variables
28
		$info = array();
28
		$info = array();
29
		$contenu = '';
29
		$contenu = '';
30
		
30
		
31
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
31
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
32
			// Pré traitement des paramêtres
32
			// Pré traitement des paramêtres
33
			$pour_bdd = false;
33
			$pour_bdd = false;
34
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
34
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
35
			extract($p);
35
			extract($p);
36
			$this->parametres = $params;
36
			$this->parametres = $params;
37
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
37
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
38
			
38
			
39
			// Récupération de la liste des flux
39
			// Récupération de la liste des flux
40
			$this->chargerListeDesFlux();
40
			$this->chargerListeDesFlux();
41
			
41
			
42
			// Chargement du bon type de service demandé
42
			// Chargement du bon type de service demandé
43
			if (isset($service)) {
43
			if (isset($service)) {
44
				$this->service = $this->traiterNomService($service);
44
				$this->service = $this->traiterNomService($service);
45
				$methode = $this->getNomMethodeService();
45
				$methode = $this->getNomMethodeService();
46
				if (method_exists($this, $methode)) {
46
				if (method_exists($this, $methode)) {
47
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
47
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
48
						// Mise en minuscule de l'indication du format
48
						// Mise en minuscule de l'indication du format
49
						$this->format = strtolower($format);
49
						$this->format = strtolower($format);
50
						// Définition du fichier squelette demandé
50
						// Définition du fichier squelette demandé
51
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
51
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
52
					} else if (isset($this->flux[$this->service])) {
52
					} else if (isset($this->flux[$this->service])) {
53
						$this->format = '';
53
						$this->format = '';
54
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
54
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
55
					}
55
					}
56
					
56
					
57
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
57
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
58
						// Suppression des paramêtres inutile pour le reste des méthodes
58
						// Suppression des paramêtres inutile pour le reste des méthodes
59
						array_shift($this->parametres);
59
						array_shift($this->parametres);
60
						array_shift($this->parametres);
60
						array_shift($this->parametres);
61
						
61
						
62
						// Récupération du contenu à renvoyer
62
						// Récupération du contenu à renvoyer
63
						$contenu = $this->$methode();
63
						$contenu = $this->$methode();
64
					}
64
					}
65
				} else {
65
				} else {
66
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
66
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
67
				}
67
				}
68
			} else {
68
			} else {
69
				$this->messages[] = "Le service CEL Syndication Image nécessite d'indiquer en premier paramètre le type d'information demandé.";
69
				$this->messages[] = "Le service CEL Syndication Image nécessite d'indiquer en premier paramètre le type d'information demandé.";
70
			}
70
			}
71
		}
71
		}
72
		
72
		
73
		// Envoie sur la sortie standard
73
		// Envoie sur la sortie standard
74
		$encodage = 'utf-8';
74
		$encodage = 'utf-8';
75
		$mime = $this->getTypeMime();
75
		$mime = $this->getTypeMime();
76
		$formatage_json = $this->getFormatageJson();
76
		$formatage_json = $this->getFormatageJson();
77
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
77
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
78
	}
78
	}
79
	
79
	
80
	private function chargerListeDesFlux() {
80
	private function chargerListeDesFlux() {
81
		$this->setFlux('simple', 'Nouvelles images liées à une observation dans le CEL', 
81
		$this->setFlux('simple', 'Nouvelles images liées à une observation dans le CEL', 
82
			"Ce flux fournit l'url des nouvelles images du CEL liées à une observation.");
82
			"Ce flux fournit l'url des nouvelles images du CEL liées à une observation.");
83
		$this->setFlux('complet', 'Nouvelles images liées à une observation dans le CEL (détails)', 
83
		$this->setFlux('complet', 'Nouvelles images liées à une observation dans le CEL (détails)', 
84
			"Ce flux fournit les informations sur les nouvelles images du CEL liées à une observation.");
84
			"Ce flux fournit les informations sur les nouvelles images du CEL liées à une observation.");
85
	}
85
	}
86
	
86
	
87
	private function setFlux($nom, $titre, $description) {
87
	private function setFlux($nom, $titre, $description) {
88
		$url_base = $this->config['settings']['baseURLAbsoluDyn'].'CoelSyndicationImage/';
88
		$url_base = $this->config['settings']['baseURLAbsoluDyn'].'CoelSyndicationImage/';
89
		$formats = array('atom', 'rss2', 'rss1');
89
		$formats = array('atom', 'rss2', 'rss1');
90
		$flux = array();
90
		$flux = array();
91
		foreach ($formats as $format) {
91
		foreach ($formats as $format) {
92
			$url = $url_base.$nom.'/'.$format;
92
			$url = $url_base.$nom.'/'.$format;
93
			$flux[$format] = $url;
93
			$flux[$format] = $url;
94
		}
94
		}
95
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
95
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
96
	}
96
	}
97
 
97
 
98
	private function getFlux($nom) {
98
	private function getFlux($nom) {
99
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
99
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
100
	}
100
	}
101
	
101
	
102
	private function traiterNomService($nom) {
102
	private function traiterNomService($nom) {
103
		$nom = strtolower($nom);
103
		$nom = strtolower($nom);
104
		return $nom;
104
		return $nom;
105
	}
105
	}
106
	
106
	
107
	private function getNomMethodeService() {
107
	private function getNomMethodeService() {
108
		$methode = '';
108
		$methode = '';
109
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
109
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
110
		$methode = 'getService'.$service_formate;
110
		$methode = 'getService'.$service_formate;
111
		return $methode;
111
		return $methode;
112
	}
112
	}
113
	
113
	
114
	private function getUrlBase() {
114
	private function getUrlBase() {
115
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
115
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
116
		return $url_base;
116
		return $url_base;
117
	}
117
	}
118
	
118
	
119
	private function getUrlServiceBase() {
119
	private function getUrlServiceBase() {
120
		$url_service = $this->getUrlBase().$this->service.'/'.$this->format;
120
		$url_service = $this->getUrlBase().$this->service.'/'.$this->format;
121
		return $url_service;
121
		return $url_service;
122
	}
122
	}
123
	
123
	
124
	private function getTypeMime() {
124
	private function getTypeMime() {
125
		$mime = '';
125
		$mime = '';
126
		switch ($this->format) {
126
		switch ($this->format) {
127
			case 'atom' :
127
			case 'atom' :
128
				$mime = 'application/atom+xml';
128
				$mime = 'application/atom+xml';
129
				break;
129
				break;
130
			case 'rss1' :
130
			case 'rss1' :
131
			case 'rss2' :
131
			case 'rss2' :
132
				$mime = 'application/rss+xml';
132
				$mime = 'application/rss+xml';
133
				break;
133
				break;
134
			case 'opml' :
134
			case 'opml' :
135
				$mime = 'text/x-opml';
135
				$mime = 'text/x-opml';
136
				break;
136
				break;
137
			default:
137
			default:
138
				$mime = 'text/html';
138
				$mime = 'text/html';
139
		}
139
		}
140
		return $mime;
140
		return $mime;
141
	}
141
	}
142
	
142
	
143
	private function getFormatageJson() {
143
	private function getFormatageJson() {
144
		$json = false;
144
		$json = false;
145
		switch ($this->service) {
145
		switch ($this->service) {
146
			case 'liste-des-flux' :
146
			case 'liste-des-flux' :
147
				$json = true;
147
				$json = true;
148
				break;
148
				break;
149
			default:
149
			default:
150
				$json = false;
150
				$json = false;
151
		}
151
		}
152
		return $json;
152
		return $json;
153
	}
153
	}
154
		
154
		
155
	private function etreFluxAdmin() {
155
	private function etreFluxAdmin() {
156
		return ($_GET['admin'] == '1') ? true : false;
156
		return ($_GET['admin'] == '1') ? true : false;
157
	}
157
	}
158
	
158
	
159
	private function creerUrlService() {
159
	private function creerUrlService() {
160
		$url_service = $this->getUrlServiceBase();
160
		$url_service = $this->getUrlServiceBase();
161
		if (isset($this->start) || isset($this->limit)) {
161
		if (isset($this->start) || isset($this->limit)) {
162
			$arguments = array();
162
			$arguments = array();
163
			if (isset($this->start) && isset($_GET['start'])) {
163
			if (isset($this->start) && isset($_GET['start'])) {
164
				$arguments[] = 'start='.$this->start;
164
				$arguments[] = 'start='.$this->start;
165
			}
165
			}
166
			if (isset($this->limit) && isset($_GET['limit'])) {
166
			if (isset($this->limit) && isset($_GET['limit'])) {
167
				$arguments[] = 'limit='.$this->limit;
167
				$arguments[] = 'limit='.$this->limit;
168
			}
168
			}
169
			if (count($arguments) > 0) {
169
			if (count($arguments) > 0) {
170
				$url_service .= '?'.implode('&', $arguments);
170
				$url_service .= '?'.implode('&', $arguments);
171
			}
171
			}
172
		}
172
		}
173
		return $url_service;
173
		return $url_service;
174
	}
174
	}
175
	
175
	
176
	protected function executerRequete($requete) {
176
	protected function executerRequete($requete) {
177
		try {
177
		try {
178
			$infos = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
178
			$infos = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
179
			if ($infos === false) {
179
			if ($infos === false) {
180
				$this->messages[] = "La requête suivante a retourné aucun résultat :\n$requete";
180
				$this->messages[] = "La requête suivante a retourné aucun résultat :\n$requete";
181
			}
181
			}
182
		} catch (PDOException $e) {
182
		} catch (PDOException $e) {
183
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
183
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
184
		}
184
		}
185
		return $infos;
185
		return $infos;
186
	}
186
	}
187
	
187
	
188
	private function executerService($elements) {
188
	private function executerService($elements) {
189
		// Prétraitement des données
189
		// Prétraitement des données
190
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
190
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
191
		
191
		
192
		foreach ($elements as $element) {
192
		foreach ($elements as $element) {
193
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
193
			$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
194
		}
194
		}
195
		
195
		
196
		// Création du contenu à partir d'un template PHP
196
		// Création du contenu à partir d'un template PHP
197
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
197
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
198
		
198
		
199
		return $contenu;
199
		return $contenu;
200
	}
200
	}
201
	
201
	
202
	private function construireDonneesCommunesAuFlux($infos) {
202
	private function construireDonneesCommunesAuFlux($infos) {
203
		$donnees = $this->getFlux($this->service);
203
		$donnees = $this->getFlux($this->service);
204
		$donnees['guid'] = $this->getUrlServiceBase();
204
		$donnees['guid'] = $this->getUrlServiceBase();
205
		$donnees['lien_service'] = $this->creerUrlService();
205
		$donnees['lien_service'] = $this->creerUrlService();
206
		$donnees['lien_cel'] = sprintf($this->config['settings']['efloreUrlTpl'], $infos['num_nom_sel']);
206
		$donnees['lien_cel'] = sprintf($this->config['settings']['efloreUrlTpl'], $infos['num_nom_sel']);
207
		$donnees['editeur'] = $this->config['settings']['editeur'];
207
		$donnees['editeur'] = $this->config['settings']['editeur'];
208
		$derniere_info_en_date = reset($infos);
208
		$derniere_info_en_date = reset($infos);
209
		$date_modification_timestamp = strtotime($derniere_info_en_date['ci_meta_date_ajout']);
209
		$date_modification_timestamp = strtotime($derniere_info_en_date['ci_meta_date_ajout']);
210
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
210
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
211
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
211
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
212
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
212
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
213
		$donnees['annee_courante'] = date('Y');
213
		$donnees['annee_courante'] = date('Y');
214
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationImage';
214
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationImage';
215
		preg_match('/([0-9]+)/', '$Revision$', $match);
215
		preg_match('/([0-9]+)/', '$Revision$', $match);
216
		$donnees['generateur_version'] = $match[1];
216
		$donnees['generateur_version'] = $match[1];
217
		return $donnees; 
217
		return $donnees; 
218
	}
218
	}
219
	
219
	
220
	private function construireDonneesCommunesAuxItems($info) {
220
	private function construireDonneesCommunesAuxItems($info) {
221
		$item = array();
221
		$item = array();
222
		$date_modification_timestamp = strtotime($info['ci_meta_date_ajout']);
222
		$date_modification_timestamp = strtotime($info['ci_meta_date_ajout']);
223
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
223
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
224
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
224
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
225
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
225
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
226
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
226
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
227
		$item['titre'] = $this->creerTitre($info);
227
		$item['titre'] = $this->creerTitre($info);
228
		$item['guid'] = $this->creerGuidItem($info);
228
		$item['guid'] = $this->creerGuidItem($info);
229
		$item['lien'] = $this->creerLienItem($info);
229
		$item['lien'] = $this->creerLienItem($info);
230
		$item['description'] = $this->creerDescription($info, $item);
230
		$item['description'] = $this->creerDescription($info, $item);
231
		$item['description_encodee'] = htmlspecialchars($item['description']);
231
		$item['description_encodee'] = htmlspecialchars($item['description']);
232
		return $item;
232
		return $item;
233
	}
233
	}
234
	
234
	
235
	private function creerGuidItem($element) {
235
	private function creerGuidItem($element) {
236
		$guid = sprintf($this->config['settings']['guidImgTpl'], $element['ci_id_image']);
236
		$guid = sprintf($this->config['settings']['guidImgTpl'], $element['ci_id_image']);
237
		return $guid;
237
		return $guid;
238
	}
238
	}
239
	
239
	
240
	private function creerTitre($element) {
240
	private function creerTitre($element) {
241
		$methode = 'creerTitre'.$this->service;
241
		$methode = 'creerTitre'.$this->service;
242
		$methode = (method_exists($this, $methode)) ? $methode : 'creerTitreSimple';
242
		$methode = (method_exists($this, $methode)) ? $methode : 'creerTitreSimple';
243
		$titre = $this->$methode($element);
243
		$titre = $this->$methode($element);
244
		$titre = $this->nettoyerTexte($titre);
244
		$titre = $this->nettoyerTexte($titre);
245
		return $titre;
245
		return $titre;
246
	}
246
	}
247
	
247
	
248
	private function creerDescription($donnees, $item) {
248
	private function creerDescription($donnees, $item) {
249
		$methode = 'creerDescription'.$this->service;
249
		$methode = 'creerDescription'.$this->service;
250
		$methode = (method_exists($this, $methode)) ? $methode : 'creerDescriptionSimple';
250
		$methode = (method_exists($this, $methode)) ? $methode : 'creerDescriptionComplet';
251
		$description = $this->$methode($donnees, $item);
251
		$description = $this->$methode($donnees, $item);
252
		$description = $this->nettoyerTexte($description);
252
		$description = $this->nettoyerTexte($description);
253
		return $description;
253
		return $description;
254
	}
254
	}
255
 
255
 
256
	private function creerLienItem($element) {
256
	private function creerLienItem($element) {
257
		$lien = $this->getUrlImage($element['ci_id_image'], $this->format_image);
257
		$lien = $this->getUrlImage($element['ci_id_image'], $this->format_image);
258
		return $lien;
258
		return $lien;
259
	}
259
	}
260
	
260
	
261
	private function getServiceListeDesFlux() {
261
	private function getServiceListeDesFlux() {
262
		return $this->flux;
262
		return $this->flux;
263
	}
263
	}
264
	
264
	
265
	private function getServiceOpml() {
265
	private function getServiceOpml() {
266
		$donnees = array();
266
		$donnees = array();
267
		$id = 1;
267
		$id = 1;
268
		foreach ($this->flux as $flux_nom => $flux){
268
		foreach ($this->flux as $flux_nom => $flux){
269
			$info = array();
269
			$info = array();
270
			$info['type'] = 'atom';
270
			$info['type'] = 'atom';
271
			$info['titre'] = $flux['titre'];
271
			$info['titre'] = $flux['titre'];
272
			$info['texte'] = "CEL - Images - $flux_nom";
272
			$info['texte'] = "CEL - Images - $flux_nom";
273
			$info['description'] = $flux['description'];
273
			$info['description'] = $flux['description'];
274
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
274
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
275
			$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
275
			$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
276
			$donnees['liste_flux'][] = $info;
276
			$donnees['liste_flux'][] = $info;
277
		}
277
		}
278
		
278
		
279
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
279
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
280
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
280
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
281
		return $contenu;
281
		return $contenu;
282
	}
282
	}
283
	
283
	
284
	private function getServiceSimple() {
284
	private function getServiceSimple() {
285
		if (isset($this->parametres[0])) {
285
		if (isset($this->parametres[0])) {
286
			$this->format_image = $this->parametres[0];
286
			$this->format_image = $this->parametres[0];
287
		}
287
		}
288
		
288
		
289
		// Construction de la requête
289
		// Construction de la requête
290
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original '.
290
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original '.
291
			'FROM cel_obs_images AS coi '.
291
			'FROM cel_obs_images AS coi '.
292
			'LEFT JOIN cel_inventory AS ci '.
292
			'LEFT JOIN cel_inventory AS ci '.
293
				'ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
293
				'ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
294
			'LEFT JOIN cel_images AS cim '.
294
			'LEFT JOIN cel_images AS cim '.
295
				'ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '.  
295
				'ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '.  
296
			'WHERE ci.transmission = 1 '.
296
			'WHERE ci.transmission = 1 '.
297
			'	AND ci.identifiant = cim.ci_ce_utilisateur '.
297
			'	AND ci.identifiant = cim.ci_ce_utilisateur '.
298
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'ci_meta_date_ajout DESC').' '.
298
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'ci_meta_date_ajout DESC').' '.
299
			"LIMIT $this->start, $this->limit ";
299
			"LIMIT $this->start, $this->limit ";
300
		
300
		
301
		$elements = $this->executerRequete($requete);
301
		$elements = $this->executerRequete($requete);
302
		
302
		
303
		// Création du contenu
303
		// Création du contenu
304
		$contenu = $this->executerService($elements);
304
		$contenu = $this->executerService($elements);
305
		return $contenu;
305
		return $contenu;
306
	}
306
	}
307
	
307
	
308
	private function creerTitreSimple($element) {
308
	private function creerTitreSimple($element) {
309
		$titre = $element['nom_sel'].' [nn'.$element['num_nom_sel'].'] par '.$this->creerAuteur($element['identifiant'], $this->etreFluxAdmin());
309
		$titre = $element['nom_sel'].' [nn'.$element['num_nom_sel'].'] par '.$this->creerAuteur($element['identifiant'], $this->etreFluxAdmin());
310
		return $titre;
310
		return $titre;
311
	}
311
	}
312
	
312
	
313
	private function creerDescriptionSimple($donnees, $item) {
313
	private function creerDescriptionSimple($donnees, $item) {
314
		$description = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($donnees['num_nom_sel']));
314
		$description = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($donnees['num_nom_sel']));
315
		return $description;
315
		return $description;
316
	}
316
	}
317
	
317
	
318
	private function getServiceComplet() {
318
	private function getServiceComplet() {
319
		// Construction de la requête
319
		// Construction de la requête
-
 
320
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, '.
320
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original, ci_meta_date_ajout, ci_meta_user_comment, ci_note_image '.
321
			'	ci_id_image, ci_nom_original, ci_meta_date_ajout, ci_meta_mots_cles, ci_meta_comment, ci_note_image '.
321
			'FROM cel_obs_images AS coi '.
322
			'FROM cel_images AS cim '.
322
			'LEFT JOIN cel_inventory AS ci '.
323
			'	LEFT JOIN cel_obs_images AS coi '.
323
				'ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
324
			'		ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '.
324
			'LEFT JOIN cel_images AS cim '.
325
			'	LEFT JOIN cel_inventory AS ci '.
325
				'ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '.  
326
			'		ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
326
			'WHERE ci.transmission = 1 '.
327
			(($this->etreFluxAdmin()) ? '' : 'WHERE ci.transmission = 1 ').
327
			'	AND ci.identifiant = cim.ci_ce_utilisateur '.
-
 
328
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'ci_meta_date_ajout DESC').' '.
328
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'ci_meta_date_ajout DESC').' '.
329
			"LIMIT $this->start, $this->limit ";
329
			"LIMIT $this->start, $this->limit ";
330
		
330
		
331
		$elements = $this->executerRequete($requete);
331
		$elements = $this->executerRequete($requete);
332
		
332
 
333
		// Création du contenu
333
		// Création du contenu
-
 
334
		if ($elements != false && count($elements) > 0) {
334
		$contenu = $this->executerService($elements);
335
			$contenu = $this->executerService($elements);
-
 
336
		} else {
-
 
337
			$this->messages[] = "Aucune image disponible.";
-
 
338
		}
-
 
339
 
335
		return $contenu;
340
		return $contenu;
336
	}
341
	}
337
 
342
 
338
	private function creerDescriptionComplet($donnees, $item) {
343
	private function creerDescriptionComplet($donnees, $item) {
-
 
344
		$id_img = $donnees['ci_id_image'];
-
 
345
		$id_obs = $donnees['id'];
339
		$url_img = $this->getUrlImage($donnees['ci_id_image'], 'M');
346
		$url_img = $this->getUrlImage($donnees['ci_id_image'], 'M');
-
 
347
		$auteur = $this->creerAuteur($donnees['identifiant'], $this->etreFluxAdmin());
-
 
348
		$mots_cles_obs = $this->decoderMotsClesObs($donnees['identifiant'], $donnees['mots_cles']);
-
 
349
		$mots_cles_image = $this->decoderMotsClesImg($donnees['identifiant'], $donnees['ci_meta_mots_cles']);
-
 
350
		$lieu = $donnees['location'].' ('.$donnees['id_location'].') > '.$donnees['lieudit'].' > '.$donnees['station'];
-
 
351
		$coordonnees = ($this->etreNull($donnees['coord_x']) && $this->etreNull($donnees['coord_y'])) ? '' : $donnees['coord_x'].'/'.$donnees['coord_y'];
-
 
352
		$date_observation = $this->formaterDate($donnees['date_observation'], '%A %d %B %Y');
-
 
353
		$date_transmission = $this->formaterDate($donnees['date_transmission']);
-
 
354
		$date_modification = $this->formaterDate($donnees['date_modification']);
-
 
355
		$date_creation = $this->formaterDate($donnees['date_creation']);
-
 
356
		$transmission = $donnees['transmission'] == 1 ? "oui ($date_transmission)" : 'non';
-
 
357
		
340
		$description .= '<style>.champ{color:grey} img{float:left;padding:0 20px 0 0;}</style>';
358
		$description = '<style>.champ{color:grey} .gauche{float:left;padding:0 20px 0 0;} ul{list-style-type:none;padding:0;}</style>'.
-
 
359
			'<h2>'."Image #$id_img liée à l'observation #$id_obs".'</h2>'.
341
		$description .= '<img src="'.$url_img.'" alt="'.$donnees['ci_nom_original'].'" />';
360
			'<img class="gauche" src="'.$url_img.'" alt="'.$donnees['ci_nom_original'].'" />'.
342
		$description .= '<ul>';
361
			'<div class="gauche">'.
343
		$description .= '<li>'."Image liée à l'observation ".$donnees['id'].'</li>';
362
			'<h3>'.'Image'.'</h3>'.
-
 
363
			'<ul>'.
344
		$description .= '<li>'.'<span class="champ">Importée le :</span> '.$item['date_maj_simple'].'</li>';
364
			'<li>'.'<span class="champ">Importée le :</span> '.$item['date_maj_simple'].'</li>'.
-
 
365
			'<li>'.'<span class="champ">Par :</span> '.
-
 
366
				(($this->etreFluxAdmin()) ? '<a href="mailto:'.$auteur.'">'.$auteur.'</a>' : $auteur).
-
 
367
			'</li>'.
345
		$description .= '<li>'.'<span class="champ">Nom du fichier :</span> '.$donnees['ci_nom_original'].'</li>';
368
			'<li>'.'<span class="champ">Nom du fichier :</span> '.$donnees['ci_nom_original'].'</li>'.
346
		$description .= '<li>'.'<span class="champ">Note qualité image :</span> '.($donnees['ci_note_image'] +1).'/5</li>';
369
			'<li>'.'<span class="champ">Note qualité :</span> '.($donnees['ci_note_image'] +1).'/5</li>'.
-
 
370
			'<li>'.'<span class="champ">Commentaires :</span> '.$donnees['ci_meta_comment'].'</li>'.
-
 
371
			'<li>'.'<span class="champ">Mots-clés :</span> '.implode(', ', $mots_cles_image).'</li>'.
-
 
372
			'</ul>'.
-
 
373
			'</div>'.
347
		// TODO :traiter le problème du champ commentaire.
374
			// TODO : ajouter le champ commentaire EXIF.
-
 
375
			'<div class="gauche">'.
-
 
376
			'<h3>'.'Observation'.'</h3>'.
-
 
377
			'<ul>'.
348
		//$description .= '<li>'.'<span class="champ">Commentaire :</span> '.$donnees['ci_meta_user_comment'].'</li>';
378
			'<li>'.'<span class="champ">Famille :</span> '.$donnees['famille'].'</li>'.
349
		
-
 
350
		$description .= '<li>'.'<span class="champ">Nom saisi :</span> '.$donnees['nom_sel'].'</li>';
379
			'<li>'.'<span class="champ">Nom saisi :</span> '.$donnees['nom_sel'].'</li>'.
351
		$description .= '<li>'.'<span class="champ">Nom retenu :</span> '.$donnees['nom_ret'].'</li>';
380
			'<li>'.'<span class="champ">Nom retenu :</span> '.$donnees['nom_ret'].'</li>'.
352
		$description .= '<li>'.'<span class="champ">Observée le :</span> '.strftime('%A %d %B %Y', strtotime($donnees['date_observation'])).'</li>';
381
			'<li>'.'<span class="champ">Observée le :</span> '.$date_observation.'</li>'.
-
 
382
			'<li>'.'<span class="champ">Lieu :</span> '.$lieu.'</li>'.
-
 
383
			'<li>'.'<span class="champ">Milieu :</span> '.$donnees['milieu'].'</li>'.
-
 
384
			(($this->etreFluxAdmin()) ? '<li><span class="champ">Coordonnées (Lat/Long) :</span> '.$coordonnees.'</li>' : '').
353
		$description .= '<li>'.'<span class="champ">Lieu :</span> '.$donnees['location'].' ('.$donnees['id_location'].') '.$donnees['station'].' '.$donnees['lieudit'].'</li>';
385
			'<li>'.'<span class="champ">Commentaire :</span> '.$donnees['commentaire'].'</li>'.
-
 
386
			'<li>'.'<span class="champ">Mots-clés :</span> '.implode(', ', $mots_cles_obs).'</li>'.
-
 
387
			(($this->etreFluxAdmin()) ? '<li><span class="champ">Transmis (= public) :</span> '.$transmission.'</li>' : '').
-
 
388
			'<li><span class="champ">Modifiée le :</span> '.$date_modification.'</li>'.
-
 
389
			'<li><span class="champ">Créée le :</span> '.$date_creation.'</li>'.
354
		$description .= '</ul>';
390
			'</ul>'.
-
 
391
			'</div>';
355
		$description = $this->nettoyerTexte($description);
392
		$description = $this->nettoyerTexte($description);
356
		return $description;
393
		return $description;
357
	}
394
	}
-
 
395
	
-
 
396
	private function getServiceParMotsCles() {
-
 
397
		$contenu = '';
-
 
398
		$mot_cle = $this->parametres[0];
-
 
399
 
-
 
400
		if (isset($mot_cle)) {
-
 
401
			$mot_cle_encode = $this->bdd->quote($this->encoderMotCle($mot_cle));
-
 
402
 
-
 
403
			// Construction de la requête
-
 
404
			$requete = 	'SELECT cmc_id_mot_cle_utilisateur, cmc_id_proprietaire '.
-
 
405
				'FROM cel_mots_cles_images '.
-
 
406
				"WHERE cmc_id_mot_cle_general = $mot_cle_encode ";
-
 
407
			$elements = $this->executerRequete($requete);
-
 
408
			
-
 
409
			if ($elements != false && count($elements) > 0) {
-
 
410
				// Pré-construction du where de la requête
-
 
411
				$tpl_where = '(ci_meta_mots_cles LIKE "%%%s%%" AND ci_ce_utilisateur = %s )';
-
 
412
				$requete_where = array();
-
 
413
				foreach ($elements as $occurence) {
-
 
414
					$requete_where[] = sprintf($tpl_where, $occurence['cmc_id_mot_cle_utilisateur'], $this->bdd->quote($occurence['cmc_id_proprietaire']));
-
 
415
				}
-
 
416
				
-
 
417
				// Construction de la requête
-
 
418
				$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, '.
-
 
419
					'	ci_id_image, ci_nom_original, ci_meta_date_ajout, ci_meta_mots_cles, ci_meta_comment, ci_note_image '.
-
 
420
					'FROM cel_images AS cim '.
-
 
421
					'	LEFT JOIN cel_obs_images AS coi '.
-
 
422
					'		ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '.
-
 
423
					'	LEFT JOIN cel_inventory AS ci '.
-
 
424
					'		ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
-
 
425
					'WHERE '.implode(" \nOR ", $requete_where).' '.
-
 
426
					'	'.(($this->etreFluxAdmin()) ? '' : 'AND ci.transmission = 1').' '.
-
 
427
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'ci_meta_date_ajout DESC').' '.
-
 
428
					"LIMIT $this->start, $this->limit ";
-
 
429
				$elements = $this->executerRequete($requete);
-
 
430
				
-
 
431
				// Création du contenu
-
 
432
				$contenu = $this->executerService($elements);
-
 
433
			} else {
-
 
434
				$this->messages[] = "Aucune image ne correspond à ce mot clé.";
-
 
435
			}
-
 
436
		} else {
-
 
437
			$this->messages[] = "Le service demandé nécessite d'indiquer un mot-clé en dernier paramêtre.";
-
 
438
		}
-
 
439
		return $contenu;
-
 
440
	}
-
 
441
	
-
 
442
	private function getServiceParCommune() {
-
 
443
		$contenu = '';
-
 
444
		$commune = $this->parametres[0];
-
 
445
		if (isset($commune)) {
-
 
446
			$commune = $this->bdd->quote($commune);
-
 
447
			
-
 
448
			// Construction de la requête
-
 
449
			$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, '.
-
 
450
			'	ci_id_image, ci_nom_original, ci_meta_date_ajout, ci_meta_mots_cles, ci_meta_comment, ci_note_image '.
-
 
451
			'FROM cel_images AS cim '.
-
 
452
			'	LEFT JOIN cel_obs_images AS coi '.
-
 
453
			'		ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '.
-
 
454
			'	LEFT JOIN cel_inventory AS ci '.
-
 
455
			'		ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
-
 
456
			"WHERE ci.location = $commune ".	
-
 
457
			'	'.(($this->etreFluxAdmin()) ? '' : 'AND ci.transmission = 1').' '.
-
 
458
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'ci_meta_date_ajout DESC').' '.
-
 
459
			"LIMIT $this->start,$this->limit ";
-
 
460
			$elements = $this->executerRequete($requete);
-
 
461
			
-
 
462
			// Création du contenu
-
 
463
			if ($elements != false && count($elements) > 0) {
-
 
464
				$contenu = $this->executerService($elements);
-
 
465
			} else {
-
 
466
				$this->messages[] = "Aucune image ne correspond à cette commune.";
-
 
467
			}
-
 
468
		} else {
-
 
469
			$this->messages[] = "Le service demandé nécessite d'indiquer une nom de commune en dernier paramêtre.";
-
 
470
		}
-
 
471
		return $contenu;
-
 
472
	}
358
}	
473
}	
359
474