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
|
1336 |
jpm |
13 |
*
|
416 |
aurelien |
14 |
* Les paramêtres :
|
|
|
15 |
* - "start" indique le numéro du premier item à afficher
|
|
|
16 |
* - "limit" nombre d'items à afficher
|
1336 |
jpm |
17 |
*
|
416 |
aurelien |
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 {
|
1336 |
jpm |
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(
|
1336 |
jpm |
34 |
'utilisateur' => 'identifiant',
|
|
|
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');
|
1336 |
jpm |
41 |
|
416 |
aurelien |
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 = '';
|
1336 |
jpm |
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;
|
1336 |
jpm |
58 |
|
525 |
jpm |
59 |
// Récupération de la liste des flux
|
|
|
60 |
$this->chargerListeDesFlux();
|
1336 |
jpm |
61 |
|
525 |
jpm |
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 |
}
|
1336 |
jpm |
76 |
|
525 |
jpm |
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);
|
1336 |
jpm |
81 |
|
525 |
jpm |
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 |
}
|
1336 |
jpm |
92 |
|
416 |
aurelien |
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 |
}
|
1336 |
jpm |
99 |
|
416 |
aurelien |
100 |
private function getUrlBase() {
|
637 |
jpm |
101 |
$url_base = sprintf($this->config['settings']['baseURLAbsolu'], get_class($this).'/');
|
416 |
aurelien |
102 |
return $url_base;
|
|
|
103 |
}
|
1336 |
jpm |
104 |
|
416 |
aurelien |
105 |
private function getUrlServiceBase() {
|
528 |
jpm |
106 |
$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
|
416 |
aurelien |
107 |
return $url_service;
|
|
|
108 |
}
|
1336 |
jpm |
109 |
|
416 |
aurelien |
110 |
private function traiterNomService($nom) {
|
|
|
111 |
$nom = strtolower($nom);
|
|
|
112 |
return $nom;
|
|
|
113 |
}
|
1336 |
jpm |
114 |
|
416 |
aurelien |
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 |
}
|
1336 |
jpm |
121 |
|
416 |
aurelien |
122 |
private function getTypeMime() {
|
|
|
123 |
$mime = '';
|
1336 |
jpm |
124 |
$test = isset($this->format) ? $this->format : $this->service;
|
416 |
aurelien |
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 |
}
|
1336 |
jpm |
141 |
|
416 |
aurelien |
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 |
}
|
1336 |
jpm |
153 |
|
416 |
aurelien |
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 |
}
|
1336 |
jpm |
168 |
|
416 |
aurelien |
169 |
private function chargerListeDesFlux() {
|
1336 |
jpm |
170 |
$this->setFlux('par-defaut', 'Flux de syndication des observations publiques du CEL',
|
416 |
aurelien |
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 |
}
|
1336 |
jpm |
182 |
|
416 |
aurelien |
183 |
private function getServiceListeDesFlux() {
|
|
|
184 |
return $this->flux;
|
|
|
185 |
}
|
1336 |
jpm |
186 |
|
416 |
aurelien |
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 |
}
|
1336 |
jpm |
200 |
|
416 |
aurelien |
201 |
$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
|
|
|
202 |
$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
|
|
|
203 |
return $contenu;
|
|
|
204 |
}
|
1336 |
jpm |
205 |
|
416 |
aurelien |
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 ";
|
1336 |
jpm |
213 |
|
416 |
aurelien |
214 |
$elements = $this->executerRequete($requete);
|
1336 |
jpm |
215 |
|
416 |
aurelien |
216 |
// Création du contenu
|
|
|
217 |
$contenu = $this->executerService($elements);
|
|
|
218 |
return $contenu;
|
|
|
219 |
}
|
1336 |
jpm |
220 |
|
416 |
aurelien |
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 {
|
1336 |
jpm |
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 |
}
|
1336 |
jpm |
238 |
|
416 |
aurelien |
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 {
|
1336 |
jpm |
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 |
}
|
1336 |
jpm |
256 |
|
715 |
delphine |
257 |
private function getServiceMultiCriteres() {
|
|
|
258 |
$contenu = '';
|
1336 |
jpm |
259 |
if (isset($_GET['debut'])) $this->start = $_GET['debut'];
|
715 |
delphine |
260 |
if (isset($_GET['limite'])) $this->limite = $_GET['limite'];
|
1336 |
jpm |
261 |
|
715 |
delphine |
262 |
// Construction de la requête
|
|
|
263 |
$requete = (isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
|
|
|
264 |
'FROM cel_inventory '.
|
|
|
265 |
'WHERE transmission = 1 '.
|
|
|
266 |
' AND ';
|
1336 |
jpm |
267 |
|
715 |
delphine |
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);
|
1336 |
jpm |
275 |
}
|
715 |
delphine |
276 |
}
|
|
|
277 |
$requete = rtrim($requete, 'AND ');
|
1336 |
jpm |
278 |
$requete .= 'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby :
|
715 |
delphine |
279 |
'date_modification DESC, location ASC').' '.
|
|
|
280 |
"LIMIT $this->start,$this->limit ";
|
1336 |
jpm |
281 |
|
715 |
delphine |
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 |
}
|
1336 |
jpm |
290 |
|
715 |
delphine |
291 |
return $contenu;
|
|
|
292 |
}
|
1336 |
jpm |
293 |
|
715 |
delphine |
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;
|
1336 |
jpm |
307 |
case "date_observation" :
|
715 |
delphine |
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;
|
1336 |
jpm |
313 |
case "nom_ret" :
|
|
|
314 |
if ($nom_valeur[1] == "indetermine") $nom_valeur[1] = 'null';
|
715 |
delphine |
315 |
$requete .= ' ('.$nom_valeur[0].' LIKE "%'.$nom_valeur[1].'%" OR nom_sel LIKE "%'.
|
|
|
316 |
$nom_valeur[1].'%") AND '; break;
|
1336 |
jpm |
317 |
case "mots-cles" : $requete .= $this->creerSousRequeteMotsCles($nom_valeur[1]); break;
|
715 |
delphine |
318 |
default : $requete .= $nom_valeur[0].' = "'.$nom_valeur[1].'" AND '; break;
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
$requete = rtrim($requete,' AND ');
|
|
|
323 |
return $requete;
|
|
|
324 |
}
|
1336 |
jpm |
325 |
|
715 |
delphine |
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);
|
1336 |
jpm |
332 |
} else {
|
715 |
delphine |
333 |
// Construction de la requête
|
|
|
334 |
$prerequete = 'SELECT * '.
|
|
|
335 |
'FROM cel_mots_cles_obs '.
|
1336 |
jpm |
336 |
'WHERE cmc_id_mot_cle_general = '.$this->bdd->quote($this->encoderMotCle($mot_cle));
|
715 |
delphine |
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 = '.
|
1336 |
jpm |
342 |
$this->bdd->quote($occurence['cmc_id_proprietaire']).' ) OR ';
|
715 |
delphine |
343 |
}
|
|
|
344 |
}
|
|
|
345 |
}
|
|
|
346 |
$requete = rtrim($requete,' OR ').' AND ';
|
|
|
347 |
return $requete;
|
|
|
348 |
}
|
1336 |
jpm |
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 ');
|
1336 |
jpm |
358 |
|
715 |
delphine |
359 |
// Construction de la requête
|
1336 |
jpm |
360 |
$prerequete = "SELECT cmc_id_mot_cle_utilisateur, cmc_id_proprietaire FROM cel_mots_cles_obs WHERE $where ";
|
715 |
delphine |
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 |
}
|
1336 |
jpm |
371 |
|
715 |
delphine |
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";
|
1336 |
jpm |
378 |
|
|
|
379 |
$tab_mots_cles = explode("ET", $mot_cle);
|
715 |
delphine |
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,' , ');
|
1336 |
jpm |
391 |
|
715 |
delphine |
392 |
// Construction de la requête
|
1336 |
jpm |
393 |
$prerequete = "SELECT $champs FROM $table WHERE $where ";
|
715 |
delphine |
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;
|
1336 |
jpm |
406 |
}
|
|
|
407 |
|
715 |
delphine |
408 |
private function traiterCriteresMultiples($tableau_criteres) {
|
|
|
409 |
$tableau_criteres_pour_bdd = array();
|
1336 |
jpm |
410 |
|
715 |
delphine |
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 |
}
|
1336 |
jpm |
418 |
|
715 |
delphine |
419 |
private function creerSousRequeteRechercheGenerale($chaine_requete) {
|
|
|
420 |
$requete = '';
|
1336 |
jpm |
421 |
if (trim($chaine_requete) != '') {
|
715 |
delphine |
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 |
}
|
1336 |
jpm |
438 |
|
715 |
delphine |
439 |
private function estUneRechercheGenerale() {
|
|
|
440 |
return isset($_GET['recherche']);
|
|
|
441 |
}
|
1336 |
jpm |
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 |
}
|
1336 |
jpm |
455 |
|
416 |
aurelien |
456 |
// Création du contenu à partir d'un template PHP
|
|
|
457 |
if (isset($this->squelette)) {
|
|
|
458 |
$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
|
|
|
459 |
}
|
1336 |
jpm |
460 |
}
|
416 |
aurelien |
461 |
return $contenu;
|
|
|
462 |
}
|
1336 |
jpm |
463 |
|
416 |
aurelien |
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';
|
1336 |
jpm |
479 |
return $donnees;
|
416 |
aurelien |
480 |
}
|
1336 |
jpm |
481 |
|
416 |
aurelien |
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));
|
1336 |
jpm |
496 |
$item['modifier_par'] = $this->getIntituleAuteur($observation['identifiant']);
|
416 |
aurelien |
497 |
return $item;
|
|
|
498 |
}
|
1336 |
jpm |
499 |
|
416 |
aurelien |
500 |
private function creerTitre($obs) {
|
1320 |
aurelien |
501 |
$date = $obs['date_observation'];
|
|
|
502 |
$date = date("d/m/Y", strtotime($date));
|
416 |
aurelien |
503 |
$nom_plante = $obs['nom_sel'].' [nn'.$obs['num_nom_sel'].']';
|
|
|
504 |
$lieu = $obs['location'].' ('.$obs['id_location'].')';
|
1336 |
jpm |
505 |
$utilisateur = $this->getIntituleAuteur($obs['identifiant']);
|
1319 |
aurelien |
506 |
$titre = "$nom_plante à $lieu par $utilisateur le $date";
|
416 |
aurelien |
507 |
$titre = $this->nettoyerTexte($titre);
|
|
|
508 |
return $titre;
|
|
|
509 |
}
|
1336 |
jpm |
510 |
|
416 |
aurelien |
511 |
private function creerGuidItem($element) {
|
|
|
512 |
$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['id']);
|
|
|
513 |
return $guid;
|
|
|
514 |
}
|
1336 |
jpm |
515 |
|
416 |
aurelien |
516 |
private function creerLienItem($element) {
|
506 |
jpm |
517 |
$lien = null;
|
|
|
518 |
if ($element['num_nom_sel'] != 0) {
|
585 |
jpm |
519 |
$lien = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['num_nom_sel']), 'cel');
|
506 |
jpm |
520 |
}
|
416 |
aurelien |
521 |
return $lien;
|
|
|
522 |
}
|
1336 |
jpm |
523 |
|
416 |
aurelien |
524 |
private function creerDescription($obs, $item) {
|
568 |
jpm |
525 |
$id_obs = $obs['id'];
|
528 |
jpm |
526 |
$famille = $obs['famille'];
|
|
|
527 |
$nom_saisi = $obs['nom_sel'];
|
|
|
528 |
$nom_retenu = $obs['nom_ret'];
|
1336 |
jpm |
529 |
$auteur = $this->getIntituleAuteur($obs['identifiant']);
|
528 |
jpm |
530 |
$mots_cles_obs = $this->decoderMotsClesObs($obs['identifiant'], $obs['mots_cles']);
|
416 |
aurelien |
531 |
$lien_correction = sprintf($this->config['settings']['phpEditUrlTpl'], $obs['id']);
|
528 |
jpm |
532 |
$lieu = $obs['location'].' ('.$obs['id_location'].') > '.$obs['lieudit'].' > '.$obs['station'];
|
|
|
533 |
$milieu = $obs['milieu'];
|
|
|
534 |
$coordonnees = ($this->etreNull($obs['coord_x']) && $this->etreNull($obs['coord_y'])) ? '' : $obs['coord_x'].'/'.$obs['coord_y'];
|
529 |
jpm |
535 |
$commentaire = $obs['commentaire'];
|
528 |
jpm |
536 |
$date_observation = $this->formaterDate($obs['date_observation'], '%A %d %B %Y');
|
|
|
537 |
$date_transmission = $this->formaterDate($obs['date_transmission']);
|
|
|
538 |
$date_modification = $this->formaterDate($obs['date_modification']);
|
|
|
539 |
$date_creation = $this->formaterDate($obs['date_creation']);
|
|
|
540 |
$transmission = $obs['transmission'] == 1 ? "oui ($date_transmission)" : 'non';
|
1336 |
jpm |
541 |
|
528 |
jpm |
542 |
$description = '<h2>'."Observation #$id_obs de $nom_saisi".'</h2>'.
|
416 |
aurelien |
543 |
'<ul>'.
|
528 |
jpm |
544 |
'<li>'.'Famille : '.$famille.'</li>'.
|
|
|
545 |
'<li>'.'Nom saisi : '.$nom_saisi.'</li>'.
|
|
|
546 |
'<li>'.'Nom retenu : '.$nom_retenu.'</li>'.
|
|
|
547 |
'<li>'.'Observée le : '.$date_observation.'</li>'.
|
|
|
548 |
'<li>'.'Lieu : '.$lieu.'</li>'.
|
|
|
549 |
'<li>'.'Milieu : '.$milieu.'</li>'.
|
|
|
550 |
(($this->etreFluxAdmin()) ? '<li>Coordonnées (Lat/Long) : '.$coordonnees.'</li>' : '').
|
|
|
551 |
'<li>'.'Commentaire : '.$commentaire.'</li>'.
|
|
|
552 |
'<li>'.'Mots-clés : '.implode(', ', $mots_cles_obs).'</li>'.
|
|
|
553 |
(($this->etreFluxAdmin()) ? '<li>Transmis (= public) : '.$transmission.'</li>' : '').
|
|
|
554 |
'<li>Modifiée le : '.$date_modification.'</li>'.
|
|
|
555 |
'<li>Créée le : '.$date_creation.'</li>'.
|
|
|
556 |
(($this->etreFluxAdmin()) ? '<li><a href="'.$lien_correction.'">Corriger cette observation</a></li>' : '').
|
416 |
aurelien |
557 |
'</ul>';
|
|
|
558 |
$description = $this->nettoyerTexte($description);
|
|
|
559 |
return $description;
|
|
|
560 |
}
|
1336 |
jpm |
561 |
|
416 |
aurelien |
562 |
private function creerCategorie($element) {
|
|
|
563 |
$categorie = '';
|
|
|
564 |
$categorie = 'Observation';
|
|
|
565 |
$categorie = $this->nettoyerTexte($categorie);
|
|
|
566 |
return $categorie;
|
|
|
567 |
}
|
1336 |
jpm |
568 |
|
416 |
aurelien |
569 |
private function etreFluxAdmin() {
|
715 |
delphine |
570 |
return (isset($_GET['admin']) && $_GET['admin'] == '1') ? true : false;
|
416 |
aurelien |
571 |
}
|
1336 |
jpm |
572 |
|
416 |
aurelien |
573 |
private function creerUrlService() {
|
|
|
574 |
$url_service = $this->getUrlServiceBase();
|
528 |
jpm |
575 |
if (count($_GET) > 0) {
|
637 |
jpm |
576 |
$parametres_get = array();
|
|
|
577 |
foreach ($_GET as $cle => $valeur) {
|
|
|
578 |
$parametres_get[] = $cle.'='.$valeur;
|
|
|
579 |
}
|
|
|
580 |
$url_service .= '?'.implode('&', $parametres_get);
|
416 |
aurelien |
581 |
}
|
|
|
582 |
return $url_service;
|
|
|
583 |
}
|
1336 |
jpm |
584 |
|
|
|
585 |
private function getIntituleAuteur($courriel) {
|
|
|
586 |
$courriel = strtolower($courriel);
|
|
|
587 |
$intitule = $this->auteurs[$courriel];
|
|
|
588 |
return $intitule;
|
|
|
589 |
}
|
|
|
590 |
}
|