416 |
aurelien |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
|
|
|
4 |
* Encodage en entrée : utf8
|
|
|
5 |
* Encodage en sortie : utf8
|
|
|
6 |
* Format du service :
|
|
|
7 |
* /CelSyndicationObservation/liste-des-flux
|
|
|
8 |
* /CelSyndicationObservation/opml
|
|
|
9 |
* /CelSyndicationObservation/par-defaut/(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
|
|
|
12 |
* /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
|
|
|
13 |
*
|
|
|
14 |
* Les paramêtres :
|
|
|
15 |
* - "start" indique le numéro du premier item à afficher
|
|
|
16 |
* - "limit" nombre d'items à afficher
|
|
|
17 |
*
|
|
|
18 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
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>
|
|
|
21 |
* @version $Id$
|
|
|
22 |
* @copyright 2010
|
|
|
23 |
*/
|
|
|
24 |
class CelSyndicationObservation extends Cel {
|
|
|
25 |
|
528 |
jpm |
26 |
private $parametres_origines = null;
|
416 |
aurelien |
27 |
private $format = null;
|
|
|
28 |
private $service = null;
|
|
|
29 |
private $squelette = null;
|
|
|
30 |
private $squelette_dossier = null;
|
790 |
delphine |
31 |
private $auteurs = array();
|
416 |
aurelien |
32 |
private $flux = array();
|
715 |
delphine |
33 |
private $criteres = array(
|
741 |
delphine |
34 |
'utilisateur' => 'identifiant',
|
715 |
delphine |
35 |
'commune' => 'location',
|
741 |
delphine |
36 |
'dept' => 'id_location',
|
715 |
delphine |
37 |
'taxon' => 'nom_ret',
|
|
|
38 |
'commentaire' => 'commentaire',
|
|
|
39 |
'date' => 'date_observation',
|
|
|
40 |
'projet' => 'mots-cles');
|
416 |
aurelien |
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Méthode appelée avec une requête de type GET.
|
|
|
44 |
*/
|
|
|
45 |
public function getElement($params = array()) {
|
|
|
46 |
// Initialisation des variables
|
528 |
jpm |
47 |
$this->parametres_origines = $params;
|
416 |
aurelien |
48 |
$info = array();
|
|
|
49 |
$contenu = '';
|
|
|
50 |
|
536 |
jpm |
51 |
if (! $this->etreFluxAdmin() || $this->authentifierAdmin()) {
|
525 |
jpm |
52 |
// Pré traitement des paramêtres
|
|
|
53 |
$pour_bdd = false;
|
|
|
54 |
$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
|
|
|
55 |
extract($p);
|
|
|
56 |
$this->parametres = $params;
|
|
|
57 |
$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
|
416 |
aurelien |
58 |
|
525 |
jpm |
59 |
// Récupération de la liste des flux
|
|
|
60 |
$this->chargerListeDesFlux();
|
|
|
61 |
|
|
|
62 |
// Chargement du bon type de service demandé
|
|
|
63 |
if (isset($service)) {
|
|
|
64 |
$this->service = $this->traiterNomService($service);
|
|
|
65 |
$methode = $this->getNomMethodeService();
|
|
|
66 |
if (method_exists($this, $methode)) {
|
|
|
67 |
if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
|
|
|
68 |
// Mise en minuscule de l'indication du format
|
|
|
69 |
$this->format = strtolower($format);
|
|
|
70 |
// Définition du fichier squelette demandé
|
|
|
71 |
$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
|
|
|
72 |
} else if (isset($this->flux[$this->service])) {
|
|
|
73 |
$this->format = '';
|
|
|
74 |
$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
if (!isset($this->flux[$this->service]) || isset($this->format)) {
|
|
|
78 |
// Suppression des paramêtres inutile pour le reste des méthodes
|
|
|
79 |
array_shift($this->parametres);
|
|
|
80 |
array_shift($this->parametres);
|
|
|
81 |
|
|
|
82 |
// Récupération du contenu à renvoyer
|
|
|
83 |
$contenu = $this->$methode();
|
|
|
84 |
}
|
|
|
85 |
} else {
|
|
|
86 |
$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
|
416 |
aurelien |
87 |
}
|
|
|
88 |
} else {
|
525 |
jpm |
89 |
$this->messages[] = "Le service CEL Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
|
416 |
aurelien |
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
// Envoie sur la sortie standard
|
|
|
94 |
$encodage = 'utf-8';
|
|
|
95 |
$mime = $this->getTypeMime();
|
|
|
96 |
$formatage_json = $this->getFormatageJson();
|
|
|
97 |
$this->envoyer($contenu, $mime, $encodage, $formatage_json);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
private function getUrlBase() {
|
637 |
jpm |
101 |
$url_base = sprintf($this->config['settings']['baseURLAbsolu'], get_class($this).'/');
|
416 |
aurelien |
102 |
return $url_base;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
private function getUrlServiceBase() {
|
528 |
jpm |
106 |
$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
|
416 |
aurelien |
107 |
return $url_service;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
private function traiterNomService($nom) {
|
|
|
111 |
$nom = strtolower($nom);
|
|
|
112 |
return $nom;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
private function getNomMethodeService() {
|
|
|
116 |
$methode = '';
|
|
|
117 |
$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
|
|
|
118 |
$methode = 'getService'.$service_formate;
|
|
|
119 |
return $methode;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
private function getTypeMime() {
|
|
|
123 |
$mime = '';
|
|
|
124 |
$test = isset($this->format) ? $this->format : $this->service;
|
|
|
125 |
switch ($test) {
|
|
|
126 |
case 'atom' :
|
|
|
127 |
$mime = 'application/atom+xml';
|
|
|
128 |
break;
|
|
|
129 |
case 'rss1' :
|
|
|
130 |
case 'rss2' :
|
|
|
131 |
$mime = 'application/rss+xml';
|
|
|
132 |
break;
|
|
|
133 |
case 'opml' :
|
|
|
134 |
$mime = 'text/x-opml';
|
|
|
135 |
break;
|
|
|
136 |
default:
|
|
|
137 |
$mime = 'text/html';
|
|
|
138 |
}
|
|
|
139 |
return $mime;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
private function getFormatageJson() {
|
|
|
143 |
$json = false;
|
|
|
144 |
switch ($this->service) {
|
|
|
145 |
case 'liste-des-flux' :
|
|
|
146 |
$json = true;
|
|
|
147 |
break;
|
|
|
148 |
default:
|
|
|
149 |
$json = false;
|
|
|
150 |
}
|
|
|
151 |
return $json;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
private function getFlux($nom) {
|
|
|
155 |
return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
private function setFlux($nom, $titre, $description) {
|
|
|
159 |
$url_base = $this->getUrlBase();
|
|
|
160 |
$formats = array('atom', 'rss2', 'rss1');
|
|
|
161 |
$flux = array();
|
|
|
162 |
foreach ($formats as $format) {
|
|
|
163 |
$url = $url_base.$nom.'/'.$format;
|
|
|
164 |
$flux[$format] = $url;
|
|
|
165 |
}
|
|
|
166 |
$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
private function chargerListeDesFlux() {
|
|
|
170 |
$this->setFlux('par-defaut', 'Flux de syndication des observations publiques du CEL',
|
|
|
171 |
'Ce flux fournit des informations sur les observations du CEL.');
|
742 |
delphine |
172 |
$this->setFlux('par-mots-cles', 'Flux de syndication obsolète',
|
|
|
173 |
"Ce flux est désormais accessible via le flux multicriteres/atom/M?tag='mot-cle'.");
|
|
|
174 |
$this->setFlux('par-commune','Flux de syndication obsolète',
|
|
|
175 |
"Ce flux est désormais accessible via le flux multicriteres/atom/M?commune='commune'.");
|
|
|
176 |
$this->setFlux('multicriteres','Flux de syndication des nouvelles observations publiques du CEL '.
|
|
|
177 |
'filtrées par un ou plusieurs critères',
|
|
|
178 |
"Ce flux fournit des informations sur les nouvelles observations du CEL filtrées par ".
|
|
|
179 |
"auteur (mail), commune (nom), departement (code postal), taxon (nom scientifique), commentaire, projet ".
|
|
|
180 |
"et/ou date.");
|
416 |
aurelien |
181 |
}
|
|
|
182 |
|
|
|
183 |
private function getServiceListeDesFlux() {
|
|
|
184 |
return $this->flux;
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
private function getServiceOpml() {
|
|
|
188 |
$donnees = array();
|
|
|
189 |
$id = 1;
|
|
|
190 |
foreach ($this->flux as $flux_nom => $flux){
|
|
|
191 |
$info = array();
|
|
|
192 |
$info['type'] = 'atom';
|
|
|
193 |
$info['titre'] = $flux['titre'];
|
|
|
194 |
$info['texte'] = "CEL - Obs - $flux_nom";
|
|
|
195 |
$info['description'] = $flux['description'];
|
|
|
196 |
$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
|
|
|
197 |
$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
|
|
|
198 |
$donnees['liste_flux'][] = $info;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
|
|
|
202 |
$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
|
|
|
203 |
return $contenu;
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
private function getServiceParDefaut() {
|
|
|
207 |
// Construction de la requête
|
715 |
delphine |
208 |
$requete = (isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
|
416 |
aurelien |
209 |
'FROM cel_inventory '.
|
528 |
jpm |
210 |
(($this->etreFluxAdmin()) ? '' : 'WHERE transmission = 1 ').
|
715 |
delphine |
211 |
'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby : 'date_modification DESC').' '.
|
416 |
aurelien |
212 |
"LIMIT $this->start,$this->limit ";
|
|
|
213 |
|
|
|
214 |
$elements = $this->executerRequete($requete);
|
|
|
215 |
|
|
|
216 |
// Création du contenu
|
|
|
217 |
$contenu = $this->executerService($elements);
|
|
|
218 |
return $contenu;
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
private function getServiceParMotsCles() {
|
743 |
delphine |
222 |
$infos=array();
|
|
|
223 |
$infos[0]['num_nom_sel'] = '';
|
|
|
224 |
$infos[0]['date_modification'] = '2011-06-28';
|
|
|
225 |
$donnees = $this->construireDonneesCommunesAuFlux($infos);
|
|
|
226 |
$donnees['items'][0]['guid'] = 0;
|
|
|
227 |
$donnees['items'][0]['description'] = 'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
|
|
|
228 |
'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?projet=';
|
|
|
229 |
if (isset($this->parametres[0])) {
|
|
|
230 |
$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
|
416 |
aurelien |
231 |
} else {
|
743 |
delphine |
232 |
$donnees['items'][0]['description'] .= '</b>';
|
416 |
aurelien |
233 |
}
|
743 |
delphine |
234 |
$donnees['items'][0]['titre'] = '';
|
|
|
235 |
$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
|
416 |
aurelien |
236 |
return $contenu;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
private function getServiceParCommune() {
|
743 |
delphine |
240 |
$infos=array();
|
|
|
241 |
$infos[0]['num_nom_sel'] = '';
|
|
|
242 |
$infos[0]['date_modification'] = '2011-06-28';
|
|
|
243 |
$donnees = $this->construireDonneesCommunesAuFlux($infos);
|
|
|
244 |
$donnees['items'][0]['guid'] = 0;
|
|
|
245 |
$donnees['items'][0]['description'] = 'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
|
|
|
246 |
'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?commune=';
|
|
|
247 |
if (isset($this->parametres[0])) {
|
|
|
248 |
$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
|
416 |
aurelien |
249 |
} else {
|
743 |
delphine |
250 |
$donnees['items'][0]['description'] .= '</b>';
|
416 |
aurelien |
251 |
}
|
743 |
delphine |
252 |
$donnees['items'][0]['titre'] = '';
|
|
|
253 |
$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
|
416 |
aurelien |
254 |
return $contenu;
|
|
|
255 |
}
|
|
|
256 |
|
715 |
delphine |
257 |
private function getServiceMultiCriteres() {
|
|
|
258 |
$contenu = '';
|
|
|
259 |
if (isset($_GET['debut'])) $this->start = $_GET['debut'];
|
|
|
260 |
if (isset($_GET['limite'])) $this->limite = $_GET['limite'];
|
|
|
261 |
|
|
|
262 |
// Construction de la requête
|
|
|
263 |
$requete = (isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
|
|
|
264 |
'FROM cel_inventory '.
|
|
|
265 |
'WHERE transmission = 1 '.
|
|
|
266 |
' AND ';
|
|
|
267 |
|
|
|
268 |
if ($this->estUneRechercheGenerale()) {
|
|
|
269 |
$chaine_requete = $_GET['recherche'];
|
|
|
270 |
$requete .= $this->creerSousRequeteRechercheGenerale($chaine_requete);
|
|
|
271 |
} else {
|
|
|
272 |
$criteres = $this->traiterCriteresMultiples($_GET) ;
|
|
|
273 |
if (!empty($criteres)) {
|
|
|
274 |
$requete .= $this->creerSousRequeteRechercheParCriteres($criteres);
|
|
|
275 |
}
|
|
|
276 |
}
|
|
|
277 |
$requete = rtrim($requete, 'AND ');
|
|
|
278 |
$requete .= 'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby :
|
|
|
279 |
'date_modification DESC, location ASC').' '.
|
|
|
280 |
"LIMIT $this->start,$this->limit ";
|
|
|
281 |
|
|
|
282 |
$elements = $this->executerRequete($requete);//echo $requete;
|
|
|
283 |
|
|
|
284 |
// Création du contenu
|
|
|
285 |
if ($elements != false && count($elements) > 0) {
|
|
|
286 |
$contenu = $this->executerService($elements);
|
|
|
287 |
} else {
|
|
|
288 |
$this->messages[] = "Aucune observation disponible.";
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
return $contenu;
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
private function creerSousRequeteRechercheParCriteres($criteres) {
|
|
|
295 |
$requete = '';
|
|
|
296 |
foreach ($criteres as $pair) {
|
|
|
297 |
$nom_valeur = explode("=",$pair);
|
|
|
298 |
if (sizeof($nom_valeur) != 0) {
|
|
|
299 |
switch ($nom_valeur[0]) {
|
|
|
300 |
case "ci_limite" : $this->limite = $this->bdd->quote($nom_valeur[1]); break;
|
|
|
301 |
case "commentaire" : $mots_comment_liste = explode(" " , $nom_valeur[1]);
|
|
|
302 |
foreach($mots_comment_liste as $mot_comment) {
|
|
|
303 |
$mot_comment = trim($mot_comment) ;
|
|
|
304 |
$requete .= $nom_valeur[0].' LIKE '.$this->bdd->quote('%'.$mot_comment.'%').' AND ';
|
|
|
305 |
}
|
|
|
306 |
break;
|
|
|
307 |
case "date_observation" :
|
|
|
308 |
$nom_valeur[1] = str_replace('/', '-', $nom_valeur[1]);
|
|
|
309 |
if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $nom_valeur[1], $matches)) {
|
|
|
310 |
$nom_valeur[1] = $matches[3].'-'.$matches[2].'-'.$matches[1];
|
|
|
311 |
}
|
|
|
312 |
$requete .= $nom_valeur[0].'='.$this->bdd->quote($nom_valeur[1]).' AND '; break;
|
|
|
313 |
case "nom_ret" :
|
|
|
314 |
if ($nom_valeur[1] == "indetermine") $nom_valeur[1] = 'null';
|
|
|
315 |
$requete .= ' ('.$nom_valeur[0].' LIKE "%'.$nom_valeur[1].'%" OR nom_sel LIKE "%'.
|
|
|
316 |
$nom_valeur[1].'%") AND '; break;
|
|
|
317 |
case "mots-cles" : $requete .= $this->creerSousRequeteMotsCles($nom_valeur[1]); break;
|
|
|
318 |
default : $requete .= $nom_valeur[0].' = "'.$nom_valeur[1].'" AND '; break;
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
$requete = rtrim($requete,' AND ');
|
|
|
323 |
return $requete;
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
private function creerSousRequeteMotsCles($mot_cle) {
|
|
|
327 |
$requete = 'mots_cles like "inexistant" OR';
|
741 |
delphine |
328 |
if (preg_match('/.*OU.*/', $mot_cle)) {
|
715 |
delphine |
329 |
$requete = $this->creerSousRequeteMotsClesOu($mot_cle);
|
|
|
330 |
} else if (preg_match('/.*ET.*/', $mot_cle)) {
|
|
|
331 |
$requete = $this->creerSousRequeteMotsClesEt($mot_cle);
|
|
|
332 |
} else {
|
|
|
333 |
// Construction de la requête
|
|
|
334 |
$prerequete = 'SELECT * '.
|
|
|
335 |
'FROM cel_mots_cles_obs '.
|
|
|
336 |
'WHERE cmc_id_mot_cle_general = '.$this->bdd->quote($this->encoderMotCle($mot_cle));
|
|
|
337 |
$elements = $this->executerRequete($prerequete);
|
|
|
338 |
if ($elements != false && count($elements) > 0) {
|
|
|
339 |
$requete = '';
|
|
|
340 |
foreach ($elements as $occurence) {
|
|
|
341 |
$requete .= '(mots_cles LIKE "%'.$occurence['cmc_id_mot_cle_utilisateur'].'%" AND identifiant = '.
|
|
|
342 |
$this->bdd->quote($occurence['cmc_id_proprietaire']).' ) OR ';
|
|
|
343 |
}
|
|
|
344 |
}
|
|
|
345 |
}
|
|
|
346 |
$requete = rtrim($requete,' OR ').' AND ';
|
|
|
347 |
return $requete;
|
|
|
348 |
}
|
|
|
349 |
|
|
|
350 |
private function creerSousRequeteMotsClesOu($mot_cle) {
|
|
|
351 |
$requete = 'mots_cles like "inexistant" OR';
|
741 |
delphine |
352 |
$tab_mots_cles = explode('OU', $mot_cle);
|
715 |
delphine |
353 |
$where = '';
|
|
|
354 |
foreach ($tab_mots_cles as $mot) {
|
741 |
delphine |
355 |
$where .= 'cmc_id_mot_cle_general = '.$this->bdd->quote($this->encoderMotCle(trim($mot))).' OR ';
|
715 |
delphine |
356 |
}
|
|
|
357 |
$where = rtrim($where,' OR ');
|
|
|
358 |
|
|
|
359 |
// Construction de la requête
|
|
|
360 |
$prerequete = "SELECT cmc_id_mot_cle_utilisateur, cmc_id_proprietaire FROM cel_mots_cles_obs WHERE $where ";
|
|
|
361 |
$elements = $this->executerRequete($prerequete);//print_r($elements);
|
|
|
362 |
if ($elements != false && count($elements) > 0) {
|
|
|
363 |
$requete = '';
|
|
|
364 |
foreach ($elements as $occurence) {
|
|
|
365 |
$requete .= '(mots_cles LIKE "%'.$occurence['cmc_id_mot_cle_utilisateur'].'%" AND identifiant = '.
|
|
|
366 |
$this->bdd->quote($occurence['cmc_id_proprietaire']).' ) OR ';
|
|
|
367 |
}
|
|
|
368 |
}
|
|
|
369 |
return $requete;
|
|
|
370 |
}
|
|
|
371 |
|
|
|
372 |
private function creerSousRequeteMotsClesEt($mot_cle) {
|
|
|
373 |
$requete = 'mots_cles like "inexistant" OR';
|
|
|
374 |
$where = '';
|
|
|
375 |
$champs = 'a.cmc_id_proprietaire , ';
|
|
|
376 |
$table = '';
|
|
|
377 |
$i = "a"; $j = "a";
|
|
|
378 |
|
|
|
379 |
$tab_mots_cles = explode("ET", $mot_cle);
|
|
|
380 |
foreach ($tab_mots_cles as $mot) {
|
|
|
381 |
$champs .= "$i.cmc_id_mot_cle_utilisateur as $i , ";
|
|
|
382 |
$table .= "cel_mots_cles_obs $i , ";
|
741 |
delphine |
383 |
$where .= "$i.cmc_id_mot_cle_general = ".$this->bdd->quote($this->encoderMotCle(trim($mot))).' AND ';
|
715 |
delphine |
384 |
if ($i !== "a") {
|
|
|
385 |
$where .= " $i.cmc_id_proprietaire = ".$j.".cmc_id_proprietaire AND ";
|
|
|
386 |
$j++;
|
|
|
387 |
}
|
|
|
388 |
$i++;
|
|
|
389 |
}
|
|
|
390 |
$where = rtrim($where,' AND '); $champs = rtrim($champs,' , '); $table = rtrim($table,' , ');
|
|
|
391 |
|
|
|
392 |
// Construction de la requête
|
|
|
393 |
$prerequete = "SELECT $champs FROM $table WHERE $where ";
|
|
|
394 |
$elements = $this->executerRequete($prerequete);//print_r($elements);
|
|
|
395 |
if ($elements != false && count($elements) > 0) {
|
|
|
396 |
$requete = '';
|
|
|
397 |
foreach ($elements as $occurence) {
|
|
|
398 |
$requete = ' (';
|
|
|
399 |
for ($j = 'a'; $j < $i; $j++) {
|
|
|
400 |
$requete .= 'mots_cles like "%'.$occurence[$j].'%" AND ';
|
|
|
401 |
}
|
|
|
402 |
$requete .= ' identifiant = '.$this->bdd->quote($occurence['cmc_id_proprietaire']).' ) OR ';
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
return $requete;
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
private function traiterCriteresMultiples($tableau_criteres) {
|
|
|
409 |
$tableau_criteres_pour_bdd = array();
|
|
|
410 |
|
|
|
411 |
foreach($tableau_criteres as $nom_critere => $valeur_critere) {
|
|
|
412 |
if (isset($this->criteres[$nom_critere])) {
|
|
|
413 |
$tableau_criteres_pour_bdd[] = $this->criteres[$nom_critere].'='.$valeur_critere;
|
|
|
414 |
}
|
|
|
415 |
}
|
|
|
416 |
return $tableau_criteres_pour_bdd;
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
private function creerSousRequeteRechercheGenerale($chaine_requete) {
|
|
|
420 |
$requete = '';
|
|
|
421 |
if (trim($chaine_requete) != '') {
|
|
|
422 |
$chaine_requete = strtolower($chaine_requete);
|
|
|
423 |
$chaine_requete = str_replace(' ', '_', $chaine_requete);
|
|
|
424 |
$requete = ' ('.
|
|
|
425 |
'nom_ret LIKE "'.$chaine_requete.'%"'.
|
|
|
426 |
' OR '.
|
|
|
427 |
'nom_sel LIKE "'.$chaine_requete.'%"'.
|
|
|
428 |
' OR '.
|
|
|
429 |
'location LIKE "'.$chaine_requete.'%" '.
|
|
|
430 |
' OR '.
|
|
|
431 |
'id_location LIKE "'.$chaine_requete.'%" '.
|
|
|
432 |
' OR '.
|
|
|
433 |
'identifiant LIKE "'.$chaine_requete.'%" '.
|
|
|
434 |
') ';
|
|
|
435 |
}
|
|
|
436 |
return $requete;
|
|
|
437 |
}
|
|
|
438 |
|
|
|
439 |
private function estUneRechercheGenerale() {
|
|
|
440 |
return isset($_GET['recherche']);
|
|
|
441 |
}
|
|
|
442 |
|
416 |
aurelien |
443 |
private function executerService($elements) {
|
|
|
444 |
$contenu = '';
|
|
|
445 |
if (is_array($elements)) {
|
|
|
446 |
// Prétraitement des données
|
|
|
447 |
$donnees = $this->construireDonneesCommunesAuFlux($elements);
|
|
|
448 |
foreach ($elements as $element) {
|
790 |
delphine |
449 |
$identifiants[$element['identifiant']] = $element['identifiant'];
|
|
|
450 |
}
|
|
|
451 |
$this->auteurs = $this->creerAuteurs($identifiants);
|
|
|
452 |
foreach ($elements as $element) {
|
416 |
aurelien |
453 |
$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
// Création du contenu à partir d'un template PHP
|
|
|
457 |
if (isset($this->squelette)) {
|
|
|
458 |
$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
|
|
|
459 |
}
|
|
|
460 |
}
|
|
|
461 |
return $contenu;
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
private function construireDonneesCommunesAuFlux($observations) {
|
|
|
465 |
$donnees = $this->getFlux($this->service);
|
|
|
466 |
$donnees['guid'] = $this->getUrlServiceBase();
|
741 |
delphine |
467 |
$donnees['titre'] = 'Flux des observations du CEL';
|
416 |
aurelien |
468 |
$donnees['lien_service'] = $this->creerUrlService();
|
715 |
delphine |
469 |
$donnees['lien_cel'] = $this->config['settings']['baseURLAbsolu'];
|
416 |
aurelien |
470 |
$donnees['editeur'] = $this->config['settings']['editeur'];
|
|
|
471 |
$derniere_info_en_date = reset($observations);
|
|
|
472 |
$date_modification_timestamp = strtotime($derniere_info_en_date['date_modification']);
|
|
|
473 |
$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
|
|
|
474 |
$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
|
|
|
475 |
$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
|
|
|
476 |
$donnees['annee_courante'] = date('Y');
|
|
|
477 |
$donnees['generateur'] = 'CEL - Jrest - CelSyndicationObservation';
|
715 |
delphine |
478 |
$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ? $match[1] : '0';
|
416 |
aurelien |
479 |
return $donnees;
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
private function construireDonneesCommunesAuxItems($observation) {
|
|
|
483 |
$item = array();
|
528 |
jpm |
484 |
$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['date_modification']);
|
416 |
aurelien |
485 |
$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
|
|
|
486 |
$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
|
|
|
487 |
$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
|
|
|
488 |
$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
|
|
|
489 |
$item['date_creation_simple'] = strftime('%A %d %B %Y à %H:%M', strtotime($observation['date_creation']));
|
|
|
490 |
$item['titre'] = $this->creerTitre($observation);
|
|
|
491 |
$item['guid'] = $this->creerGuidItem($observation);
|
|
|
492 |
$item['lien'] = $this->creerLienItem($observation);
|
|
|
493 |
$item['categorie'] = $this->creerCategorie($item);
|
528 |
jpm |
494 |
$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
|
|
|
495 |
$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
|
790 |
delphine |
496 |
$item['modifier_par'] = $this->auteurs[$observation['identifiant']];
|
416 |
aurelien |
497 |
return $item;
|
|
|
498 |
}
|
|
|
499 |
|
|
|
500 |
private function creerTitre($obs) {
|
|
|
501 |
$nom_plante = $obs['nom_sel'].' [nn'.$obs['num_nom_sel'].']';
|
|
|
502 |
$lieu = $obs['location'].' ('.$obs['id_location'].')';
|
790 |
delphine |
503 |
$utilisateur = $this->auteurs[$obs['identifiant']];
|
416 |
aurelien |
504 |
$titre = "$nom_plante à $lieu par $utilisateur";
|
|
|
505 |
$titre = $this->nettoyerTexte($titre);
|
|
|
506 |
return $titre;
|
|
|
507 |
}
|
|
|
508 |
|
|
|
509 |
private function creerGuidItem($element) {
|
|
|
510 |
$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['id']);
|
|
|
511 |
return $guid;
|
|
|
512 |
}
|
|
|
513 |
|
|
|
514 |
private function creerLienItem($element) {
|
506 |
jpm |
515 |
$lien = null;
|
|
|
516 |
if ($element['num_nom_sel'] != 0) {
|
585 |
jpm |
517 |
$lien = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['num_nom_sel']), 'cel');
|
506 |
jpm |
518 |
}
|
416 |
aurelien |
519 |
return $lien;
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
private function creerDescription($obs, $item) {
|
568 |
jpm |
523 |
$id_obs = $obs['id'];
|
528 |
jpm |
524 |
$famille = $obs['famille'];
|
|
|
525 |
$nom_saisi = $obs['nom_sel'];
|
|
|
526 |
$nom_retenu = $obs['nom_ret'];
|
790 |
delphine |
527 |
$auteur = $this->auteurs[$obs['identifiant']];
|
528 |
jpm |
528 |
$mots_cles_obs = $this->decoderMotsClesObs($obs['identifiant'], $obs['mots_cles']);
|
416 |
aurelien |
529 |
$lien_correction = sprintf($this->config['settings']['phpEditUrlTpl'], $obs['id']);
|
528 |
jpm |
530 |
$lieu = $obs['location'].' ('.$obs['id_location'].') > '.$obs['lieudit'].' > '.$obs['station'];
|
|
|
531 |
$milieu = $obs['milieu'];
|
|
|
532 |
$coordonnees = ($this->etreNull($obs['coord_x']) && $this->etreNull($obs['coord_y'])) ? '' : $obs['coord_x'].'/'.$obs['coord_y'];
|
529 |
jpm |
533 |
$commentaire = $obs['commentaire'];
|
528 |
jpm |
534 |
$date_observation = $this->formaterDate($obs['date_observation'], '%A %d %B %Y');
|
|
|
535 |
$date_transmission = $this->formaterDate($obs['date_transmission']);
|
|
|
536 |
$date_modification = $this->formaterDate($obs['date_modification']);
|
|
|
537 |
$date_creation = $this->formaterDate($obs['date_creation']);
|
|
|
538 |
$transmission = $obs['transmission'] == 1 ? "oui ($date_transmission)" : 'non';
|
|
|
539 |
|
|
|
540 |
$description = '<h2>'."Observation #$id_obs de $nom_saisi".'</h2>'.
|
416 |
aurelien |
541 |
'<ul>'.
|
528 |
jpm |
542 |
'<li>'.'Famille : '.$famille.'</li>'.
|
|
|
543 |
'<li>'.'Nom saisi : '.$nom_saisi.'</li>'.
|
|
|
544 |
'<li>'.'Nom retenu : '.$nom_retenu.'</li>'.
|
|
|
545 |
'<li>'.'Observée le : '.$date_observation.'</li>'.
|
|
|
546 |
'<li>'.'Lieu : '.$lieu.'</li>'.
|
|
|
547 |
'<li>'.'Milieu : '.$milieu.'</li>'.
|
|
|
548 |
(($this->etreFluxAdmin()) ? '<li>Coordonnées (Lat/Long) : '.$coordonnees.'</li>' : '').
|
|
|
549 |
'<li>'.'Commentaire : '.$commentaire.'</li>'.
|
|
|
550 |
'<li>'.'Mots-clés : '.implode(', ', $mots_cles_obs).'</li>'.
|
|
|
551 |
(($this->etreFluxAdmin()) ? '<li>Transmis (= public) : '.$transmission.'</li>' : '').
|
|
|
552 |
'<li>Modifiée le : '.$date_modification.'</li>'.
|
|
|
553 |
'<li>Créée le : '.$date_creation.'</li>'.
|
|
|
554 |
(($this->etreFluxAdmin()) ? '<li><a href="'.$lien_correction.'">Corriger cette observation</a></li>' : '').
|
416 |
aurelien |
555 |
'</ul>';
|
|
|
556 |
$description = $this->nettoyerTexte($description);
|
|
|
557 |
return $description;
|
|
|
558 |
}
|
|
|
559 |
|
|
|
560 |
private function creerCategorie($element) {
|
|
|
561 |
$categorie = '';
|
|
|
562 |
$categorie = 'Observation';
|
|
|
563 |
$categorie = $this->nettoyerTexte($categorie);
|
|
|
564 |
return $categorie;
|
|
|
565 |
}
|
|
|
566 |
|
|
|
567 |
private function etreFluxAdmin() {
|
715 |
delphine |
568 |
return (isset($_GET['admin']) && $_GET['admin'] == '1') ? true : false;
|
416 |
aurelien |
569 |
}
|
|
|
570 |
|
|
|
571 |
private function creerUrlService() {
|
|
|
572 |
$url_service = $this->getUrlServiceBase();
|
528 |
jpm |
573 |
if (count($_GET) > 0) {
|
637 |
jpm |
574 |
$parametres_get = array();
|
|
|
575 |
foreach ($_GET as $cle => $valeur) {
|
|
|
576 |
$parametres_get[] = $cle.'='.$valeur;
|
|
|
577 |
}
|
|
|
578 |
$url_service .= '?'.implode('&', $parametres_get);
|
416 |
aurelien |
579 |
}
|
|
|
580 |
return $url_service;
|
|
|
581 |
}
|
|
|
582 |
}
|