Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 984 | Rev 1171 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 984 Rev 1084
1
<?php
1
<?php
2
/*
2
/*
3
 * @copyright 2013 Tela Botanica (accueil@tela-botanica.org)
3
 * @copyright 2013 Tela Botanica (accueil@tela-botanica.org)
4
 * @author Raphaël Droz <raphael@tela-botanica.org>
4
 * @author Raphaël Droz <raphael@tela-botanica.org>
5
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
5
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
6
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
6
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
7
 *
7
 *
8
 * pattern: /service:eflore:0.1/coste/textes/bdtfx.nn:182,631
8
 * pattern: /service:eflore:0.1/coste/textes/bdtfx.nn:182,631
9
 * params: txt.format=(htm|txt) ,  retour.champs=(titre,texte,...) , retour.format=(min|max), ...
9
 * params: txt.format=(htm|txt) ,  retour.champs=(titre,texte,...) , retour.format=(min|max), ...
10
 *
10
 *
11
 * Ce webservice est censé pouvoir:
11
 * Ce webservice est censé pouvoir:
12
 * 1) retourner des informations (choisies) à propos d'un ou plusieurs taxon(s) donné(s)
12
 * 1) retourner des informations (choisies) à propos d'un ou plusieurs taxon(s) donné(s)
13
 *	  (à partir de son numéro nomenclatural
13
 *	  (à partir de son numéro nomenclatural
14
 * 2) retourner des informations (choisies) à propos de taxons recherchés
14
 * 2) retourner des informations (choisies) à propos de taxons recherchés
15
 *	  (à partir de divers critères)
15
 *	  (à partir de divers critères)
16
 *
16
 *
17
 * TODO: masque.titre => masque.tag
17
 * TODO: masque.titre => masque.tag
18
 * TODO: clarifier l'attribut "tag" retourné (tag de la description ou des clefs de détermination)
18
 * TODO: clarifier l'attribut "tag" retourné (tag de la description ou des clefs de détermination)
19
 *
19
 *
20
 */
20
 */
21
 
21
 
22
// affecte le nombre d'ids autorisés dans le dernier segment d'URL
22
// affecte le nombre d'ids autorisés dans le dernier segment d'URL
23
// *et* la valeur maximale autorisée pour navigation.limite.
23
// *et* la valeur maximale autorisée pour navigation.limite.
24
define('_COSTE_TEXTE_MAX_RESULT_LIMIT', 500);
24
define('_COSTE_TEXTE_MAX_RESULT_LIMIT', 500);
25
 
25
 
26
// simplifie et accélère la sanitization de l'input:
26
// simplifie et accélère la sanitization de l'input:
27
// SELECT MAX(num_nom) FROM coste_v2_00;
27
// SELECT MAX(num_nom) FROM coste_v2_00;
28
define('_COSTE_TEXTE_MAX_COSTE_NN', 7015 + 1000);
28
define('_COSTE_TEXTE_MAX_COSTE_NN', 7015 + 1000);
29
// SELECT MAX(page) FROM coste_v2_00;
29
// SELECT MAX(page) FROM coste_v2_00;
30
define('_COSTE_TEXTE_MAX_COSTE_PAGE', 4126);
30
define('_COSTE_TEXTE_MAX_COSTE_PAGE', 4126);
31
// SELECT MAX(tome) FROM coste_v2_00;
31
// SELECT MAX(tome) FROM coste_v2_00;
32
define('_COSTE_TEXTE_MAX_COSTE_TOME', 3);
32
define('_COSTE_TEXTE_MAX_COSTE_TOME', 3);
33
// SELECT MAX(num_taxonomique) FROM coste_v2_00;
33
// SELECT MAX(num_taxonomique) FROM coste_v2_00;
34
define('_COSTE_TEXTE_MAX_BDTFX_NT', 37809);
34
define('_COSTE_TEXTE_MAX_BDTFX_NT', 37809);
35
// SELECT MAX(num_nom) FROM bdtfx_v2_00;
35
// SELECT MAX(num_nom) FROM bdtfx_v2_00;
36
define('_COSTE_TEXTE_MAX_BDTFX_NN', 120816 + 100000);
36
define('_COSTE_TEXTE_MAX_BDTFX_NN', 120816 + 100000);
37
 
37
 
38
/* restore_error_handler();
38
/* restore_error_handler();
39
   error_reporting(E_ALL); */
39
   error_reporting(E_ALL); */
40
class Textes {
40
class Textes {
41
	// paramètres autorisés
41
	// paramètres autorisés
42
	static $allow_params = array(
42
	static $allow_params = array(
43
		'txt.format', 'retour.format', 'retour.champs', 'retour.indexBy',
43
		'txt.format', 'retour.format', 'retour.champs', 'retour.indexBy',
44
		'recherche',
44
		'recherche',
45
		'masque.ns', 'masque.txt', 'masque.page', 'masque.tome', 'masque.famille', 'masque.nt',
45
		'masque.ns', 'masque.txt', 'masque.page', 'masque.tome', 'masque.famille', 'masque.nt',
46
		'masque.titre', // masque sur titre de la page wiki correspondante (page "clef" OR page "description")
46
		'masque.titre', // masque sur titre de la page wiki correspondante (page "clef" OR page "description")
47
		'navigation.depart', 'navigation.limite');
47
		'navigation.depart', 'navigation.limite');
48
	// et valeurs par défaut
48
	// et valeurs par défaut
49
	static $default_params = array('txt.format' => 'txt', 'retour.format' => 'max', 'retour.indexBy' => 'coste',
49
	static $default_params = array('txt.format' => 'txt', 'retour.format' => 'max', 'retour.indexBy' => 'coste',
50
								   'recherche' => 'stricte',
50
								   'recherche' => 'stricte',
51
								   'retour.champs' => 'titre,texte,determination,tag',
51
								   'retour.champs' => 'titre,texte,determination,tag',
52
								   'navigation.depart' => 0, 'navigation.limite' => 50);
52
								   'navigation.depart' => 0, 'navigation.limite' => 50);
53
 
53
 
54
	// les champs de base de coste_v2_00
54
	// les champs de base de coste_v2_00
55
	// mysql -N tb_eflore<<<"SHOW FIELDS FROM coste_v2_00"|egrep -v 'page_'|awk '{print $1}'|xargs -i -n1 printf "'%s' => 'c.%s',\n" {} {}
55
	// mysql -N tb_eflore<<<"SHOW FIELDS FROM coste_v2_00"|egrep -v 'page_'|awk '{print $1}'|xargs -i -n1 printf "'%s' => 'c.%s',\n" {} {}
56
	static $allow_champs = array(
56
	static $allow_champs = array(
57
		'coste:nn' => 'c.num_nom',
57
		'coste:nn' => 'c.num_nom',
58
		'bdtfx:nn' => 'IF(c.flore_bdtfx_nn = "",NULL,c.flore_bdtfx_nn)',
58
		'bdtfx:nn' => 'IF(c.flore_bdtfx_nn = "",NULL,c.flore_bdtfx_nn)',
59
		'bdtfx:nt' => 'c.flore_bdtfx_nt',
59
		'bdtfx:nt' => 'IF(c.flore_bdtfx_nt = "",NULL,c.flore_bdtfx_nt)',
60
		'num_nom' => 'c.num_nom',
60
		'num_nom' => 'c.num_nom',
61
		'num_nom_retenu' => 'c.num_nom_retenu',
61
		'num_nom_retenu' => 'c.num_nom_retenu',
62
		'num_tax_sup' => 'c.num_tax_sup',
62
		'num_tax_sup' => 'c.num_tax_sup',
63
		'rang' => 'c.rang',
63
		'rang' => 'c.rang',
64
		'nom_sci' => 'c.nom_sci',
64
		'nom_sci' => 'c.nom_sci',
65
		'nom_supra_generique' => 'c.nom_supra_generique',
65
		'nom_supra_generique' => 'c.nom_supra_generique',
66
		'genre' => 'c.genre',
66
		'genre' => 'c.genre',
67
		'epithete_infra_generique' => 'c.epithete_infra_generique',
67
		'epithete_infra_generique' => 'c.epithete_infra_generique',
68
		'epithete_sp' => 'c.epithete_sp',
68
		'epithete_sp' => 'c.epithete_sp',
69
		'type_epithete' => 'c.type_epithete',
69
		'type_epithete' => 'c.type_epithete',
70
		'epithete_infra_sp' => 'c.epithete_infra_sp',
70
		'epithete_infra_sp' => 'c.epithete_infra_sp',
71
		'cultivar_groupe' => 'c.cultivar_groupe',
71
		'cultivar_groupe' => 'c.cultivar_groupe',
72
		'cultivar' => 'c.cultivar',
72
		'cultivar' => 'c.cultivar',
73
		'nom_commercial' => 'c.nom_commercial',
73
		'nom_commercial' => 'c.nom_commercial',
74
		'auteur' => 'c.auteur',
74
		'auteur' => 'c.auteur',
75
		'annee' => 'c.annee',
75
		'annee' => 'c.annee',
76
		'biblio_origine' => 'c.biblio_origine',
76
		'biblio_origine' => 'c.biblio_origine',
77
		'notes' => 'c.notes',
77
		'notes' => 'c.notes',
78
		'nom_addendum' => 'c.nom_addendum',
78
		'nom_addendum' => 'c.nom_addendum',
79
		'nom_francais' => 'c.nom_francais',
79
		'nom_francais' => 'c.nom_francais',
80
		'nom_coste' => 'c.nom_coste',
80
		'nom_coste' => 'c.nom_coste',
81
		'auteur_coste' => 'c.auteur_coste',
81
		'auteur_coste' => 'c.auteur_coste',
82
		'biblio_coste' => 'c.biblio_coste',
82
		'biblio_coste' => 'c.biblio_coste',
83
		'num_nom_coste' => 'c.num_nom_coste',
83
		'num_nom_coste' => 'c.num_nom_coste',
84
		'num_nom_retenu_coste' => 'c.num_nom_retenu_coste',
84
		'num_nom_retenu_coste' => 'c.num_nom_retenu_coste',
85
		'num_tax_sup_coste' => 'c.num_tax_sup_coste',
85
		'num_tax_sup_coste' => 'c.num_tax_sup_coste',
86
		'synonymie_coste' => 'c.synonymie_coste',
86
		'synonymie_coste' => 'c.synonymie_coste',
87
		'tome' => 'c.tome',
87
		'tome' => 'c.tome',
88
		'page' => 'c.page',
88
		'page' => 'c.page',
89
		'nbre_taxons' => 'c.nbre_taxons',
89
		'nbre_taxons' => 'c.nbre_taxons',
90
		'flore_bdtfx_nn' => 'c.flore_bdtfx_nn',
90
		'flore_bdtfx_nn' => 'c.flore_bdtfx_nn',
91
		'flore_bdtfx_nt' => 'c.flore_bdtfx_nt',
91
		'flore_bdtfx_nt' => 'c.flore_bdtfx_nt',
92
		'image' => 'c.image',
92
		'image' => 'c.image',
93
		'image_auteur' => 'c.image_auteur',
93
		'image_auteur' => 'c.image_auteur',
94
		'nom_sci_html' => 'c.nom_sci_html',
94
		'nom_sci_html' => 'c.nom_sci_html',
95
 
95
 
96
		// handly duplicate (redirigé vers nom_sci ou nom_sci_html selon que txt.format vaut "txt" ou "htm"
96
		// handly duplicate (redirigé vers nom_sci ou nom_sci_html selon que txt.format vaut "txt" ou "htm"
97
		'titre' => 'c.nom_sci',
97
		'titre' => 'c.nom_sci',
98
 
98
 
99
		// champs spécifiques (et étrangères)
99
		// champs spécifiques (et étrangères)
100
		'texte' => 'dsc.body',
100
		'texte' => 'dsc.body',
101
		'determination' => 'cle.body',
101
		'determination' => 'cle.body',
102
		'tag' => 'dsc.tag',
102
		'tag' => 'dsc.tag',
103
		'famille' => 'b.famille', // cf sqlAddJoins()
103
		'famille' => 'b.famille', // cf sqlAddJoins()
104
		'*' => 'XXX' // spécial
104
		'*' => 'XXX' // spécial
105
	);
105
	);
106
 
106
 
107
	// les champs suivants disparaissent de la liste utilisée pour former la requête SQL
107
	// les champs suivants disparaissent de la liste utilisée pour former la requête SQL
108
	// (ils sont exclue lorsque '*' est utilisée, ce sont généralement des synonymes)
108
	// (ils sont exclue lorsque '*' est utilisée, ce sont généralement des synonymes)
109
	static $special_champs = array('nom_sci_html', 'nom_sci', '*', 'flore_bdtfx_nn', 'flore_bdtfx_nt', 'num_nom');
109
	static $special_champs = array('nom_sci_html', 'nom_sci', '*', 'flore_bdtfx_nn', 'flore_bdtfx_nt', 'num_nom');
110
 
110
 
111
	// ces champs sont toujours dans les résultats (cf sqlSelectFields()
111
	// ces champs sont toujours dans les résultats (cf sqlSelectFields()
112
	static $champs_obligatoires = array('coste:nn', 'bdtfx:nn');
112
	static $champs_obligatoires = array('coste:nn', 'bdtfx:nn', 'bdtfx:nt');
113
 
113
 
114
 
114
 
115
	// le pattern utilisé pour la recherche dite "floue"
115
	// le pattern utilisé pour la recherche dite "floue"
116
	static $soundex_scheme = '(%1$s LIKE %2$s OR SOUNDEX(%1$s) = SOUNDEX(%2$s) OR SOUNDEX(REVERSE(%1$s)) = SOUNDEX(REVERSE(%2$s)))';
116
	static $soundex_scheme = '(%1$s LIKE %2$s OR SOUNDEX(%1$s) = SOUNDEX(%2$s) OR SOUNDEX(REVERSE(%1$s)) = SOUNDEX(REVERSE(%2$s)))';
117
 
117
 
118
	// contrainte du point d'entrée d'API webservice Tela lors d'un GET
118
	// contrainte du point d'entrée d'API webservice Tela lors d'un GET
119
	public function consulter($ressources, $parametres, $db = NULL) {
119
	public function consulter($ressources, $parametres, $db = NULL) {
120
		if (!$db) {
120
		if (!$db) {
121
			// http_response_code(500);
121
			// http_response_code(500);
122
			throw new Exception('no DB', 500);
122
			throw new Exception('no DB', 500);
123
		}
123
		}
124
 
124
 
125
		// parser la requête et filtrer les paramètres valides
125
		// parser la requête et filtrer les paramètres valides
126
		// en cas d'accès HTTP
126
		// en cas d'accès HTTP
127
		if (array_key_exists('QUERY_STRING', $_SERVER)) {
127
		if (array_key_exists('QUERY_STRING', $_SERVER)) {
128
			self::requestParse($uri, $params);
128
			self::requestParse($uri, $params);
129
		} else {// en cas d'accès phpunit
129
		} else {// en cas d'accès phpunit
130
			$uri = $ressources;
130
			$uri = $ressources;
131
		}
131
		}
132
 
132
 
133
		// renvoie du plain/text d'aide (cf fin de programme)
133
		// renvoie du plain/text d'aide (cf fin de programme)
134
		if (count($uri) == 1 && $uri[0] == 'aide') {
134
		if (count($uri) == 1 && $uri[0] == 'aide') {
135
			die(self::aide());
135
			die(self::aide());
136
		}
136
		}
137
 
137
 
138
		if (is_null($parametres)) {
138
		if (is_null($parametres)) {
139
			$parametres = Array();
139
			$parametres = Array();
140
		}
140
		}
141
		$params = self::requestFilterParams($parametres);
141
		$params = self::requestFilterParams($parametres);
142
		// les contraintes liées aux ids (passés comme composants d'URL)
142
		// les contraintes liées aux ids (passés comme composants d'URL)
143
		// sont ajoutées aux params [sans être accepté comme paramètre d'URL]
143
		// sont ajoutées aux params [sans être accepté comme paramètre d'URL]
144
		$params['_ids'] = self::requestFilterIds($uri);
144
		$params['_ids'] = self::requestFilterIds($uri);
145
 
145
 
146
		// XXX: temporaires, passage de $db aux fonctions
146
		// XXX: temporaires, passage de $db aux fonctions
147
		// de toolkits
147
		// de toolkits
148
		$req = self::getCosteInfo($params, $db);
148
		$req = self::getCosteInfo($params, $db);
149
 
-
 
150
		$res = $db->recupererTous($req);
149
		$res = $db->recupererTous($req);
151
		$err = mysql_error();
150
		$err = mysql_error();
152
		if (!$res && $err) {
151
		if (!$res && $err) {
153
			// http_response_code(400);
152
			// http_response_code(400);
154
			// if(defined('DEBUG') && DEBUG) header("X-Debug: $req");
153
			// if(defined('DEBUG') && DEBUG) header("X-Debug: $req");
155
			throw new Exception('not found', 400);
154
			throw new Exception('not found', 400);
156
		}
155
		}
157
 
156
 
158
		// rapide formatage des résultats:
157
		// rapide formatage des résultats:
159
		$matches = 0;
158
		$matches = 0;
160
 
159
 
161
		if ($res) {
160
		if ($res) {
162
			// nombre de matches (sans LIMIT) utilisé pour l'en-tête
161
			// nombre de matches (sans LIMIT) utilisé pour l'en-tête
163
			$matches = $db->recuperer('SELECT FOUND_ROWS() AS total');
162
			$matches = $db->recuperer('SELECT FOUND_ROWS() AS total');
164
			$matches = intval($matches['total']);
163
			$matches = intval($matches['total']);
165
		}
164
		}
166
 
165
 
167
		// reformate les résultats pour les indexer par coste:nn par défaut
166
		// reformate les résultats pour les indexer par coste:nn par défaut
168
		// cependant le paramètre retour.indexBy permet de choisir une indexation par num_nom de bdtfx
167
		// cependant le paramètre retour.indexBy permet de choisir une indexation par num_nom de bdtfx
169
		$clef_index = $params['retour.indexBy'] == 'coste' ? 'coste:nn' : 'bdtfx:nn';
168
		$clef_index = $params['retour.indexBy'] == 'coste' ? 'coste:nn' : 'bdtfx:nn';
170
		$res2 = array();
169
		$res2 = array();
171
		foreach ($res as $v) {
170
		foreach ($res as $v) {
172
			if (!$v[$clef_index]) {
171
			if (!$v[$clef_index]) {
173
				throw new Exception('format error: index NULL, use retour.indexBy=coste', 409);
172
				throw new Exception('format error: index NULL, use retour.indexBy=coste', 409);
174
			}
173
			}
175
			$res2[$v[$clef_index]] = $v;
174
			$res2[$v[$clef_index]] = $v;
176
		}
175
		}
177
 
176
 
178
		// l'appelant s'occupera du json_encode()
177
		// l'appelant s'occupera du json_encode()
179
		// même si ça démange d'exit'er ici
178
		// même si ça démange d'exit'er ici
180
		if(strpos($_SERVER['SCRIPT_NAME'], 'phpunit') === FALSE) header("Content-Type: application/json; charset=utf-8");
179
		if(strpos($_SERVER['SCRIPT_NAME'], 'phpunit') === FALSE) header("Content-Type: application/json; charset=utf-8");
181
		return array('entete' => array(
180
		return array('entete' => array(
182
			'depart' => $params['navigation.depart'],
181
			'depart' => $params['navigation.depart'],
183
			'limite' => $params['navigation.limite'],
182
			'limite' => $params['navigation.limite'],
184
			'total' => count($res2),
183
			'total' => count($res2),
185
			'match' => $matches),
184
			'match' => $matches),
186
					 'resultats' => $res2);
185
			'resultats' => $res2);
187
	}
186
	}
188
 
187
 
189
 
188
 
190
	// la fonction centrale: récupère les infos à partir de paramètres
189
	// la fonction centrale: récupère les infos à partir de paramètres
191
	// et une optionnelle contrainte sur coste:nn ou bdtfx:nn
190
	// et une optionnelle contrainte sur coste:nn ou bdtfx:nn
192
	static function getCosteInfo(array $params, $db) {
191
	static function getCosteInfo(array $params, $db) {
193
		// contraintes (WHERE):
192
		// contraintes (WHERE):
194
		$constraints = self::sqlAddConstraint($params, $db);
193
		$constraints = self::sqlAddConstraint($params, $db);
195
		// XXX: que faire en l'absence de contrainte ? pour l'instant : "WHERE 1"
194
		// XXX: que faire en l'absence de contrainte ? pour l'instant : "WHERE 1"
196
 
195
 
197
		// champs:
196
		// champs:
198
		$champs_valides_non_formattes = NULL;
197
		$champs_valides_non_formattes = NULL;
199
		$champs_valides = self::sqlSelectFields($params, $champs_valides_non_formattes);
198
		$champs_valides = self::sqlSelectFields($params, $champs_valides_non_formattes);
200
 
199
 
201
		// joins:
200
		// joins:
202
		$other_join = self::sqlAddJoins($params, $champs_valides_non_formattes);
201
		$other_join = self::sqlAddJoins($params, $champs_valides_non_formattes);
203
		$requete_tpl = "SELECT SQL_CALC_FOUND_ROWS  %s".
202
		$requete_tpl = "SELECT SQL_CALC_FOUND_ROWS  %s ".
204
			"FROM tb_eflore.coste_v2_00 c ".
203
			"FROM tb_eflore.coste_v2_00 c ".
205
			"	LEFT JOIN tela_prod_wikini.florecoste_pages dsc ON c.page_wiki_dsc = dsc.tag AND dsc.latest = 'Y' ".
204
			"	LEFT JOIN tela_prod_wikini.florecoste_pages dsc ON c.page_wiki_dsc = dsc.tag AND dsc.latest = 'Y' ".
206
			"	LEFT JOIN tela_prod_wikini.florecoste_pages cle ON c.page_wiki_cle = cle.tag AND cle.latest = 'Y' ".
205
			"	LEFT JOIN tela_prod_wikini.florecoste_pages cle ON c.page_wiki_cle = cle.tag AND cle.latest = 'Y' ".
207
			" %s ".
206
			" %s ".
208
			"WHERE %s ORDER BY c.num_nom LIMIT %u, %u -- %s ";
207
			"WHERE %s ORDER BY c.num_nom LIMIT %u, %u -- %s ";
209
		$req = sprintf($requete_tpl,
208
		$req = sprintf($requete_tpl,
210
			$champs_valides, // dans le SELECT (parmi champs coste_v2_00)
209
			$champs_valides, // dans le SELECT (parmi champs coste_v2_00)
211
			// autre join, si nécessaire
210
			// autre join, si nécessaire
212
			$other_join ? $other_join : '',
211
			$other_join ? $other_join : '',
213
 
212
 
214
			// where
213
			// where
215
			$constraints ? implode(' AND ', $constraints) : '1',
214
			$constraints ? implode(' AND ', $constraints) : '1',
216
 
215
 
217
			// limit
216
			// limit
218
			$params['navigation.depart'],
217
			$params['navigation.depart'],
219
			$params['navigation.limite'],
218
			$params['navigation.limite'],
220
			__FILE__ . ':' . __LINE__);
219
			__FILE__ . ':' . __LINE__);
221
 
220
 
222
		return $req;
221
		return $req;
223
	}
222
	}
224
 
223
 
225
	// SQL helpers
224
	// SQL helpers
226
	// le préfix de coste_v2_00 est "c"
225
	// le préfix de coste_v2_00 est "c"
227
	// le préfix de florecoste_pages sur la description est est "dsc"
226
	// le préfix de florecoste_pages sur la description est est "dsc"
228
	// le préfix de florecoste_pages sur la clef de détermination est est "cle"
227
	// le préfix de florecoste_pages sur la clef de détermination est est "cle"
229
	static function sqlAddConstraint($params, $db) {
228
	static function sqlAddConstraint($params, $db) {
230
		$stack = array();
229
		$stack = array();
231
		if (!empty($params['masque.ns'])) {
230
		if (!empty($params['masque.ns'])) {
232
			if ($params['recherche'] == 'etendue') {
231
			if ($params['recherche'] == 'etendue') {
233
				$stack[] = 'c.nom_sci LIKE '.$db->proteger('%' . trim($params['masque.ns']).'%');
232
				$stack[] = 'c.nom_sci LIKE '.$db->proteger('%' . trim($params['masque.ns']).'%');
234
			} elseif($params['recherche'] == 'floue') {
233
			} elseif($params['recherche'] == 'floue') {
235
				$stack[] = sprintf(self::$soundex_scheme,
234
				$stack[] = sprintf(self::$soundex_scheme,
236
					'c.nom_sci',
235
					'c.nom_sci',
237
					$db->proteger('%'.trim($params['masque.ns']).'%'));
236
					$db->proteger('%'.trim($params['masque.ns']).'%'));
238
			} else {
237
			} else {
239
				$stack[] = 'c.nom_sci = '.$db->proteger(trim($params['masque.ns']));
238
				$stack[] = 'c.nom_sci = '.$db->proteger(trim($params['masque.ns']));
240
			}
239
			}
241
		}
240
		}
242
 
241
 
243
		// le masque sur texte est toujours un LIKE() "étendue", sauf si "floue" spécifié
242
		// le masque sur texte est toujours un LIKE() "étendue", sauf si "floue" spécifié
244
		if(!empty($params['masque.txt'])) {
243
		if(!empty($params['masque.txt'])) {
245
			if($params['recherche'] == 'floue') {
244
			if($params['recherche'] == 'floue') {
246
				$stack[] = sprintf(self::$soundex_scheme,
245
				$stack[] = sprintf(self::$soundex_scheme,
247
					'dsc.body',
246
					'dsc.body',
248
					$db->proteger('%'.trim($params['masque.txt']).'%'));
247
					$db->proteger('%'.trim($params['masque.txt']).'%'));
249
			}
248
			}
250
			else {
249
			else {
251
				$stack[] = 'dsc.body LIKE '.$db->proteger('%'.trim($params['masque.txt']).'%');
250
				$stack[] = 'dsc.body LIKE '.$db->proteger('%'.trim($params['masque.txt']).'%');
252
			}
251
			}
253
		}
252
		}
254
 
253
 
255
		if(!empty($params['masque.titre'])) {
254
		if(!empty($params['masque.titre'])) {
256
			if($params['recherche'] == 'stricte') {
255
			if($params['recherche'] == 'stricte') {
257
				$stack[] = sprintf('(dsc.tag = %1$s OR cle.tag = %1$s)',
256
				$stack[] = sprintf('(dsc.tag = %1$s OR cle.tag = %1$s)',
258
					$db->proteger(trim($params['masque.titre'])));
257
					$db->proteger(trim($params['masque.titre'])));
259
			}
258
			}
260
			else {
259
			else {
261
				$stack[] = sprintf('(dsc.tag LIKE %1$s OR cle.tag LIKE %1$s)',
260
				$stack[] = sprintf('(dsc.tag LIKE %1$s OR cle.tag LIKE %1$s)',
262
					$db->proteger('%'.trim($params['masque.titre']).'%'));
261
					$db->proteger('%'.trim($params['masque.titre']).'%'));
263
			}
262
			}
264
		}
263
		}
265
 
264
 
266
		if(array_key_exists('masque.famille', $params)) {
265
		if(array_key_exists('masque.famille', $params)) {
267
			$stack[] = 'b.famille LIKE '.$db->proteger(trim($params['masque.famille']));
266
			$stack[] = 'b.famille LIKE '.$db->proteger(trim($params['masque.famille']));
268
		}
267
		}
269
 
268
 
270
		if(array_key_exists('masque.page', $params)) {
269
		if(array_key_exists('masque.page', $params)) {
271
			$stack[] = 'c.page = '.intval($params['masque.page']);
270
			$stack[] = 'c.page = '.intval($params['masque.page']);
272
		}
271
		}
273
 
272
 
274
		if(array_key_exists('masque.tome', $params)) {
273
		if(array_key_exists('masque.tome', $params)) {
275
			$stack[] = 'c.tome = '.intval($params['masque.tome']);
274
			$stack[] = 'c.tome = '.intval($params['masque.tome']);
276
		}
275
		}
277
 
276
 
278
		if(array_key_exists('masque.nt', $params)) {
277
		if(array_key_exists('masque.nt', $params)) {
279
			$stack[] = 'c.flore_bdtfx_nt = '.intval($params['masque.nt']);
278
			$stack[] = 'c.flore_bdtfx_nt = '.intval($params['masque.nt']);
280
		}
279
		}
281
 
280
 
282
		// ajout de la contrainte sur coste:nn ou bdtfx:nn si un composant d'URL supplémentaire
281
		// ajout de la contrainte sur coste:nn ou bdtfx:nn si un composant d'URL supplémentaire
283
		// comportant un #id existe, cf self::requestFilterIds()
282
		// comportant un #id existe, cf self::requestFilterIds()
284
		$o_stack = array();
283
		$o_stack = array();
285
		if (array_key_exists('_ids', $params) && $params['_ids']) {
284
		if (array_key_exists('_ids', $params) && $params['_ids']) {
286
			if ($params['_ids']['coste']) {
285
			if ($params['_ids']['coste.nn']) {
287
				$o_stack[] = sprintf("c.num_nom IN (%s)", implode(',', $params['_ids']['coste']));
286
				$o_stack[] = sprintf("c.num_nom IN (%s)", implode(',', $params['_ids']['coste.nn']));
-
 
287
			}
-
 
288
			if ($params['_ids']['bdtfx.nn']) {
-
 
289
				$o_stack[] = sprintf("c.flore_bdtfx_nn IN (%s)", implode(',', $params['_ids']['bdtfx.nn']));
288
			}
290
			}
289
			if ($params['_ids']['bdtfx']) {
291
			if ($params['_ids']['bdtfx.nt']) {
290
				$o_stack[] = sprintf("c.flore_bdtfx_nn IN (%s)", implode(',', $params['_ids']['bdtfx']));
292
				$o_stack[] = sprintf("c.flore_bdtfx_nt IN (%s)", implode(',', $params['_ids']['bdtfx.nt']));
291
			}
293
			}
292
		}
294
		}
293
		if ($o_stack) {
295
		if ($o_stack) {
294
			$stack[] = '(' . implode(' OR ', $o_stack) . ')';
296
			$stack[] = '(' . implode(' OR ', $o_stack) . ')';
295
		}
297
		}
296
 
298
 
297
		return $stack;
299
		return $stack;
298
	}
300
	}
299
 
301
 
300
 
302
 
301
	// $unmerged contient la même liste de champs que celle renvoyée
303
	// $unmerged contient la même liste de champs que celle renvoyée
302
	// à la différence que celle-ci n'est pas reformatée et s'avère donc
304
	// à la différence que celle-ci n'est pas reformatée et s'avère donc
303
	// utilisable plus aisément dans sqlAddJoins() qui peut en avoir besoin
305
	// utilisable plus aisément dans sqlAddJoins() qui peut en avoir besoin
304
	static function sqlSelectFields($params, &$unmerged) {
306
	static function sqlSelectFields($params, &$unmerged) {
305
		$champs = $params['retour.champs'];
307
		$champs = $params['retour.champs'];
306
		// champs coste_v2_00
308
		// champs coste_v2_00
307
		$c = self::addSQLToFieldSynonym(explode(',', $champs));
309
		$c = self::addSQLToFieldSynonym(explode(',', $champs));
308
		if (isset($c['*'])) {
310
		if (isset($c['*'])) {
309
			$t = array_diff_key(self::$allow_champs, array_flip(self::$special_champs));
311
			$t = array_diff_key(self::$allow_champs, array_flip(self::$special_champs));
310
		} else {
312
		} else {
311
			// just loop below
313
			// just loop below
312
			$t = $c;
314
			$t = $c;
313
		}
315
		}
314
 
316
 
315
		// si aucun des champs fournis n'est valide
317
		// si aucun des champs fournis n'est valide
316
		// on se rappelle nous-même après avoir réinitialisé retour.champs
318
		// on se rappelle nous-même après avoir réinitialisé retour.champs
317
		// avec les champs par défaut
319
		// avec les champs par défaut
318
		if(!$t) {
320
		if(!$t) {
319
			$params['retour.champs'] = self::$default_params['retour.champs'];
321
			$params['retour.champs'] = self::$default_params['retour.champs'];
320
			return self::sqlSelectFields($params);
322
			return self::sqlSelectFields($params);
321
		}
323
		}
322
 
324
 
323
		if(array_key_exists('titre', $t))
325
		if(array_key_exists('titre', $t))
324
			$t['titre'] = $params['txt.format'] == 'txt' ? 'c.nom_sci' : 'c.nom_sci_html';
326
			$t['titre'] = $params['txt.format'] == 'txt' ? 'c.nom_sci' : 'c.nom_sci_html';
325
 
327
 
326
		// champs obligatoires:
328
		// champs obligatoires:
327
		$t = array_merge($t, self::addSQLToFieldSynonym(self::$champs_obligatoires));
329
		$t = array_merge($t, self::addSQLToFieldSynonym(self::$champs_obligatoires));
328
		$unmerged = $t;
330
		$unmerged = $t;
329
 
331
 
330
		// XXX: PHP-5.3
332
		// XXX: PHP-5.3
331
		$ret = array();
333
		$ret = array();
332
		foreach($t as $k => $v) {
334
		foreach($t as $k => $v) {
333
			if (strpos($k, ':') !== FALSE) {
335
			if (strpos($k, ':') !== FALSE) {
334
				$ret[] = "$v AS \"$k\"";
336
				$ret[] = "$v AS \"$k\"";
335
			} else {
337
			} else {
336
				$ret[] = "$v AS $k";
338
				$ret[] = "$v AS $k";
337
			}
339
			}
338
		}
340
		}
339
		return implode(',',$ret);
341
		return implode(',',$ret);
340
	}
342
	}
341
 
343
 
342
	static function sqlAddJoins($params, $champs) {
344
	static function sqlAddJoins($params, $champs) {
343
		$j = '';
345
		$j = '';
344
		// ces tests doivent correspondre aux champs générés par sqlSelectFields()
346
		// ces tests doivent correspondre aux champs générés par sqlSelectFields()
345
		// ou contraintes générées par sqlAddConstraint()
347
		// ou contraintes générées par sqlAddConstraint()
346
		if(array_key_exists('masque.famille', $params) ||
348
		if(array_key_exists('masque.famille', $params) ||
347
		   array_key_exists('famille', $champs)) {
349
		   array_key_exists('famille', $champs)) {
348
			$j .= 'LEFT JOIN tb_eflore.bdtfx_v2_00 b ON c.flore_bdtfx_nn = b.num_nom';
350
			$j .= 'LEFT JOIN tb_eflore.bdtfx_v2_00 b ON c.flore_bdtfx_nn = b.num_nom';
349
		}
351
		}
350
 
352
 
351
		return $j;
353
		return $j;
352
	}
354
	}
353
 
355
 
354
	// d'un tableau de type array("coste:nn", "type_epithete")
356
	// d'un tableau de type array("coste:nn", "type_epithete")
355
	// retourne
357
	// retourne
356
	// un tableau de type array("coste:nn" => "c.num_nom", "type_epithete" => "c.type_epithete")
358
	// un tableau de type array("coste:nn" => "c.num_nom", "type_epithete" => "c.type_epithete")
357
	// basé sur self::$allow_champs
359
	// basé sur self::$allow_champs
358
	static function addSQLToFieldSynonym(Array $syno) {
360
	static function addSQLToFieldSynonym(Array $syno) {
359
		return array_intersect_key(self::$allow_champs, array_flip($syno));
361
		return array_intersect_key(self::$allow_champs, array_flip($syno));
360
	}
362
	}
361
 
363
 
362
	// request handler
364
	// request handler
363
	static function requestParse(&$ressource, &$params) {
365
	static function requestParse(&$ressource, &$params) {
364
		if (isset($_SERVER['REDIRECT_URL'])) {
366
		if (isset($_SERVER['REDIRECT_URL'])) {
365
            $uri = explode('/', $_SERVER['REDIRECT_URL']);
367
			$uri = explode('/', $_SERVER['REDIRECT_URL']);
366
        } else {
368
		} else {
367
            $uri = explode('/', $_SERVER['REQUEST_URI']);
369
			$uri = explode('/', $_SERVER['REQUEST_URI']);
368
        }
370
		}
369
		if(!empty($_SERVER['QUERY_STRING']))
371
		if (!empty($_SERVER['QUERY_STRING'])) {
370
			parse_str($_SERVER['QUERY_STRING'], $params);
372
			parse_str($_SERVER['QUERY_STRING'], $params);
-
 
373
		}
371
		$ressource = array_slice($uri, array_search('textes', $uri) + 1, 3);
374
		$ressource = array_slice($uri, array_search('textes', $uri) + 1, 3);
372
	}
375
	}
373
 
376
 
374
	// supprime l'index du tableau des paramètres si sa valeur ne correspond pas
377
	// supprime l'index du tableau des paramètres si sa valeur ne correspond pas
375
	// au spectre passé par $values.
378
	// au spectre passé par $values.
376
	static function unsetIfInvalid(&$var, $index, $values) {
379
	static function unsetIfInvalid(&$var, $index, $values) {
377
		if(array_key_exists($index, $var) && !in_array($var[$index], $values))
380
		if(array_key_exists($index, $var) && !in_array($var[$index], $values))
378
			unset($var[$index]);
381
			unset($var[$index]);
379
	}
382
	}
380
 
383
 
381
	static function requestFilterParams(Array $params) {
384
	static function requestFilterParams(Array $params) {
382
		$p = array_intersect_key($params, array_flip(self::$allow_params));
385
		$p = array_intersect_key($params, array_flip(self::$allow_params));
383
		self::unsetIfInvalid($p, 'txt.format', array('txt', 'htm'));
386
		self::unsetIfInvalid($p, 'txt.format', array('txt', 'htm'));
384
		self::unsetIfInvalid($p, 'retour.format', array('min','max'));
387
		self::unsetIfInvalid($p, 'retour.format', array('min','max'));
385
		self::unsetIfInvalid($p, 'retour.indexBy', array('coste', 'bdtfx'));
388
		self::unsetIfInvalid($p, 'retour.indexBy', array('coste', 'bdtfx'));
386
		self::unsetIfInvalid($p, 'recherche', array('stricte','etendue','floue'));
389
		self::unsetIfInvalid($p, 'recherche', array('stricte','etendue','floue'));
387
 
390
 
388
		if(isset($params['masque.ns'])) $p['masque.ns'] = trim($params['masque.ns']);
391
		if(isset($params['masque.ns'])) $p['masque.ns'] = trim($params['masque.ns']);
389
		if(isset($params['masque.texte'])) $p['masque.texte'] = trim($params['masque.texte']);
392
		if(isset($params['masque.texte'])) $p['masque.texte'] = trim($params['masque.texte']);
390
 
393
 
391
		if(isset($params['masque.famille'])) {
394
		if(isset($params['masque.famille'])) {
392
			// mysql -N<<<"SELECT DISTINCT famille FROM bdtfx_v2_00;"|sed -r "s/(.)/\1\n/g"|sort -u|tr -d "\n"
395
			// mysql -N<<<"SELECT DISTINCT famille FROM bdtfx_v2_00;"|sed -r "s/(.)/\1\n/g"|sort -u|tr -d "\n"
393
			$p['masque.famille'] = preg_replace('/[^a-zA-Z %_]/', '', iconv("UTF-8",
396
			$p['masque.famille'] = preg_replace('/[^a-zA-Z %_]/', '', iconv("UTF-8",
394
																			"ASCII//TRANSLIT",
397
																			"ASCII//TRANSLIT",
395
																			$params['masque.famille']));
398
																			$params['masque.famille']));
396
		}
399
		}
397
 
400
 
398
		// TODO: use filter_input(INPUT_GET);
401
		// TODO: use filter_input(INPUT_GET);
399
		// renvoie FALSE ou NULL si absent ou invalide
402
		// renvoie FALSE ou NULL si absent ou invalide
400
		$p['navigation.limite'] = filter_var(@$params['navigation.limite'],
403
		$p['navigation.limite'] = filter_var(@$params['navigation.limite'],
401
			FILTER_VALIDATE_INT,
404
			FILTER_VALIDATE_INT,
402
			array('options' => array(
405
			array('options' => array(
403
				'default' => NULL,
406
				'default' => NULL,
404
				'min_range' => 1,
407
				'min_range' => 1,
405
				'max_range' => _COSTE_TEXTE_MAX_RESULT_LIMIT)));
408
				'max_range' => _COSTE_TEXTE_MAX_RESULT_LIMIT)));
406
		$p['navigation.depart'] = filter_var(@$params['navigation.depart'],
409
		$p['navigation.depart'] = filter_var(@$params['navigation.depart'],
407
			FILTER_VALIDATE_INT,
410
			FILTER_VALIDATE_INT,
408
			array('options' => array(
411
			array('options' => array(
409
				'default' => NULL,
412
				'default' => NULL,
410
				'min_range' => 0,
413
				'min_range' => 0,
411
				'max_range' => _COSTE_TEXTE_MAX_COSTE_NN)));
414
				'max_range' => _COSTE_TEXTE_MAX_COSTE_NN)));
412
		$p['masque.page'] = filter_var(@$params['masque.page'],
415
		$p['masque.page'] = filter_var(@$params['masque.page'],
413
			FILTER_VALIDATE_INT,
416
			FILTER_VALIDATE_INT,
414
			array('options' => array(
417
			array('options' => array(
415
				'default' => NULL,
418
				'default' => NULL,
416
				'min_range' => 0,
419
				'min_range' => 0,
417
				'max_range' => _COSTE_TEXTE_MAX_COSTE_PAGE)));
420
				'max_range' => _COSTE_TEXTE_MAX_COSTE_PAGE)));
418
		$p['masque.tome'] = filter_var(@$params['masque.tome'],
421
		$p['masque.tome'] = filter_var(@$params['masque.tome'],
419
			FILTER_VALIDATE_INT,
422
			FILTER_VALIDATE_INT,
420
			array('options' => array(
423
			array('options' => array(
421
				'default' => NULL,
424
				'default' => NULL,
422
				'min_range' => 0,
425
				'min_range' => 0,
423
				'max_range' => _COSTE_TEXTE_MAX_COSTE_TOME)));
426
				'max_range' => _COSTE_TEXTE_MAX_COSTE_TOME)));
424
		$p['masque.nt'] = filter_var(@$params['masque.nt'],
427
		$p['masque.nt'] = filter_var(@$params['masque.nt'],
425
			FILTER_VALIDATE_INT,
428
			FILTER_VALIDATE_INT,
426
			array('options' => array(
429
			array('options' => array(
427
				'default' => NULL,
430
				'default' => NULL,
428
				'min_range' => 0,
431
				'min_range' => 0,
429
				'max_range' => _COSTE_TEXTE_MAX_BDTFX_NT)));
432
				'max_range' => _COSTE_TEXTE_MAX_BDTFX_NT)));
430
 
433
 
431
		// on filtre les NULL, FALSE et '', mais pas les 0, d'où le callback()
434
		// on filtre les NULL, FALSE et '', mais pas les 0, d'où le callback()
432
		// TODO: PHP-5.3
435
		// TODO: PHP-5.3
433
		$p = array_filter($p, create_function('$a','return !in_array($a, array("",false,null),true);'));
436
		$p = array_filter($p, create_function('$a','return !in_array($a, array("",false,null),true);'));
434
		$p = array_merge(self::$default_params, $p);
437
		$p = array_merge(self::$default_params, $p);
435
 
438
 
436
		return $p;
439
		return $p;
437
	}
440
	}
438
 
441
 
439
	static function requestFilterIds($uri) {
442
	static function requestFilterIds($uri) {
440
		if(count($uri) != 1) return NULL;
443
		if(count($uri) != 1) return NULL;
441
 
444
 
442
		// getNN* renvoient le num_nom passé comme segment d'URI:
445
		// getNN* renvoient le num_nom passé comme segment d'URI:
443
		// - soit un id selon coste (num_nom dans coste_v2_00)
446
		// - soit un id selon coste (num_nom dans coste_v2_00)
444
		// - soit un id selon bdtfx (num_nom dans bdtfx_v2_00)
447
		// - soit un id selon bdtfx (num_nom dans bdtfx_v2_00)
445
		// ou bien l'extrait du pattern bdtfx.nn:(#id)
448
		// ou bien l'extrait du pattern bdtfx.nn:(#id)
446
		$ids_coste = array_filter(array_map(array(__CLASS__, 'getNNCoste'), explode(',', $uri[0])));
449
		$ids_coste_nn = array_filter(array_map(array(__CLASS__, 'getNNCoste'), explode(',', $uri[0])));
447
		$ids_bdtfx = array_filter(array_map(array(__CLASS__, 'getNNBdtfx'), explode(',', $uri[0])));
450
		$ids_bdtfx_nn = array_filter(array_map(array(__CLASS__, 'getNNBdtfx'), explode(',', $uri[0])));
-
 
451
		$ids_bdtfx_nt = array_filter(array_map(array(__CLASS__, 'getNTBdtfx'), explode(',', $uri[0])));
448
 
452
 
449
		// en cas d'échec (tous les id sont invalides), bail-out
453
		// en cas d'échec (tous les id sont invalides), bail-out
450
		if(!$ids_bdtfx && !$ids_coste) {
454
		if(!$ids_bdtfx_nt && !$ids_bdtfx_nn && !$ids_coste_nn) {
451
			// http_response_code(500);
455
			// http_response_code(500);
452
			throw new Exception('not supported', 500);
456
			throw new Exception('not supported', 500);
453
		}
457
		}
454
 
458
 
455
		return array(
459
		return array(
456
			'coste' => array_slice($ids_coste, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) ),
460
			'coste.nn' => array_slice($ids_coste_nn, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) ),
-
 
461
			'bdtfx.nn' => array_slice($ids_bdtfx_nn, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) ),
457
			'bdtfx' => array_slice($ids_bdtfx, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) )
462
			'bdtfx.nt' => array_slice($ids_bdtfx_nt, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) )
458
		);
463
		);
459
	}
464
	}
460
 
465
 
461
	static function aide() {
466
	static function aide() {
462
		header("Content-Type: text/plain; charset=utf-8");
467
		header("Content-Type: text/plain; charset=utf-8");
463
		return sprintf("Service coste/textes:
468
		return sprintf("Service coste/textes:
464
 
469
 
465
Retourne des informations (choisies) à propos d'un taxon donné (à partir de son numéro nomenclatural
470
Retourne des informations (choisies) à propos d'un taxon donné (à partir de son numéro nomenclatural
466
Retourne des informations (choisies) à propos de taxons recherchés (à partir de divers critères)
471
Retourne des informations (choisies) à propos de taxons recherchés (à partir de divers critères)
467
Les résultats sont indexés. La clef par défaut est le num_nom d'après coste (attribut \"coste:nn\")
472
Les résultats sont indexés. La clef par défaut est le num_nom d'après coste (attribut \"coste:nn\")
468
Usage:  coste/textes[/<liste-num_nom>]?<params>
473
Usage:  coste/textes[/<liste-num_nom>]?<params>
469
 
474
 
470
* le paramètre \"retour.indexBy\" affecte le mode d'indexation (\"bdtfx\" ou \"coste\" (defaut))
475
* le paramètre \"retour.indexBy\" affecte le mode d'indexation (\"bdtfx\" ou \"coste\" (defaut))
471
* <liste-num_nom> étant une liste de numéros nomenclaturaux de taxons séparés par des virgules au format:
476
* <liste-num_nom> étant une liste de numéros nomenclaturaux de taxons séparés par des virgules au format:
472
 - <#id>: un numéro nomenclatural dans la base coste
477
 - <#id>: un numéro nomenclatural dans la base coste
473
 - <bdtfx.nn:#id>: un numéro nomenclatural dans la base bdtfx
478
 - <bdtfx.nn:#id>: un numéro nomenclatural dans la base bdtfx
474
* retour.champs une liste de champs séparés par des virgules parmi *,%s
479
* retour.champs une liste de champs séparés par des virgules parmi *,%s
475
* les paramètres acceptés sont les suivants: %s
480
* les paramètres acceptés sont les suivants: %s
476
* les champs retournés par défaut sont les suivants: %s
481
* les champs retournés par défaut sont les suivants: %s
477
* le paramètre \"recherche\" affecte les masques \"ns\" et \"texte\"
482
* le paramètre \"recherche\" affecte les masques \"ns\" et \"texte\"
478
* le paramètre \"famille\" est traité via LIKE et accepte les caractères '_' et '%%'
483
* le paramètre \"famille\" est traité via LIKE et accepte les caractères '_' et '%%'
479
* le paramètre \"retour.format\" est inutilisé pour l'instant.
484
* le paramètre \"retour.format\" est inutilisé pour l'instant.
480
 
485
 
481
Exemples:
486
Exemples:
482
/service:eflore:0.1/coste/textes/bdtfx.nn:182?retour.champs=titre
487
/service:eflore:0.1/coste/textes/bdtfx.nn:182?retour.champs=titre
483
	# retourne l'Acer monspessulanum
488
	# retourne l'Acer monspessulanum
484
/service:eflore:0.1/coste/textes/182?retour.champs=titre
489
/service:eflore:0.1/coste/textes/182?retour.champs=titre
485
	# retourne la Roemeria violacea (bdtfx:nn = 56272)
490
	# retourne la Roemeria violacea (bdtfx:nn = 56272)
486
/service:eflore:0.1/coste/textes/182,bdtfx.nn:182?retour.champs=titre
491
/service:eflore:0.1/coste/textes/182,bdtfx.nn:182?retour.champs=titre
487
	# retourne les deux précédents
492
	# retourne les deux précédents
488
/service:eflore:0.1/coste/textes?masque.titre=Cla001Thalamiflores&retour.champs=titre
493
/service:eflore:0.1/coste/textes?masque.titre=Cla001Thalamiflores&retour.champs=titre
489
	# retourne la section de Coste relatives aux Thalamiflores
494
	# retourne la section de Coste relatives aux Thalamiflores
490
/service:eflore:0.1/coste/textes?masque.titre=Thalamiflores&recherche=floue&retour.champs=titre
495
/service:eflore:0.1/coste/textes?masque.titre=Thalamiflores&recherche=floue&retour.champs=titre
491
	# idem, en utilisant une recherche floue
496
	# idem, en utilisant une recherche floue
492
/service:eflore:0.1/coste/textes?masque.titre=Cla001Thalamiflores&retour.champs=titre&retour.indexBy=bdtfx
497
/service:eflore:0.1/coste/textes?masque.titre=Cla001Thalamiflores&retour.champs=titre&retour.indexBy=bdtfx
493
	# retourne une erreur de format car cette section de coste n'est associée à aucun taxon de la BDTFX
498
	# retourne une erreur de format car cette section de coste n'est associée à aucun taxon de la BDTFX
494
",
499
",
495
			implode(',', array_keys(self::$allow_champs)),
500
			implode(',', array_keys(self::$allow_champs)),
496
			implode(',', self::$allow_params),
501
			implode(',', self::$allow_params),
497
			self::$default_params['retour.champs']
502
			self::$default_params['retour.champs']
498
		);
503
		);
499
	}
504
	}
500
 
505
 
501
	static function getNNCoste($refnn) {
506
	static function getNNCoste($refnn) {
502
		if (is_numeric($refnn)) {
507
		if (is_numeric($refnn)) {
503
			$t = intval($refnn);
508
			$t = intval($refnn);
504
			if ($t >= 1 && $t < _COSTE_TEXTE_MAX_COSTE_NN) return $t;
509
			if ($t >= 1 && $t < _COSTE_TEXTE_MAX_COSTE_NN) return $t;
505
		}
510
		}
506
		return FALSE;
511
		return FALSE;
507
	}
512
	}
508
 
513
 
509
	static function getNNBdtfx($refnn) {
514
	static function getNNBdtfx($refnn) {
510
		if(strpos($refnn, 'bdtfx.nn:') !== 0) return FALSE;
515
		if(strpos($refnn, 'bdtfx.nn:') !== 0) return FALSE;
511
		$t = intval(str_replace('bdtfx.nn:', '', $refnn));
516
		$t = intval(str_replace('bdtfx.nn:', '', $refnn));
512
		if($t >= 1 && $t < _COSTE_TEXTE_MAX_BDTFX_NN) return $t;
517
		if($t >= 1 && $t < _COSTE_TEXTE_MAX_BDTFX_NN) return $t;
513
		return FALSE;
518
		return FALSE;
-
 
519
	}
-
 
520
 
-
 
521
	static function getNTBdtfx($refnt) {
-
 
522
		if(strpos($refnt, 'bdtfx.nt:') !== 0) return FALSE;
-
 
523
		$t = intval(str_replace('bdtfx.nt:', '', $refnt));
-
 
524
		if($t >= 1 && $t < _COSTE_TEXTE_MAX_BDTFX_NT) return $t;
-
 
525
		return FALSE;
514
	}
526
	}
515
}
527
}