Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 525 Rev 528
1
<?php
1
<?php
2
/**
2
/**
3
 * Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
3
 * Service fournissant des informations concernant le 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
 * Format du service :
6
 * Format du service :
7
 * /CelSyndicationObservation/liste-des-flux
7
 * /CelSyndicationObservation/liste-des-flux
8
 * /CelSyndicationObservation/opml
8
 * /CelSyndicationObservation/opml
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
13
 * 
13
 * 
14
 * Les paramêtres :
14
 * Les paramêtres :
15
 *  - "start" indique le numéro du premier item à afficher
15
 *  - "start" indique le numéro du premier item à afficher
16
 *  - "limit" nombre d'items à afficher
16
 *  - "limit" nombre d'items à afficher
17
 * 
17
 * 
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
21
 * @version $Id$
21
 * @version $Id$
22
 * @copyright 2010
22
 * @copyright 2010
23
 */
23
 */
24
class CelSyndicationObservation extends Cel {
24
class CelSyndicationObservation extends Cel {
-
 
25
	
25
	
26
	private $parametres_origines = null;
26
	private $format = null;
27
	private $format = null;
27
	private $service = null;
-
 
28
	public $parametres = null;
28
	private $service = null;
29
	private $squelette = null;
29
	private $squelette = null;
30
	private $squelette_dossier = null;
30
	private $squelette_dossier = null;
31
	private $flux = array();
31
	private $flux = array();
32
	
32
	
33
	/**
33
	/**
34
	 * Méthode appelée avec une requête de type GET.
34
	 * Méthode appelée avec une requête de type GET.
35
	 */
35
	 */
36
	public function getElement($params = array()) {
36
	public function getElement($params = array()) {
37
		// Initialisation des variables
37
		// Initialisation des variables
-
 
38
		$this->parametres_origines = $params;
38
		$info = array();
39
		$info = array();
39
		$contenu = '';
40
		$contenu = '';
40
		
41
		
41
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
42
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
42
			// Pré traitement des paramêtres
43
			// Pré traitement des paramêtres
43
			$pour_bdd = false;
44
			$pour_bdd = false;
44
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
45
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
45
			extract($p);
46
			extract($p);
46
			$this->parametres = $params;
47
			$this->parametres = $params;
47
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
48
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
48
					
49
					
49
			// Récupération de la liste des flux
50
			// Récupération de la liste des flux
50
			$this->chargerListeDesFlux();
51
			$this->chargerListeDesFlux();
51
			
52
			
52
			// Chargement du bon type de service demandé
53
			// Chargement du bon type de service demandé
53
			if (isset($service)) {
54
			if (isset($service)) {
54
				$this->service = $this->traiterNomService($service);
55
				$this->service = $this->traiterNomService($service);
55
				$methode = $this->getNomMethodeService();
56
				$methode = $this->getNomMethodeService();
56
				if (method_exists($this, $methode)) {
57
				if (method_exists($this, $methode)) {
57
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
58
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
58
						// Mise en minuscule de l'indication du format
59
						// Mise en minuscule de l'indication du format
59
						$this->format = strtolower($format);
60
						$this->format = strtolower($format);
60
						// Définition du fichier squelette demandé
61
						// Définition du fichier squelette demandé
61
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
62
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
62
					} else if (isset($this->flux[$this->service])) {
63
					} else if (isset($this->flux[$this->service])) {
63
						$this->format = '';
64
						$this->format = '';
64
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
65
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
65
					}
66
					}
66
	
67
	
67
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
68
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
68
						// Suppression des paramêtres inutile pour le reste des méthodes
69
						// Suppression des paramêtres inutile pour le reste des méthodes
69
						array_shift($this->parametres);
70
						array_shift($this->parametres);
70
						array_shift($this->parametres);
71
						array_shift($this->parametres);
71
						
72
						
72
						// Récupération du contenu à renvoyer
73
						// Récupération du contenu à renvoyer
73
						$contenu = $this->$methode();
74
						$contenu = $this->$methode();
74
					}
75
					}
75
				} else {
76
				} else {
76
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
77
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
77
				}
78
				}
78
			} else {
79
			} else {
79
				$this->messages[] = "Le service CEL Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
80
				$this->messages[] = "Le service CEL Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
80
			}
81
			}
81
		}
82
		}
82
		
83
		
83
		// Envoie sur la sortie standard
84
		// Envoie sur la sortie standard
84
		$encodage = 'utf-8';
85
		$encodage = 'utf-8';
85
		$mime = $this->getTypeMime();
86
		$mime = $this->getTypeMime();
86
		$formatage_json = $this->getFormatageJson();
87
		$formatage_json = $this->getFormatageJson();
87
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
88
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
88
	}
89
	}
89
	
90
	
90
	private function getUrlBase() {
91
	private function getUrlBase() {
91
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
92
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
92
		return $url_base;
93
		return $url_base;
93
	}
94
	}
94
	
95
	
95
	private function getUrlServiceBase() {
96
	private function getUrlServiceBase() {
96
		$url_service = $this->getUrlBase().$this->service.'/'.$this->format;
97
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
97
		return $url_service;
98
		return $url_service;
98
	}
99
	}
99
	
100
	
100
	private function traiterNomService($nom) {
101
	private function traiterNomService($nom) {
101
		$nom = strtolower($nom);
102
		$nom = strtolower($nom);
102
		return $nom;
103
		return $nom;
103
	}
104
	}
104
	
105
	
105
	private function getNomMethodeService() {
106
	private function getNomMethodeService() {
106
		$methode = '';
107
		$methode = '';
107
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
108
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
108
		$methode = 'getService'.$service_formate;
109
		$methode = 'getService'.$service_formate;
109
		return $methode;
110
		return $methode;
110
	}
111
	}
111
	
112
	
112
	private function getTypeMime() {
113
	private function getTypeMime() {
113
		$mime = '';
114
		$mime = '';
114
		$test = isset($this->format) ? $this->format : $this->service; 
115
		$test = isset($this->format) ? $this->format : $this->service; 
115
		switch ($test) {
116
		switch ($test) {
116
			case 'atom' :
117
			case 'atom' :
117
				$mime = 'application/atom+xml';
118
				$mime = 'application/atom+xml';
118
				break;
119
				break;
119
			case 'rss1' :
120
			case 'rss1' :
120
			case 'rss2' :
121
			case 'rss2' :
121
				$mime = 'application/rss+xml';
122
				$mime = 'application/rss+xml';
122
				break;
123
				break;
123
			case 'opml' :
124
			case 'opml' :
124
				$mime = 'text/x-opml';
125
				$mime = 'text/x-opml';
125
				break;
126
				break;
126
			default:
127
			default:
127
				$mime = 'text/html';
128
				$mime = 'text/html';
128
		}
129
		}
129
		return $mime;
130
		return $mime;
130
	}
131
	}
131
	
132
	
132
	private function getFormatageJson() {
133
	private function getFormatageJson() {
133
		$json = false;
134
		$json = false;
134
		switch ($this->service) {
135
		switch ($this->service) {
135
			case 'liste-des-flux' :
136
			case 'liste-des-flux' :
136
				$json = true;
137
				$json = true;
137
				break;
138
				break;
138
			default:
139
			default:
139
				$json = false;
140
				$json = false;
140
		}
141
		}
141
		return $json;
142
		return $json;
142
	}
143
	}
143
	
144
	
144
	private function getFlux($nom) {
145
	private function getFlux($nom) {
145
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
146
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
146
	}
147
	}
147
 
148
 
148
	private function setFlux($nom, $titre, $description) {
149
	private function setFlux($nom, $titre, $description) {
149
		$url_base = $this->getUrlBase();
150
		$url_base = $this->getUrlBase();
150
		$formats = array('atom', 'rss2', 'rss1');
151
		$formats = array('atom', 'rss2', 'rss1');
151
		$flux = array();
152
		$flux = array();
152
		foreach ($formats as $format) {
153
		foreach ($formats as $format) {
153
			$url = $url_base.$nom.'/'.$format;
154
			$url = $url_base.$nom.'/'.$format;
154
			$flux[$format] = $url;
155
			$flux[$format] = $url;
155
		}
156
		}
156
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
157
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
157
	}
158
	}
158
	
159
	
159
	private function chargerListeDesFlux() {
160
	private function chargerListeDesFlux() {
160
		$this->setFlux('par-defaut', 'Flux de syndication des observations publiques du CEL', 
161
		$this->setFlux('par-defaut', 'Flux de syndication des observations publiques du CEL', 
161
			'Ce flux fournit des informations sur les observations du CEL.');
162
			'Ce flux fournit des informations sur les observations du CEL.');
162
		$this->setFlux('par-mots-cles', 'Flux de syndication des observations publiques du CEL filtrées par mots clés', 
163
		$this->setFlux('par-mots-cles', 'Flux de syndication des observations publiques du CEL filtrées par mots clés', 
163
			"Ce flux fournit des informations sur les observations du CEL filtrées par mots-clés. Il nécessite d'être 
164
			"Ce flux fournit des informations sur les observations du CEL filtrées par mots-clés. Il nécessite d'être 
164
			paramétré en indiquant en dernier position de l'url le mot-clé à rechercher.");
165
			paramétré en indiquant en dernier position de l'url le mot-clé à rechercher.");
165
		$this->setFlux('par-commune','Flux de syndication des observations publiques du CEL filtrées par commune',
166
		$this->setFlux('par-commune','Flux de syndication des observations publiques du CEL filtrées par commune',
166
			"Ce flux fournit des informations sur les observations du CEL filtrées par commune. Il nécessite d'être 
167
			"Ce flux fournit des informations sur les observations du CEL filtrées par commune. Il nécessite d'être 
167
			paramétré en indiquant en dernier position de l'url le nom de la commune à rechercher.");
168
			paramétré en indiquant en dernier position de l'url le nom de la commune à rechercher.");
168
	}
169
	}
169
	
170
	
170
	private function getServiceListeDesFlux() {
171
	private function getServiceListeDesFlux() {
171
		return $this->flux;
172
		return $this->flux;
172
	}
173
	}
173
	
174
	
174
	private function getServiceOpml() {
175
	private function getServiceOpml() {
175
		$donnees = array();
176
		$donnees = array();
176
		$id = 1;
177
		$id = 1;
177
		foreach ($this->flux as $flux_nom => $flux){
178
		foreach ($this->flux as $flux_nom => $flux){
178
			$info = array();
179
			$info = array();
179
			$info['type'] = 'atom';
180
			$info['type'] = 'atom';
180
			$info['titre'] = $flux['titre'];
181
			$info['titre'] = $flux['titre'];
181
			$info['texte'] = "CEL - Obs - $flux_nom";
182
			$info['texte'] = "CEL - Obs - $flux_nom";
182
			$info['description'] = $flux['description'];
183
			$info['description'] = $flux['description'];
183
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
184
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
184
			$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
185
			$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
185
			$donnees['liste_flux'][] = $info;
186
			$donnees['liste_flux'][] = $info;
186
		}
187
		}
187
		
188
		
188
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
189
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
189
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
190
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
190
		return $contenu;
191
		return $contenu;
191
	}
192
	}
192
	
193
	
193
	private function getServiceParDefaut() {
194
	private function getServiceParDefaut() {
194
		// Construction de la requête
195
		// Construction de la requête
195
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
196
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
196
			'FROM cel_inventory '.
197
			'FROM cel_inventory '.
197
			'WHERE transmission = 1 '.
198
			(($this->etreFluxAdmin()) ? '' : 'WHERE transmission = 1 ').
198
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
-
 
199
			"LIMIT $this->start,$this->limit ";
-
 
200
		
-
 
201
		$elements = $this->executerRequete($requete);
-
 
202
		
-
 
203
		// Création du contenu
-
 
204
		$contenu = $this->executerService($elements);
-
 
205
		return $contenu;
-
 
206
	}
-
 
207
	
-
 
208
	private function getServicePourAdmin() {
-
 
209
		// Construction de la requête
-
 
210
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
-
 
211
			'FROM cel_inventory '.
-
 
212
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
199
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
213
			"LIMIT $this->start,$this->limit ";
200
			"LIMIT $this->start,$this->limit ";
214
		
201
		
215
		$elements = $this->executerRequete($requete);
202
		$elements = $this->executerRequete($requete);
216
		
203
		
217
		// Création du contenu
204
		// Création du contenu
218
		$contenu = $this->executerService($elements);
205
		$contenu = $this->executerService($elements);
219
		return $contenu;
206
		return $contenu;
220
	}
207
	}
221
	
208
	
222
	private function getServiceParMotsCles() {
209
	private function getServiceParMotsCles() {
223
		$contenu = '';
210
		$contenu = '';
224
		$mot_cle = $this->parametres[0];
211
		$mot_cle = $this->parametres[0];
225
 
212
 
226
		if (isset($mot_cle)) {
213
		if (isset($mot_cle)) {
227
			$mot_cle_encode = $this->bdd->quote($this->encoderMotCle($mot_cle));
214
			$mot_cle_encode = $this->bdd->quote($this->encoderMotCle($mot_cle));
228
 
215
 
229
			// Construction de la requête
216
			// Construction de la requête
230
			$requete = 	'SELECT * '.
217
			$requete = 	'SELECT * '.
231
				'FROM cel_mots_cles_obs '.
218
				'FROM cel_mots_cles_obs '.
232
				"WHERE cmc_id_mot_cle_general = $mot_cle_encode ";
219
				"WHERE cmc_id_mot_cle_general = $mot_cle_encode ";
233
			$elements = $this->executerRequete($requete);
220
			$elements = $this->executerRequete($requete);
234
			
221
			
235
			if ($elements != false && count($elements) > 0) {
222
			if ($elements != false && count($elements) > 0) {
236
				// Pré-construction du where de la requête
223
				// Pré-construction du where de la requête
237
				$tpl_where = '(mots_cles LIKE "%%%s%%" AND identifiant = %s )';
224
				$tpl_where = '(mots_cles LIKE "%%%s%%" AND identifiant = %s )';
238
				$requete_where = array();
225
				$requete_where = array();
239
				foreach ($elements as $occurence) {
226
				foreach ($elements as $occurence) {
240
					$requete_where[] = sprintf($tpl_where, $occurence['cmc_id_mot_cle_utilisateur'], $this->bdd->quote($occurence['cmc_id_proprietaire']));
227
					$requete_where[] = sprintf($tpl_where, $occurence['cmc_id_mot_cle_utilisateur'], $this->bdd->quote($occurence['cmc_id_proprietaire']));
241
				}
228
				}
242
				
229
				
243
				// Construction de la requête
230
				// Construction de la requête
244
				$requete = 	'SELECT * '.
231
				$requete = 	'SELECT * '.
245
					'FROM cel_inventory '.
232
					'FROM cel_inventory '.
246
					'WHERE transmission = 1 '.
233
					'WHERE '.implode(" \nOR ", $requete_where).' '.
247
					'AND '.implode(" \nOR ", $requete_where).' '.
234
					'	'.(($this->etreFluxAdmin()) ? '' : 'AND transmission = 1 ').
248
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification, date_creation DESC').' '.
235
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification, date_creation DESC').' '.
249
					"LIMIT $this->start,$this->limit ";
236
					"LIMIT $this->start,$this->limit ";
250
				$elements = $this->executerRequete($requete);
237
				$elements = $this->executerRequete($requete);
251
				
238
				
252
				// Création du contenu
239
				// Création du contenu
253
				$contenu = $this->executerService($elements);
240
				$contenu = $this->executerService($elements);
254
			} else {
241
			} else {
255
				$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
242
				$this->messages[] = "Aucune observation ne correspond à ce mot clé.";
256
			}
243
			}
257
		} else {
244
		} else {
258
			$this->messages[] = "Le service demandé nécessite d'indiquer un mot-clé en dernier paramêtre.";
245
			$this->messages[] = "Le service demandé nécessite d'indiquer un mot-clé en dernier paramêtre.";
259
		}
246
		}
260
		return $contenu;
247
		return $contenu;
261
	}
248
	}
262
	
249
	
263
	private function getServiceParCommune() {
250
	private function getServiceParCommune() {
264
		$contenu = '';
251
		$contenu = '';
265
		$commune = $this->parametres[0];
252
		$commune = $this->parametres[0];
266
		if (isset($commune)) {
253
		if (isset($commune)) {
267
			$commune = $this->bdd->quote($commune);
254
			$commune = $this->bdd->quote($commune);
268
			
255
			
269
			// Construction de la requête
256
			// Construction de la requête
270
			$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
257
			$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
271
				'FROM cel_inventory '.
258
				'FROM cel_inventory '.
272
				'WHERE transmission = 1 '.
259
				"WHERE location = $commune ".
273
				"AND location = $commune ".
260
				'	'.(($this->etreFluxAdmin()) ? '' : 'AND transmission = 1 ').
274
				'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC, location ASC').' '.
261
				'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC, location ASC').' '.
275
				"LIMIT $this->start,$this->limit ";
262
				"LIMIT $this->start,$this->limit ";
276
			
263
			
277
			$elements = $this->executerRequete($requete);
264
			$elements = $this->executerRequete($requete);
278
			
265
			
279
			// Création du contenu
266
			// Création du contenu
280
			$contenu = $this->executerService($elements);
267
			$contenu = $this->executerService($elements);
281
		} else {
268
		} else {
282
			$this->messages[] = "Le service demandé nécessite d'indiquer une nom de commune en dernier paramêtre.";
269
			$this->messages[] = "Le service demandé nécessite d'indiquer une nom de commune en dernier paramêtre.";
283
		}
270
		}
284
		return $contenu;
271
		return $contenu;
285
	}
272
	}
286
	
273
	
287
	private function executerService($elements) {
274
	private function executerService($elements) {
288
		$contenu = '';
275
		$contenu = '';
289
		if (is_array($elements)) {
276
		if (is_array($elements)) {
290
			// Prétraitement des données
277
			// Prétraitement des données
291
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
278
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
292
			
279
			
293
			foreach ($elements as $element) {
280
			foreach ($elements as $element) {
294
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
281
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
295
			}
282
			}
296
			
283
			
297
			// Création du contenu à partir d'un template PHP
284
			// Création du contenu à partir d'un template PHP
298
			if (isset($this->squelette)) {
285
			if (isset($this->squelette)) {
299
				$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
286
				$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
300
			}
287
			}
301
		}		
288
		}		
302
		return $contenu;
289
		return $contenu;
303
	}
290
	}
304
	
291
	
305
	private function construireDonneesCommunesAuFlux($observations) {
292
	private function construireDonneesCommunesAuFlux($observations) {
306
		$donnees = $this->getFlux($this->service);
293
		$donnees = $this->getFlux($this->service);
307
		$donnees['guid'] = $this->getUrlServiceBase();
294
		$donnees['guid'] = $this->getUrlServiceBase();
308
		$donnees['lien_service'] = $this->creerUrlService();
295
		$donnees['lien_service'] = $this->creerUrlService();
309
		$donnees['lien_cel'] = $this->config['settings']['celUrlAbsolu'];
296
		$donnees['lien_cel'] = $this->config['settings']['celUrlAbsolu'];
310
		$donnees['editeur'] = $this->config['settings']['editeur'];
297
		$donnees['editeur'] = $this->config['settings']['editeur'];
311
		$derniere_info_en_date = reset($observations);
298
		$derniere_info_en_date = reset($observations);
312
		$date_modification_timestamp = strtotime($derniere_info_en_date['date_modification']);
299
		$date_modification_timestamp = strtotime($derniere_info_en_date['date_modification']);
313
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
300
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
314
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
301
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
315
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
302
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
316
		$donnees['annee_courante'] = date('Y');
303
		$donnees['annee_courante'] = date('Y');
317
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationObservation';
304
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationObservation';
318
		preg_match('/([0-9]+)/', '$Revision$', $match);
305
		preg_match('/([0-9]+)/', '$Revision$', $match);
319
		$donnees['generateur_version'] = $match[1];
306
		$donnees['generateur_version'] = $match[1];
320
		return $donnees; 
307
		return $donnees; 
321
	}
308
	}
322
	
309
	
323
	private function construireDonneesCommunesAuxItems($observation) {
310
	private function construireDonneesCommunesAuxItems($observation) {
324
		$item = array();
311
		$item = array();
325
		$date_modification_timestamp = strtotime($observation['date_modification']);
312
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['date_modification']);
326
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
313
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
327
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
314
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
328
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
315
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
329
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
316
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
330
		$item['date_creation_simple'] = strftime('%A %d %B %Y à %H:%M', strtotime($observation['date_creation']));
317
		$item['date_creation_simple'] = strftime('%A %d %B %Y à %H:%M', strtotime($observation['date_creation']));
331
		$item['titre'] = $this->creerTitre($observation);
318
		$item['titre'] = $this->creerTitre($observation);
332
		$item['guid'] = $this->creerGuidItem($observation);
319
		$item['guid'] = $this->creerGuidItem($observation);
333
		$item['lien'] = $this->creerLienItem($observation);
320
		$item['lien'] = $this->creerLienItem($observation);
334
		$item['description'] = $this->creerDescription($observation, $item);
-
 
335
		$item['categorie'] = $this->creerCategorie($item);
321
		$item['categorie'] = $this->creerCategorie($item);
-
 
322
		$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
336
		$item['description_encodee'] = htmlspecialchars($item['description']);
323
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
337
		$item['modifier_par'] = $this->creerAuteur($observation['identifiant'], $this->etreFluxAdmin());
324
		$item['modifier_par'] = $this->creerAuteur($observation['identifiant'], $this->etreFluxAdmin());
338
		return $item;
325
		return $item;
339
	}
326
	}
340
	
327
	
341
	private function creerTitre($obs) {
328
	private function creerTitre($obs) {
342
		$nom_plante = $obs['nom_sel'].' [nn'.$obs['num_nom_sel'].']';
329
		$nom_plante = $obs['nom_sel'].' [nn'.$obs['num_nom_sel'].']';
343
		$lieu = $obs['location'].' ('.$obs['id_location'].')';
330
		$lieu = $obs['location'].' ('.$obs['id_location'].')';
344
		$utilisateur = $this->creerAuteur($obs['identifiant'], $this->etreFluxAdmin());
331
		$utilisateur = $this->creerAuteur($obs['identifiant'], $this->etreFluxAdmin());
345
		$titre = "$nom_plante à $lieu par $utilisateur";
332
		$titre = "$nom_plante à $lieu par $utilisateur";
346
		$titre = $this->nettoyerTexte($titre);
333
		$titre = $this->nettoyerTexte($titre);
347
		return $titre;
334
		return $titre;
348
	}
335
	}
349
	
336
	
350
	private function creerGuidItem($element) {
337
	private function creerGuidItem($element) {
351
		$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['id']);
338
		$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['id']);
352
		return $guid;
339
		return $guid;
353
	}
340
	}
354
	
341
	
355
	private function creerLienItem($element) {
342
	private function creerLienItem($element) {
356
		$lien = null;
343
		$lien = null;
357
		if ($element['num_nom_sel'] != 0) {
344
		if ($element['num_nom_sel'] != 0) {
358
			$lien = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['num_nom_sel']));
345
			$lien = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['num_nom_sel']));
359
		}
346
		}
360
		return $lien;
347
		return $lien;
361
	}
348
	}
362
	
349
	
363
	private function creerDescription($obs, $item) {
350
	private function creerDescription($obs, $item) {
-
 
351
		$id_obs = $donnees['id'];
-
 
352
		$famille = $obs['famille'];
-
 
353
		$nom_saisi = $obs['nom_sel'];
-
 
354
		$nom_retenu = $obs['nom_ret'];
-
 
355
		$auteur = $this->creerAuteur($obs['identifiant'], $this->etreFluxAdmin());
-
 
356
		$mots_cles_obs = $this->decoderMotsClesObs($obs['identifiant'], $obs['mots_cles']);
364
		$lien_correction = sprintf($this->config['settings']['phpEditUrlTpl'], $obs['id']);
357
		$lien_correction = sprintf($this->config['settings']['phpEditUrlTpl'], $obs['id']);
-
 
358
		$lieu = $obs['location'].' ('.$obs['id_location'].') > '.$obs['lieudit'].' > '.$obs['station'];
365
		$description = 
359
		$milieu = $obs['milieu'];
-
 
360
		$coordonnees = ($this->etreNull($obs['coord_x']) && $this->etreNull($obs['coord_y'])) ? '' : $obs['coord_x'].'/'.$obs['coord_y'];
-
 
361
		$commentaire = htmlspecialchars($obs['commentaire']);
-
 
362
		$date_observation = $this->formaterDate($obs['date_observation'], '%A %d %B %Y');
-
 
363
		$date_transmission = $this->formaterDate($obs['date_transmission']);
-
 
364
		$date_modification = $this->formaterDate($obs['date_modification']);
-
 
365
		$date_creation = $this->formaterDate($obs['date_creation']);
-
 
366
		$transmission = $obs['transmission'] == 1 ? "oui ($date_transmission)" : 'non';
-
 
367
		
-
 
368
		$description = '<h2>'."Observation #$id_obs de $nom_saisi".'</h2>'.
366
			'<ul>'.
369
			'<ul>'.
-
 
370
			'<li>'.'Famille : '.$famille.'</li>'.
367
			'	<li>Nom saisi : '.$obs['nom_sel'].'</li>'.
371
			'<li>'.'Nom saisi : '.$nom_saisi.'</li>'.
368
			(($obs['nom_sel'] != $obs['nom_ret']) ? '	<li>Nom retenu : '.$obs['nom_ret'].'</li>' : '').
372
			'<li>'.'Nom retenu : '.$nom_retenu.'</li>'.
369
			'	<li>Lieu : '.$obs['location'].' ('.$obs['id_location'].')</li>'.
373
			'<li>'.'Observée le : '.$date_observation.'</li>'.
-
 
374
			'<li>'.'Lieu : '.$lieu.'</li>'.
370
			($this->etreNull($obs['station']) ? '': '	<li>Station : '.$obs['station'].'</li>').
375
			'<li>'.'Milieu : '.$milieu.'</li>'.
371
			($this->etreNull($obs['milieu']) ? '': '	<li>Milieu : '.$obs['milieu'].'</li>').
376
			(($this->etreFluxAdmin()) ? '<li>Coordonnées (Lat/Long) : '.$coordonnees.'</li>' : '').
372
			($this->etreNull($obs['commentaire']) ? '': '	<li>Commentaire : '.$obs['commentaire'].'</li>').
377
			'<li>'.'Commentaire : '.$commentaire.'</li>'.
-
 
378
			'<li>'.'Mots-clés : '.implode(', ', $mots_cles_obs).'</li>'.
373
			(($this->etreFluxAdmin()) ? '	<li>Transmis (= public) : '.($obs['transmission'] == 1 ? 'oui' : 'non').'</li>' : '').
379
			(($this->etreFluxAdmin()) ? '<li>Transmis (= public) : '.$transmission.'</li>' : '').
374
			'	<li>Modifiée le : '.$item['date_maj_simple'].'</li>'.
380
			'<li>Modifiée le : '.$date_modification.'</li>'.
375
			'	<li>Créée le : '.$item['date_creation_simple'].'</li>'. 
381
			'<li>Créée le : '.$date_creation.'</li>'.
376
			(($this->etreFluxAdmin()) ? '	<li><a href="'.$lien_correction.'">Corriger cette observation</a></li>' : '').
382
			(($this->etreFluxAdmin()) ? '<li><a href="'.$lien_correction.'">Corriger cette observation</a></li>' : '').
377
			'</ul>';
383
			'</ul>';
378
		$description = $this->nettoyerTexte($description);
384
		$description = $this->nettoyerTexte($description);
379
		return $description;
385
		return $description;
380
	}
386
	}
381
	
387
	
382
	private function creerCategorie($element) {
388
	private function creerCategorie($element) {
383
		$categorie = '';
389
		$categorie = '';
384
		$categorie = 'Observation';
390
		$categorie = 'Observation';
385
		$categorie = $this->nettoyerTexte($categorie);
391
		$categorie = $this->nettoyerTexte($categorie);
386
		return $categorie;
392
		return $categorie;
387
	}
393
	}
388
	
394
	
389
	private function etreFluxAdmin() {
395
	private function etreFluxAdmin() {
390
		return ($this->service == 'pour-admin' || $_GET['admin'] == '1') ? true : false;
396
		return ($_GET['admin'] == '1') ? true : false;
391
	}
397
	}
392
	
398
	
393
	private function creerUrlService() {
399
	private function creerUrlService() {
394
		$url_service = $this->getUrlServiceBase();
400
		$url_service = $this->getUrlServiceBase();
395
		if (isset($this->start) || isset($this->limit)) {
-
 
396
			$arguments = array();
-
 
397
			if (isset($this->start) && isset($_GET['start'])) {
-
 
398
				$arguments[] = 'start='.$this->start;
-
 
399
			}
-
 
400
			if (isset($this->limit) && isset($_GET['limit'])) {
-
 
401
				$arguments[] = 'limit='.($this->limit);
-
 
402
			}
-
 
403
			if (count($arguments) > 0) {
401
		if (count($_GET) > 0) {
404
				$url_service .= '?'.implode('&', $arguments);
402
			$url_service .= '?'.implode('&', $_GET);
405
			}
-
 
406
		}
403
		}
407
		return $url_service;
404
		return $url_service;
408
	}
405
	}
409
}	
406
}