Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 523 Rev 524
Line 21... Line 21...
21
	private $format_image = 'L';
21
	private $format_image = 'L';
Line 22... Line 22...
22
	
22
	
23
	/**
23
	/**
24
	 * Méthode appelée avec une requête de type GET.
24
	 * Méthode appelée avec une requête de type GET.
25
	 */
25
	 */
26
	public function getElement($param = array()) {
26
	public function getElement($params = array()) {
27
		// Initialisation des variables
27
		// Initialisation des variables
28
		$info = array();
28
		$info = array();
Line 29... Line 29...
29
		$contenu = '';
29
		$contenu = '';
30
		
30
		
31
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
31
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
32
			// Pré traitement des paramêtres
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]);
33
			$pour_bdd = false;
-
 
34
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
-
 
35
			extract($p);
Line 37... Line 36...
37
			sort($param);
36
			$this->parametres = $params;
38
			extract($p);
37
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
Line 39... Line 38...
39
			
38
			
40
			// Récupération de la liste des flux
39
			// Récupération de la liste des flux
41
			$this->chargerListeDesFlux();
40
			$this->chargerListeDesFlux();
42
			
41
			
43
			// Chargement du bon type de service demandé
42
			// Chargement du bon type de service demandé
44
			if (isset($service)) {
-
 
45
				$this->service = $service;
43
			if (isset($service)) {
46
				$methode = $this->getNomMethodeService();
44
				$this->service = $this->traiterNomService($service);
47
				if (method_exists($this, $methode)) {
45
				$methode = $this->getNomMethodeService();
48
					if ($this->service != 'liste_des_flux') {
46
				if (method_exists($this, $methode)) {
49
						if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
-
 
50
							// Mise en minuscule de l'indication du format
47
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
51
							$this->format = strtolower($format);
48
						// Mise en minuscule de l'indication du format
52
							// Définition du fichier squelette demandé
49
						$this->format = strtolower($format);
53
							$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
50
						// Définition du fichier squelette demandé
54
							$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
51
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
-
 
52
					} else if (isset($this->flux[$this->service])) {
-
 
53
						$this->format = '';
-
 
54
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
-
 
55
					}
-
 
56
					
-
 
57
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
-
 
58
						// Suppression des paramêtres inutile pour le reste des méthodes
-
 
59
						array_shift($this->parametres);
55
						} else {
60
						array_shift($this->parametres);
56
							$this->format = '';
-
 
57
							$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
-
 
58
						}
61
						
59
					}
62
						// Récupération du contenu à renvoyer
60
					// Récupération du contenu à renvoyer
63
						$contenu = $this->$methode();
61
					$contenu = $this->$methode($param);
64
					}
62
				} else {
65
				} else {
Line 72... Line 75...
72
		$mime = $this->getTypeMime();
75
		$mime = $this->getTypeMime();
73
		$formatage_json = $this->getFormatageJson();
76
		$formatage_json = $this->getFormatageJson();
74
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
77
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
75
	}
78
	}
Line 76... Line 79...
76
	
79
	
-
 
80
	private function chargerListeDesFlux() {
-
 
81
		$this->setFlux('simple', 'Nouvelles images liées à une observation dans le CEL', 
-
 
82
			"Ce flux fournit l'url des nouvelles images du CEL liées à une observation.");
-
 
83
		$this->setFlux('complet', 'Nouvelles images liées à une observation dans le CEL (détails)', 
-
 
84
			"Ce flux fournit les informations sur les nouvelles images du CEL liées à une observation.");
-
 
85
	}
-
 
86
	
77
	private function getUrlServiceBase() {
87
	private function setFlux($nom, $titre, $description) {
-
 
88
		$url_base = $this->config['settings']['baseURLAbsoluDyn'].'CoelSyndicationImage/';
-
 
89
		$formats = array('atom', 'rss2', 'rss1');
-
 
90
		$flux = array();
-
 
91
		foreach ($formats as $format) {
-
 
92
			$url = $url_base.$nom.'/'.$format;
-
 
93
			$flux[$format] = $url;
-
 
94
		}
-
 
95
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
-
 
96
	}
-
 
97
 
-
 
98
	private function getFlux($nom) {
-
 
99
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
-
 
100
	}
-
 
101
	
-
 
102
	private function traiterNomService($nom) {
78
		$url_service = $this->config['settings']['baseURLAbsoluDyn'].'CelSyndicationImage/'.$this->service.'/'.$this->format;
103
		$nom = strtolower($nom);
79
		return $url_service;
104
		return $nom;
Line 80... Line 105...
80
	}
105
	}
81
	
106
	
82
	private function getNomMethodeService() {
107
	private function getNomMethodeService() {
83
		$methode = '';
108
		$methode = '';
84
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('_', $this->service))));
109
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
85
		$methode = 'getService'.$service_formate;
110
		$methode = 'getService'.$service_formate;
Line -... Line 111...
-
 
111
		return $methode;
-
 
112
	}
-
 
113
	
-
 
114
	private function getUrlBase() {
-
 
115
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
-
 
116
		return $url_base;
-
 
117
	}
-
 
118
	
-
 
119
	private function getUrlServiceBase() {
-
 
120
		$url_service = $this->getUrlBase().$this->service.'/'.$this->format;
86
		return $methode;
121
		return $url_service;
87
	}
122
	}
88
	
123
	
89
	private function getTypeMime() {
124
	private function getTypeMime() {
90
		$mime = '';
125
		$mime = '';
91
		switch ($this->format) {
126
		switch ($this->format) {
92
			case 'atom' :
127
			case 'atom' :
93
				$mime = 'application/atom+xml';
128
				$mime = 'application/atom+xml';
94
				break;
129
				break;
95
			case 'rss1' :
130
			case 'rss1' :
-
 
131
			case 'rss2' :
-
 
132
				$mime = 'application/rss+xml';
-
 
133
				break;
96
			case 'rss2' :
134
			case 'opml' :
97
				$mime = 'application/rss+xml';
135
				$mime = 'text/x-opml';
98
				break;
136
				break;
99
			default:
137
			default:
100
				$mime = 'text/html';
138
				$mime = 'text/html';
Line 101... Line 139...
101
		}
139
		}
102
		return $mime;
140
		return $mime;
103
	}
141
	}
104
	
142
	
105
	private function getFormatageJson() {
143
	private function getFormatageJson() {
106
		$json = false;
144
		$json = false;
107
		switch ($this->service) {
145
		switch ($this->service) {
108
			case 'liste_des_flux' :
146
			case 'liste-des-flux' :
109
				$json = true;
147
				$json = true;
110
				break;
148
				break;
111
			default:
149
			default:
112
				$json = false;
150
				$json = false;
113
		}
-
 
114
		return $json;
-
 
115
	}
-
 
116
	
-
 
117
	private function getFlux($nom) {
-
 
118
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
-
 
119
	}
-
 
120
 
-
 
121
	private function setFlux($nom, $titre, $description) {
-
 
122
		$url_base = $this->config['settings']['baseURLAbsoluDyn'].'CoelSyndicationImage/';
-
 
123
		$formats = array('atom', 'rss2', 'rss1');
-
 
124
		$flux = array();
-
 
125
		foreach ($formats as $format) {
-
 
126
			$url = $url_base.$nom.'/'.$format;
-
 
127
			$flux[$format] = $url;
-
 
128
		}
-
 
129
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
-
 
130
	}
-
 
131
	
-
 
132
	private function chargerListeDesFlux() {
-
 
133
		$this->setFlux('Simple', 'Nouvelles images liées à une observation dans le CEL', 
-
 
134
			"Ce flux fournit l'url des nouvelles images du CEL liées à une observation.");
-
 
135
		$this->setFlux('Complet', 'Nouvelles images liées à une observation dans le CEL (détails)', 
-
 
136
			"Ce flux fournit les informations sur les nouvelles images du CEL liées à une observation.");
-
 
137
	}
-
 
138
	
-
 
139
	private function getServiceListeDesFlux() {
151
		}
140
		return $this->flux;
152
		return $json;
141
	}
153
	}
Line 142... Line 154...
142
	
154
		
Line 244... Line 256...
244
	private function creerLienItem($element) {
256
	private function creerLienItem($element) {
245
		$lien = $this->getUrlImage($element['ci_id_image'], $this->format_image);
257
		$lien = $this->getUrlImage($element['ci_id_image'], $this->format_image);
246
		return $lien;
258
		return $lien;
247
	}
259
	}
Line 248... Line 260...
248
	
260
	
-
 
261
	private function getServiceListeDesFlux() {
-
 
262
		return $this->flux;
-
 
263
	}
-
 
264
	
249
	private function getServiceSimple($params) {
265
	private function getServiceOpml() {
-
 
266
		$donnees = array();
-
 
267
		$id = 1;
-
 
268
		foreach ($this->flux as $flux_nom => $flux){
250
		if (isset($params[0])) {
269
			$info = array();
-
 
270
			$info['type'] = 'atom';
-
 
271
			$info['titre'] = $flux['titre'];
-
 
272
			$info['texte'] = "CEL - Images - $flux_nom";
-
 
273
			$info['description'] = $flux['description'];
-
 
274
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
-
 
275
			$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
251
			$this->format_image = $params[0];
276
			$donnees['liste_flux'][] = $info;
Line -... Line 277...
-
 
277
		}
-
 
278
		
252
		}
279
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
-
 
280
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
-
 
281
		return $contenu;
-
 
282
	}
253
		
283
	
-
 
284
	private function getServiceSimple() {
-
 
285
		if (isset($this->parametres[0])) {
Line 254... Line 286...
254
		$this->start = 0;
286
			$this->format_image = $this->parametres[0];
255
		$this->limit = 10;
287
		}
256
		
288
		
257
		// Construction de la requête
289
		// Construction de la requête
Line 281... Line 313...
281
	private function creerDescriptionSimple($donnees, $item) {
313
	private function creerDescriptionSimple($donnees, $item) {
282
		$description = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($donnees['num_nom_sel']));
314
		$description = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($donnees['num_nom_sel']));
283
		return $description;
315
		return $description;
284
	}
316
	}
Line 285... Line 317...
285
	
317
	
286
	private function getServiceComplet($params) {
318
	private function getServiceComplet() {
287
		// Construction de la requête
319
		// Construction de la requête
288
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original, ci_meta_date_ajout, ci_meta_user_comment, ci_note_image '.
320
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' ci.*, ci_id_image, ci_nom_original, ci_meta_date_ajout, ci_meta_user_comment, ci_note_image '.
289
			'FROM cel_obs_images AS coi '.
321
			'FROM cel_obs_images AS coi '.
290
			'LEFT JOIN cel_inventory AS ci '.
322
			'LEFT JOIN cel_inventory AS ci '.