Subversion Repositories eFlore/Applications.cel

Rev

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

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