Subversion Repositories eFlore/Applications.cel

Rev

Rev 516 | Rev 523 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 516 Rev 522
Line 1... Line 1...
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 les images du CEL au format RSS1, RSS2 ou ATOM.
4
 * Encodage en entrée : utf8
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
5
 * Encodage en sortie : utf8
6
 * 
6
 * 
7
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
7
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
Line 25... Line 25...
25
	 */
25
	 */
26
	public function getElement($param = array()) {
26
	public function getElement($param = array()) {
27
		// Initialisation des variables
27
		// Initialisation des variables
28
		$info = array();
28
		$info = array();
29
		$contenu = '';
29
		$contenu = '';
-
 
30
		
-
 
31
		if ($this->authentifier()) {
-
 
32
			// Pré traitement des paramêtres
-
 
33
			$pour_bdd = false;
-
 
34
			$p = $this->traiterParametres(array('service', 'format'), $param, $pour_bdd);
-
 
35
			unset($param[0]);
-
 
36
			unset($param[1]);
-
 
37
			sort($param);
-
 
38
			extract($p);
-
 
39
			
-
 
40
			// Récupération de la liste des flux
-
 
41
			$this->chargerListeDesFlux();
Line 30... Line -...
30
			
-
 
31
		// Pré traitement des paramêtres
-
 
32
		$pour_bdd = false;
-
 
33
		$p = $this->traiterParametres(array('service', 'format'), $param, $pour_bdd);
-
 
34
		unset($param[0]);
-
 
35
		unset($param[1]);
-
 
36
		
-
 
37
		sort($param);
-
 
38
		
-
 
39
		extract($p);
-
 
40
		
-
 
41
		// Récupération de la liste des flux
-
 
42
		$this->chargerListeDesFlux();
-
 
43
		
42
			
44
		// Chargement du bon type de service demandé
43
			// Chargement du bon type de service demandé
45
		if (isset($service)) {
44
			if (isset($service)) {
46
			$this->service = $service;
45
				$this->service = $service;
47
			$methode = $this->getNomMethodeService();
46
				$methode = $this->getNomMethodeService();
48
			if (method_exists($this, $methode)) {
47
				if (method_exists($this, $methode)) {
49
				if ($this->service != 'liste_des_flux') {
48
					if ($this->service != 'liste_des_flux') {
50
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
-
 
51
						// Multiplication par deux de la limite car nous récupérons deux lignes par item
-
 
52
						$this->limit = $this->limit*2;
49
						if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
53
						// Mise en minuscule de l'indication du format
50
							// Mise en minuscule de l'indication du format
54
						$this->format = strtolower($format);
51
							$this->format = strtolower($format);
55
						// Définition du fichier squelette demandé
52
							// Définition du fichier squelette demandé
56
						$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
53
							$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
57
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
54
							$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
58
					} else {
55
						} else {
59
						$this->format = '';
56
							$this->format = '';
-
 
57
							$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
60
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
58
						}
-
 
59
					}
-
 
60
					// Récupération du contenu à renvoyer
-
 
61
					$contenu = $this->$methode($param);
-
 
62
				} else {
61
					}
63
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
62
				}
-
 
63
				// Récupération du contenu à renvoyer
-
 
64
				$contenu = $this->$methode($param);
64
				}
65
			} else {
65
			} else {
66
				$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
66
				$this->messages[] = "Le service CEL Syndication Image nécessite d'indiquer en premier paramètre le type d'information demandé.";
67
			}
-
 
68
		} else {
-
 
69
			$this->messages[] = "Le service CEL Syndication Image nécessite d'indiquer en premier paramètre le type d'information demandé.";
67
			}
Line 70... Line 68...
70
		}
68
		}
71
		
69
		
72
		// Envoie sur la sortie standard
70
		// Envoie sur la sortie standard
Line 79... Line 77...
79
	private function getUrlServiceBase() {
77
	private function getUrlServiceBase() {
80
		$url_service = $this->config['settings']['baseURLAbsoluDyn'].'CelSyndicationImage/'.$this->service.'/'.$this->format;
78
		$url_service = $this->config['settings']['baseURLAbsoluDyn'].'CelSyndicationImage/'.$this->service.'/'.$this->format;
81
		return $url_service;
79
		return $url_service;
82
	}
80
	}
Line 83... Line -...
83
	
-
 
84
	private function getUrlImageBase($id, $format = 'L') {
-
 
85
		
-
 
86
			$chemin_sur_serveur = $this->config['cel_db']['url_images'];
-
 
87
		
-
 
88
			$id = sprintf('%09s', $id) ;
-
 
89
            $id = wordwrap($id, 3 , '_', true) ;
-
 
90
        
-
 
91
            $id_fichier = $id.".jpg" ;
-
 
92
            
-
 
93
            $niveauDossier = split("_", $id) ;
-
 
94
            
-
 
95
            $dossierNiveau1 = $niveauDossier[0] ;
-
 
96
            $dossierNiveau2 = $niveauDossier[1] ;
-
 
97
            
-
 
98
            $chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
-
 
99
            $chemin_fichier = $chemin_sur_serveur_final.'/'.$format.'/'.$id.'_'.$format.'.jpg'; 
-
 
100
 
-
 
101
            return $chemin_fichier;
-
 
102
	}
-
 
103
	
81
	
104
	private function getNomMethodeService() {
82
	private function getNomMethodeService() {
105
		$methode = '';
83
		$methode = '';
106
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('_', $this->service))));
84
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('_', $this->service))));
107
		$methode = 'getService'.$service_formate;
85
		$methode = 'getService'.$service_formate;
Line 150... Line 128...
150
		}
128
		}
151
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
129
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
152
	}
130
	}
Line 153... Line 131...
153
	
131
	
154
	private function chargerListeDesFlux() {
-
 
155
		$this->setFlux('RssParDefaut', 'Flux de syndication par défaut', 
-
 
156
			'Ce flux fournit des informations sur les images du CEL.');
132
	private function chargerListeDesFlux() {
157
		$this->setFlux('RssParMotsCles', 'Flux des images filtré par mots clés', 
133
		$this->setFlux('Simple', 'Nouvelles images liées à une observation dans le CEL', 
158
			'Ce flux fournit des informations sur les images du CEL filtrées par mots-clés.');
134
			"Ce flux fournit l'url des nouvelles images du CEL liées à une observation.");
159
		$this->setFlux('RssParLocalisation','Flux des images filtré par localisation',
135
		$this->setFlux('Complet', 'Nouvelles images liées à une observation dans le CEL (détails)', 
160
			'Ce flux fournit des informations sur les images du CEL filtrées par localisation.');
136
			"Ce flux fournit les informations sur les nouvelles images du CEL liées à une observation.");
Line 161... Line 137...
161
	}
137
	}
162
	
138
	
163
	private function getServiceListeDesFlux() {
139
	private function getServiceListeDesFlux() {
Line 164... Line 140...
164
		return $this->flux;
140
		return $this->flux;
165
	}
-
 
166
	
-
 
167
	private function getServiceParDefaut() {
-
 
168
		// Construction de la requête
-
 
169
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
-
 
170
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
-
 
171
			"LIMIT $this->start,$this->limit ";
-
 
172
		
-
 
173
		$elements = $this->executerRequete($requete);
141
	}
174
		
-
 
175
		// Création du contenu
142
	
Line 176... Line 143...
176
		$contenu = $this->executerService($elements);
143
	private function etreFluxAdmin() {
-
 
144
		return ($_GET['admin'] == '1') ? true : false;
-
 
145
	}
-
 
146
	
-
 
147
	private function creerUrlService() {
-
 
148
		$url_service = $this->getUrlServiceBase();
-
 
149
		if (isset($this->start) || isset($this->limit)) {
-
 
150
			$arguments = array();
-
 
151
			if (isset($this->start) && isset($_GET['start'])) {
177
		return $contenu;
152
				$arguments[] = 'start='.$this->start;
178
	}
153
			}
179
	
154
			if (isset($this->limit) && isset($_GET['limit'])) {
-
 
155
				$arguments[] = 'limit='.$this->limit;
180
	private function getServiceSimple($params) {
156
			}
181
		
-
 
182
		if(isset($params[0])) {
-
 
183
			$this->format_image = $params[0];
-
 
184
		}
-
 
185
		
-
 
186
		$this->start = 0;
-
 
187
		$this->limit = 10;
-
 
188
		
-
 
189
		// Construction de la requête
-
 
190
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
-
 
191
			'FROM cel_obs_images a '.
-
 
192
			'INNER JOIN cel_inventory b '.
-
 
193
				'ON a.coi_ce_observation = b.ordre AND a.coi_ce_utilisateur = b.identifiant '.
-
 
194
			'INNER JOIN cel_images c '.
-
 
195
				'ON a.coi_ce_image = c.ci_id_image AND a.coi_ce_utilisateur = c.ci_ce_utilisateur '.  
-
 
196
			'WHERE b.transmission = 1 AND b.identifiant = c.ci_ce_utilisateur '.
-
 
197
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'ci_meta_date_ajout DESC').' '.
-
 
198
			"LIMIT $this->start,$this->limit ";
-
 
199
		
-
 
200
		$elements = $this->executerRequete($requete);
157
			if (count($arguments) > 0) {
201
		
158
				$url_service .= '?'.implode('&', $arguments);
Line 202... Line 159...
202
		// Création du contenu
159
			}
203
		$contenu = $this->executerService($elements);
160
		}
204
		return $contenu;
161
		return $url_service;
Line 215... Line 172...
215
		}
172
		}
216
		return $infos;
173
		return $infos;
217
	}
174
	}
Line 218... Line 175...
218
	
175
	
219
	private function executerService($elements) {
-
 
220
		
176
	private function executerService($elements) {
221
		// Prétraitement des données
177
		// Prétraitement des données
Line 222... Line 178...
222
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
178
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
223
		
179
		
Line 248... Line 204...
248
		$donnees['generateur_version'] = $match[1];
204
		$donnees['generateur_version'] = $match[1];
249
		return $donnees; 
205
		return $donnees; 
250
	}
206
	}
Line 251... Line 207...
251
	
207
	
252
	private function construireDonneesCommunesAuxItems($info) {
-
 
253
		
208
	private function construireDonneesCommunesAuxItems($info) {
254
		$item = array();
209
		$item = array();
255
		$date_modification_timestamp = strtotime($info['ci_meta_date_ajout']);
210
		$date_modification_timestamp = strtotime($info['ci_meta_date_ajout']);
256
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
211
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
257
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
212
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
Line 263... Line 218...
263
		$item['description'] = $this->creerDescription($info);
218
		$item['description'] = $this->creerDescription($info);
264
		$item['description_encodee'] = htmlspecialchars($item['description']);
219
		$item['description_encodee'] = htmlspecialchars($item['description']);
265
		return $item;
220
		return $item;
266
	}
221
	}
Line 267... Line -...
267
	
-
 
268
	private function creerTitre($element) {
-
 
269
		
-
 
270
		$titre = '';
-
 
271
		$titre = $element['nom_sel'].' [nn'.$element['num_nom_sel'].'] par '.$this->creerAuteur($element['identifiant']);
-
 
272
		$titre = $this->nettoyerTexte($titre);
-
 
273
		$titre = htmlspecialchars($titre);
-
 
274
		
-
 
275
		return $titre;
-
 
276
	}
-
 
277
	
222
	
278
	private function creerGuidItem($element) {
223
	private function creerGuidItem($element) {
279
		$guid = sprintf($this->config['settings']['guidImgTpl'], $element['ci_id_image']);
224
		$guid = sprintf($this->config['settings']['guidImgTpl'], $element['ci_id_image']);
280
		return $guid;
225
		return $guid;
Line 281... Line 226...
281
	}
226
	}
282
	
-
 
-
 
227
	
283
	private function creerLienItem($element) {
228
	private function creerTitre($element) {
-
 
229
		$methode = 'creerTitre'.$this->service;
-
 
230
		$methode = (method_exists($this, $methode)) ? $methode : 'creerTitreSimple';
284
		
231
		$titre = $this->$methode($element);
285
		$lien = $this->getUrlImageBase($element['ci_id_image'],$this->format_image);
232
		$titre = $this->nettoyerTexte($titre);
Line 286... Line 233...
286
		return $lien;
233
		return $titre;
287
	}
-
 
-
 
234
	}
288
	
235
	
-
 
236
	private function creerDescription($element) {
289
	private function creerDescription($element) {
237
		$methode = 'creerDescription'.$this->service;
290
		
-
 
291
		$description = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['num_nom_sel']));
238
		$methode = (method_exists($this, $methode)) ? $methode : 'creerDescriptionSimple';
292
		$description = $this->nettoyerTexte($description);
239
		$description = $this->$methode($element);
293
		
240
		$description = $this->nettoyerTexte($description);
294
		return $description;
241
		return $description;
295
	}
242
	}
296
	
243
 
297
	private function creerAuteur($courriel) {
244
	private function creerLienItem($element) {
Line 298... Line 245...
298
		$auteur = ($this->etreFluxAdmin()) ? $courriel : $this->traiterCourriel($courriel);
245
		$lien = $this->getUrlImage($element['ci_id_image'], $this->format_image);
-
 
246
		return $lien;
-
 
247
	}
-
 
248
	
-
 
249
	private function getServiceSimple($params) {
-
 
250
		if (isset($params[0])) {
-
 
251
			$this->format_image = $params[0];
-
 
252
		}
-
 
253
		
-
 
254
		$this->start = 0;
-
 
255
		$this->limit = 10;
-
 
256
		
-
 
257
		// Construction de la requête
-
 
258
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original '.
-
 
259
			'FROM cel_obs_images AS coi '.
-
 
260
			'LEFT JOIN cel_inventory AS ci '.
-
 
261
				'ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
-
 
262
			'LEFT JOIN cel_images AS cim '.
-
 
263
				'ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '.  
-
 
264
			'WHERE ci.transmission = 1 '.
-
 
265
			'	AND ci.identifiant = cim.ci_ce_utilisateur '.
-
 
266
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'ci_meta_date_ajout DESC').' '.
-
 
267
			"LIMIT $this->start, $this->limit ";
299
		return $auteur;
268
		
300
	}
269
		$elements = $this->executerRequete($requete);
301
	
270
		
Line 302... Line 271...
302
	private function traiterCourriel($courriel) {
271
		// Création du contenu
-
 
272
		$contenu = $this->executerService($elements);
303
		$courriel = preg_replace('/[^@]+$/i', '...', $courriel);
273
		return $contenu;
304
		return $courriel;
274
	}
Line 305... Line 275...
305
	}
275
	
306
	
-
 
307
	private function etreFluxAdmin() {
276
	private function creerTitreSimple($element) {
308
		return ($this->service == 'pour-admin') ? true : false;
-
 
309
	}
-
 
310
	
277
		$titre = $element['nom_sel'].' [nn'.$element['num_nom_sel'].'] par '.$this->creerAuteur($element['identifiant'], $this->etreFluxAdmin());
311
	private function etreNull($valeur) {
278
		return $titre;
Line 312... Line 279...
312
		$etre_null = false;
279
	}
-
 
280
	
-
 
281
	private function creerDescriptionSimple($element) {
-
 
282
		$description = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['num_nom_sel']));
-
 
283
		return $description;
313
		if ($valeur == '' || $valeur == null || $valeur == '000null' || $valeur == 'null') {
284
	}
-
 
285
	
-
 
286
	private function getServiceComplet($params) {
-
 
287
		// Construction de la requête
314
			$etre_null = true;
288
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original, ci_meta_date_ajout '.
-
 
289
			'FROM cel_obs_images AS coi '.
-
 
290
			'LEFT JOIN cel_inventory AS ci '.
-
 
291
				'ON (coi.coi_ce_observation = ci.ordre AND coi.coi_ce_utilisateur = ci.identifiant) '.
-
 
292
			'LEFT JOIN cel_images AS cim '.
-
 
293
				'ON (coi.coi_ce_image = cim.ci_id_image AND coi.coi_ce_utilisateur = cim.ci_ce_utilisateur) '.  
-
 
294
			'WHERE ci.transmission = 1 '.
-
 
295
			'	AND ci.identifiant = cim.ci_ce_utilisateur '.
315
		}
296
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'ci_meta_date_ajout DESC').' '.
316
		return $etre_null;
297
			"LIMIT $this->start, $this->limit ";
317
	}
298
		
318
	
299
		$elements = $this->executerRequete($requete);
319
	private function nettoyerTexte($txt) {
300
		
-
 
301
		// Création du contenu
320
		$txt = preg_replace('/&(?!([a-z]+|#[0-9]+|#x[0-9][a-f]+);)/i', '&amp;', $txt);
302
		$contenu = $this->executerService($elements);
321
		$txt = preg_replace('/^(?:000null|null)$/i', '', $txt);
303
		return $contenu;
322
		return $txt;
304
	}
323
	}
305
 
324
	
-
 
-
 
306
	private function creerDescriptionComplet($element) {
325
	private function creerUrlService() {
307
		$url_img = $this->getUrlImage($element['ci_id_image'], 'M');
326
		$url_service = $this->getUrlServiceBase();
308
		$description .= '<style>.champ{color:grey} ul{margin:10px 20px;} img{margin:10px;}}</style>';
327
		if (isset($this->start) || isset($this->limit)) {
-
 
-
 
309
		$description .= '<img src="'.$url_img.'" alt="'.$element['ci_nom_original'].'" />';
-
 
310
		$description .= '<ul>';
328
			$arguments = array();
311
		$description .= '<li>'."Image liée à l'observation ".$element['id'].'</li>';
329
			if (isset($this->start) && isset($_GET['start'])) {
312
		$description .= '<li>'.'<span class="champ">Importée le :</span> '.$element['ci_meta_date_ajout'].'</li>';
330
				$arguments[] = 'start='.$this->start;
-
 
331
			}
-
 
332
			if (isset($this->limit) && isset($_GET['limit'])) {
313
		$description .= '<li>'.'<span class="champ">Nom du fichier :</span> '.$element['ci_nom_original'].'</li>';
333
				$arguments[] = 'limit='.($this->limit/2);
314
		$description .= '<li>'.'<span class="champ">Nom saisi :</span> '.$element['nom_sel'].'</li>';
334
			}
-
 
335
			if (count($arguments) > 0) {
-
 
336
				$url_service .= '?'.implode('&', $arguments);
-
 
337
			}
-
 
338
		}
-
 
339
		return $url_service;
-
 
340
	}
-
 
341
	
-
 
342
	function calculerDimensions($tailleXY, $tailleoR = 300) {
-
 
343
        
-
 
344
        if($tailleXY[1] == 0) {
-
 
345
            $tailleXY[1] = $tailleOr;
-
 
346
        }
-
 
347
        
-
 
348
        if($tailleXY[0] == 0) {
-
 
349
            $tailleXY[0] = $tailleOr;
-
 
350
        }
-
 
351
        
-
 
352
        $maxTaille = max($tailleXY[1],$tailleXY[0]) ;
-
 
353
        
-
 
354
        if($maxTaille == $tailleXY[1]) {
-
 
355
            
-
 
356
            $rapport = $tailleXY[1]/$tailleXY[0] ;
-
 
357
            $tailleXY[1] = $tailleOr ;
-
 
358
            $tailleXY[0] = round($tailleXY[1]/$rapport,0) ;
-
 
359
            
-
 
360
        }else {
-
 
361
            $rapport = $tailleXY[0]/$tailleXY[1] ;
315
		$description .= '<li>'.'<span class="champ">Nom retenu :</span> '.$element['nom_ret'].'</li>';
362
            $tailleXY[0] = $tailleOr ;
316
		$description .= '<li>'.'<span class="champ">Observée le :</span> '.$element['date_observation'].'</li>';