Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 933 | Rev 948 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 933 Rev 934
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_v1_02;
35
// SELECT MAX(num_nom) FROM bdtfx_v1_02;
36
define('_COSTE_TEXTE_MAX_BDTFX_NN', 103386 + 10000);
36
define('_COSTE_TEXTE_MAX_BDTFX_NN', 103386 + 10000);
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' => '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');
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
			return self::aide();
135
			die(self::aide());
136
		}
136
		}
137
 
-
 
138
 
137
 
139
		if (is_null($parametres)) {
138
		if (is_null($parametres)) {
140
			$parametres = Array();
139
			$parametres = Array();
141
		}
140
		}
142
		$params = self::requestFilterParams($parametres);
141
		$params = self::requestFilterParams($parametres);
143
		// 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)
144
		// 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]
145
		$params['_ids'] = self::requestFilterIds($uri);
144
		$params['_ids'] = self::requestFilterIds($uri);
146
 
145
 
147
		// XXX: temporaires, passage de $db aux fonctions
146
		// XXX: temporaires, passage de $db aux fonctions
148
		// de toolkits
147
		// de toolkits
149
		$req = self::getCosteInfo($params, $db);
148
		$req = self::getCosteInfo($params, $db);
150
 
149
 
151
		$res = $db->recupererTous($req);
150
		$res = $db->recupererTous($req);
152
		$err = mysql_error();
151
		$err = mysql_error();
153
		if (!$res && $err) {
152
		if (!$res && $err) {
154
			// http_response_code(400);
153
			// http_response_code(400);
155
			// if(defined('DEBUG') && DEBUG) header("X-Debug: $req");
154
			// if(defined('DEBUG') && DEBUG) header("X-Debug: $req");
156
			throw new Exception('not found', 400);
155
			throw new Exception('not found', 400);
157
		}
156
		}
158
 
157
 
159
		// rapide formatage des résultats:
158
		// rapide formatage des résultats:
160
		$matches = 0;
159
		$matches = 0;
161
 
160
 
162
		if ($res) {
161
		if ($res) {
163
			// nombre de matches (sans LIMIT) utilisé pour l'en-tête
162
			// nombre de matches (sans LIMIT) utilisé pour l'en-tête
164
			$matches = $db->recuperer('SELECT FOUND_ROWS() AS total');
163
			$matches = $db->recuperer('SELECT FOUND_ROWS() AS total');
165
			$matches = intval($matches['total']);
164
			$matches = intval($matches['total']);
166
		}
165
		}
167
 
166
 
168
		// reformate les résultats pour les indexer par coste:nn par défaut
167
		// reformate les résultats pour les indexer par coste:nn par défaut
169
		// cependant le paramètre retour.indexBy permet de choisir une indexation par num_nom de bdtfx
168
		// cependant le paramètre retour.indexBy permet de choisir une indexation par num_nom de bdtfx
170
		$clef_index = $params['retour.indexBy'] == 'coste' ? 'coste:nn' : 'bdtfx:nn';
169
		$clef_index = $params['retour.indexBy'] == 'coste' ? 'coste:nn' : 'bdtfx:nn';
171
		$res2 = array();
170
		$res2 = array();
172
		foreach ($res as $v) {
171
		foreach ($res as $v) {
173
			if (!$v[$clef_index]) {
172
			if (!$v[$clef_index]) {
174
				throw new Exception('format error: index NULL, use retour.indexBy=coste', 409);
173
				throw new Exception('format error: index NULL, use retour.indexBy=coste', 409);
175
			}
174
			}
176
			$res2[$v[$clef_index]] = $v;
175
			$res2[$v[$clef_index]] = $v;
177
		}
176
		}
178
 
177
 
179
		// l'appelant s'occupera du json_encode()
178
		// l'appelant s'occupera du json_encode()
180
		// même si ça démange d'exit'er ici
179
		// même si ça démange d'exit'er ici
181
		header("Content-Type: application/json; charset=utf-8");
180
		header("Content-Type: application/json; charset=utf-8");
182
		return array('entete' => array(
181
		return array('entete' => array(
183
			'depart' => $params['navigation.depart'],
182
			'depart' => $params['navigation.depart'],
184
			'limite' => $params['navigation.limite'],
183
			'limite' => $params['navigation.limite'],
185
			'total' => count($res2),
184
			'total' => count($res2),
186
			'match' => $matches),
185
			'match' => $matches),
187
					 'resultats' => $res2);
186
					 'resultats' => $res2);
188
	}
187
	}
189
 
188
 
190
 
189
 
191
	// la fonction centrale: récupère les infos à partir de paramètres
190
	// la fonction centrale: récupère les infos à partir de paramètres
192
	// et une optionnelle contrainte sur coste:nn ou bdtfx:nn
191
	// et une optionnelle contrainte sur coste:nn ou bdtfx:nn
193
	static function getCosteInfo(array $params, $db) {
192
	static function getCosteInfo(array $params, $db) {
194
		// contraintes (WHERE):
193
		// contraintes (WHERE):
195
		$constraints = self::sqlAddConstraint($params, $db);
194
		$constraints = self::sqlAddConstraint($params, $db);
196
		// XXX: que faire en l'absence de contrainte ? pour l'instant : "WHERE 1"
195
		// XXX: que faire en l'absence de contrainte ? pour l'instant : "WHERE 1"
197
 
196
 
198
		// champs:
197
		// champs:
199
		$champs_valides_non_formattes = NULL;
198
		$champs_valides_non_formattes = NULL;
200
		$champs_valides = self::sqlSelectFields($params, $champs_valides_non_formattes);
199
		$champs_valides = self::sqlSelectFields($params, $champs_valides_non_formattes);
201
 
200
 
202
		// joins:
201
		// joins:
203
		$other_join = self::sqlAddJoins($params, $champs_valides_non_formattes);
202
		$other_join = self::sqlAddJoins($params, $champs_valides_non_formattes);
204
		$requete_tpl = "SELECT SQL_CALC_FOUND_ROWS  %s".
203
		$requete_tpl = "SELECT SQL_CALC_FOUND_ROWS  %s".
205
			"FROM tb_eflore.coste_v2_00 c ".
204
			"FROM tb_eflore.coste_v2_00 c ".
206
			"	LEFT JOIN tela_prod_wikini.florecoste_pages dsc ON c.page_wiki_dsc = dsc.tag AND dsc.latest = 'Y' ".
205
			"	LEFT JOIN tela_prod_wikini.florecoste_pages dsc ON c.page_wiki_dsc = dsc.tag AND dsc.latest = 'Y' ".
207
			"	LEFT JOIN tela_prod_wikini.florecoste_pages cle ON c.page_wiki_cle = cle.tag AND cle.latest = 'Y' ".
206
			"	LEFT JOIN tela_prod_wikini.florecoste_pages cle ON c.page_wiki_cle = cle.tag AND cle.latest = 'Y' ".
208
			" %s ".
207
			" %s ".
209
			"WHERE %s ORDER BY c.num_nom LIMIT %u, %u -- %s ";
208
			"WHERE %s ORDER BY c.num_nom LIMIT %u, %u -- %s ";
210
		$req = sprintf($requete_tpl,
209
		$req = sprintf($requete_tpl,
211
			$champs_valides, // dans le SELECT (parmi champs coste_v2_00)
210
			$champs_valides, // dans le SELECT (parmi champs coste_v2_00)
212
			// autre join, si nécessaire
211
			// autre join, si nécessaire
213
			$other_join ? $other_join : '',
212
			$other_join ? $other_join : '',
214
 
213
 
215
			// where
214
			// where
216
			$constraints ? implode(' AND ', $constraints) : '1',
215
			$constraints ? implode(' AND ', $constraints) : '1',
217
 
216
 
218
			// limit
217
			// limit
219
			$params['navigation.depart'],
218
			$params['navigation.depart'],
220
			$params['navigation.limite'],
219
			$params['navigation.limite'],
221
			__FILE__ . ':' . __LINE__);
220
			__FILE__ . ':' . __LINE__);
222
 
221
 
223
		return $req;
222
		return $req;
224
	}
223
	}
225
 
224
 
226
	// SQL helpers
225
	// SQL helpers
227
	// le préfix de coste_v2_00 est "c"
226
	// le préfix de coste_v2_00 est "c"
228
	// le préfix de florecoste_pages sur la description est est "dsc"
227
	// le préfix de florecoste_pages sur la description est est "dsc"
229
	// le préfix de florecoste_pages sur la clef de détermination est est "cle"
228
	// le préfix de florecoste_pages sur la clef de détermination est est "cle"
230
	static function sqlAddConstraint($params, $db) {
229
	static function sqlAddConstraint($params, $db) {
231
		$stack = array();
230
		$stack = array();
232
		if (!empty($params['masque.ns'])) {
231
		if (!empty($params['masque.ns'])) {
233
			if ($params['recherche'] == 'etendue') {
232
			if ($params['recherche'] == 'etendue') {
234
				$stack[] = 'c.nom_sci LIKE '.$db->proteger('%' . trim($params['masque.ns']).'%');
233
				$stack[] = 'c.nom_sci LIKE '.$db->proteger('%' . trim($params['masque.ns']).'%');
235
			} elseif($params['recherche'] == 'floue') {
234
			} elseif($params['recherche'] == 'floue') {
236
				$stack[] = sprintf(self::$soundex_scheme,
235
				$stack[] = sprintf(self::$soundex_scheme,
237
					'c.nom_sci',
236
					'c.nom_sci',
238
					$db->proteger('%'.trim($params['masque.ns']).'%'));
237
					$db->proteger('%'.trim($params['masque.ns']).'%'));
239
			} else {
238
			} else {
240
				$stack[] = 'c.nom_sci = '.$db->proteger(trim($params['masque.ns']));
239
				$stack[] = 'c.nom_sci = '.$db->proteger(trim($params['masque.ns']));
241
			}
240
			}
242
		}
241
		}
243
 
242
 
244
		// le masque sur texte est toujours un LIKE() "étendue", sauf si "floue" spécifié
243
		// le masque sur texte est toujours un LIKE() "étendue", sauf si "floue" spécifié
245
		if(!empty($params['masque.txt'])) {
244
		if(!empty($params['masque.txt'])) {
246
			if($params['recherche'] == 'floue') {
245
			if($params['recherche'] == 'floue') {
247
				$stack[] = sprintf(self::$soundex_scheme,
246
				$stack[] = sprintf(self::$soundex_scheme,
248
					'dsc.body',
247
					'dsc.body',
249
					$db->proteger('%'.trim($params['masque.txt']).'%'));
248
					$db->proteger('%'.trim($params['masque.txt']).'%'));
250
			}
249
			}
251
			else {
250
			else {
252
				$stack[] = 'dsc.body LIKE '.$db->proteger('%'.trim($params['masque.txt']).'%');
251
				$stack[] = 'dsc.body LIKE '.$db->proteger('%'.trim($params['masque.txt']).'%');
253
			}
252
			}
254
		}
253
		}
255
 
254
 
256
		if(!empty($params['masque.titre'])) {
255
		if(!empty($params['masque.titre'])) {
257
			if($params['recherche'] == 'stricte') {
256
			if($params['recherche'] == 'stricte') {
258
				$stack[] = sprintf('(dsc.tag = %1$s OR cle.tag = %1$s)',
257
				$stack[] = sprintf('(dsc.tag = %1$s OR cle.tag = %1$s)',
259
					$db->proteger(trim($params['masque.titre'])));
258
					$db->proteger(trim($params['masque.titre'])));
260
			}
259
			}
261
			else {
260
			else {
262
				$stack[] = sprintf('(dsc.tag LIKE %1$s OR cle.tag LIKE %1$s)',
261
				$stack[] = sprintf('(dsc.tag LIKE %1$s OR cle.tag LIKE %1$s)',
263
					$db->proteger('%'.trim($params['masque.titre']).'%'));
262
					$db->proteger('%'.trim($params['masque.titre']).'%'));
264
			}
263
			}
265
		}
264
		}
266
 
265
 
267
		if(array_key_exists('masque.famille', $params)) {
266
		if(array_key_exists('masque.famille', $params)) {
268
			$stack[] = 'b.famille LIKE '.$db->proteger(trim($params['masque.famille']));
267
			$stack[] = 'b.famille LIKE '.$db->proteger(trim($params['masque.famille']));
269
		}
268
		}
270
 
269
 
271
		if(array_key_exists('masque.page', $params)) {
270
		if(array_key_exists('masque.page', $params)) {
272
			$stack[] = 'c.page = '.intval($params['masque.page']);
271
			$stack[] = 'c.page = '.intval($params['masque.page']);
273
		}
272
		}
274
 
273
 
275
		if(array_key_exists('masque.tome', $params)) {
274
		if(array_key_exists('masque.tome', $params)) {
276
			$stack[] = 'c.tome = '.intval($params['masque.tome']);
275
			$stack[] = 'c.tome = '.intval($params['masque.tome']);
277
		}
276
		}
278
 
277
 
279
		if(array_key_exists('masque.nt', $params)) {
278
		if(array_key_exists('masque.nt', $params)) {
280
			$stack[] = 'c.flore_bdtfx_nt = '.intval($params['masque.nt']);
279
			$stack[] = 'c.flore_bdtfx_nt = '.intval($params['masque.nt']);
281
		}
280
		}
282
 
281
 
283
		// ajout de la contrainte sur coste:nn ou bdtfx:nn si un composant d'URL supplémentaire
282
		// ajout de la contrainte sur coste:nn ou bdtfx:nn si un composant d'URL supplémentaire
284
		// comportant un #id existe, cf self::requestFilterIds()
283
		// comportant un #id existe, cf self::requestFilterIds()
285
		$o_stack = array();
284
		$o_stack = array();
286
		if (array_key_exists('_ids', $params) && $params['_ids']) {
285
		if (array_key_exists('_ids', $params) && $params['_ids']) {
287
			if ($params['_ids']['coste']) {
286
			if ($params['_ids']['coste']) {
288
				$o_stack[] = sprintf("c.num_nom IN (%s)", implode(',', $params['_ids']['coste']));
287
				$o_stack[] = sprintf("c.num_nom IN (%s)", implode(',', $params['_ids']['coste']));
289
			}
288
			}
290
			if ($params['_ids']['bdtfx']) {
289
			if ($params['_ids']['bdtfx']) {
291
				$o_stack[] = sprintf("c.flore_bdtfx_nn IN (%s)", implode(',', $params['_ids']['bdtfx']));
290
				$o_stack[] = sprintf("c.flore_bdtfx_nn IN (%s)", implode(',', $params['_ids']['bdtfx']));
292
			}
291
			}
293
		}
292
		}
294
		if ($o_stack) {
293
		if ($o_stack) {
295
			$stack[] = '(' . implode(' OR ', $o_stack) . ')';
294
			$stack[] = '(' . implode(' OR ', $o_stack) . ')';
296
		}
295
		}
297
 
296
 
298
		return $stack;
297
		return $stack;
299
	}
298
	}
300
 
299
 
301
 
300
 
302
	// $unmerged contient la même liste de champs que celle renvoyée
301
	// $unmerged contient la même liste de champs que celle renvoyée
303
	// à la différence que celle-ci n'est pas reformatée et s'avère donc
302
	// à la différence que celle-ci n'est pas reformatée et s'avère donc
304
	// utilisable plus aisément dans sqlAddJoins() qui peut en avoir besoin
303
	// utilisable plus aisément dans sqlAddJoins() qui peut en avoir besoin
305
	static function sqlSelectFields($params, &$unmerged) {
304
	static function sqlSelectFields($params, &$unmerged) {
306
		$champs = $params['retour.champs'];
305
		$champs = $params['retour.champs'];
307
		// champs coste_v2_00
306
		// champs coste_v2_00
308
		$c = self::addSQLToFieldSynonym(explode(',', $champs));
307
		$c = self::addSQLToFieldSynonym(explode(',', $champs));
309
		if (isset($c['*'])) {
308
		if (isset($c['*'])) {
310
			$t = array_diff_key(self::$allow_champs, array_flip(self::$special_champs));
309
			$t = array_diff_key(self::$allow_champs, array_flip(self::$special_champs));
311
		} else {
310
		} else {
312
			// just loop below
311
			// just loop below
313
			$t = $c;
312
			$t = $c;
314
		}
313
		}
315
 
314
 
316
		// si aucun des champs fournis n'est valide
315
		// si aucun des champs fournis n'est valide
317
		// on se rappelle nous-même après avoir réinitialisé retour.champs
316
		// on se rappelle nous-même après avoir réinitialisé retour.champs
318
		// avec les champs par défaut
317
		// avec les champs par défaut
319
		if(!$t) {
318
		if(!$t) {
320
			$params['retour.champs'] = self::$default_params['retour.champs'];
319
			$params['retour.champs'] = self::$default_params['retour.champs'];
321
			return self::sqlSelectFields($params);
320
			return self::sqlSelectFields($params);
322
		}
321
		}
323
 
322
 
324
		if(array_key_exists('titre', $t))
323
		if(array_key_exists('titre', $t))
325
			$t['titre'] = $params['txt.format'] == 'txt' ? 'c.nom_sci' : 'c.nom_sci_html';
324
			$t['titre'] = $params['txt.format'] == 'txt' ? 'c.nom_sci' : 'c.nom_sci_html';
326
 
325
 
327
		// champs obligatoires:
326
		// champs obligatoires:
328
		$t = array_merge($t, self::addSQLToFieldSynonym(self::$champs_obligatoires));
327
		$t = array_merge($t, self::addSQLToFieldSynonym(self::$champs_obligatoires));
329
		$unmerged = $t;
328
		$unmerged = $t;
330
 
329
 
331
		// XXX: PHP-5.3
330
		// XXX: PHP-5.3
332
		$ret = array();
331
		$ret = array();
333
		foreach($t as $k => $v) {
332
		foreach($t as $k => $v) {
334
			if (strpos($k, ':') !== FALSE) {
333
			if (strpos($k, ':') !== FALSE) {
335
				$ret[] = "$v AS \"$k\"";
334
				$ret[] = "$v AS \"$k\"";
336
			} else {
335
			} else {
337
				$ret[] = "$v AS $k";
336
				$ret[] = "$v AS $k";
338
			}
337
			}
339
		}
338
		}
340
		return implode(',',$ret);
339
		return implode(',',$ret);
341
	}
340
	}
342
 
341
 
343
	static function sqlAddJoins($params, $champs) {
342
	static function sqlAddJoins($params, $champs) {
344
		$j = '';
343
		$j = '';
345
		// ces tests doivent correspondre aux champs générés par sqlSelectFields()
344
		// ces tests doivent correspondre aux champs générés par sqlSelectFields()
346
		// ou contraintes générées par sqlAddConstraint()
345
		// ou contraintes générées par sqlAddConstraint()
347
		if(array_key_exists('masque.famille', $params) ||
346
		if(array_key_exists('masque.famille', $params) ||
348
		   array_key_exists('famille', $champs)) {
347
		   array_key_exists('famille', $champs)) {
349
			$j .= 'LEFT JOIN tb_eflore.bdtfx_v1_02 b ON c.flore_bdtfx_nn = b.num_nom';
348
			$j .= 'LEFT JOIN tb_eflore.bdtfx_v1_02 b ON c.flore_bdtfx_nn = b.num_nom';
350
		}
349
		}
351
 
350
 
352
		return $j;
351
		return $j;
353
	}
352
	}
354
 
353
 
355
	// d'un tableau de type array("coste:nn", "type_epithete")
354
	// d'un tableau de type array("coste:nn", "type_epithete")
356
	// retourne
355
	// retourne
357
	// un tableau de type array("coste:nn" => "c.num_nom", "type_epithete" => "c.type_epithete")
356
	// un tableau de type array("coste:nn" => "c.num_nom", "type_epithete" => "c.type_epithete")
358
	// basé sur self::$allow_champs
357
	// basé sur self::$allow_champs
359
	static function addSQLToFieldSynonym(Array $syno) {
358
	static function addSQLToFieldSynonym(Array $syno) {
360
		return array_intersect_key(self::$allow_champs, array_flip($syno));
359
		return array_intersect_key(self::$allow_champs, array_flip($syno));
361
	}
360
	}
362
 
361
 
363
	// request handler
362
	// request handler
364
	static function requestParse(&$ressource, &$params) {
363
	static function requestParse(&$ressource, &$params) {
365
		$uri = explode('/', $_SERVER['REDIRECT_URL']);
364
		$uri = explode('/', $_SERVER['REDIRECT_URL']);
366
		if(!empty($_SERVER['QUERY_STRING']))
365
		if(!empty($_SERVER['QUERY_STRING']))
367
			parse_str($_SERVER['REDIRECT_QUERY_STRING'], $params);
366
			parse_str($_SERVER['REDIRECT_QUERY_STRING'], $params);
368
		$ressource = array_slice($uri, array_search('textes', $uri) + 1, 3);
367
		$ressource = array_slice($uri, array_search('textes', $uri) + 1, 3);
369
	}
368
	}
370
 
369
 
371
	// supprime l'index du tableau des paramètres si sa valeur ne correspond pas
370
	// supprime l'index du tableau des paramètres si sa valeur ne correspond pas
372
	// au spectre passé par $values.
371
	// au spectre passé par $values.
373
	static function unsetIfInvalid(&$var, $index, $values) {
372
	static function unsetIfInvalid(&$var, $index, $values) {
374
		if(array_key_exists($index, $var) && !in_array($var[$index], $values))
373
		if(array_key_exists($index, $var) && !in_array($var[$index], $values))
375
			unset($var[$index]);
374
			unset($var[$index]);
376
	}
375
	}
377
 
376
 
378
	static function requestFilterParams(Array $params) {
377
	static function requestFilterParams(Array $params) {
379
		$p = array_intersect_key($params, array_flip(self::$allow_params));
378
		$p = array_intersect_key($params, array_flip(self::$allow_params));
380
		self::unsetIfInvalid($p, 'txt.format', array('txt', 'htm'));
379
		self::unsetIfInvalid($p, 'txt.format', array('txt', 'htm'));
381
		self::unsetIfInvalid($p, 'retour.format', array('min','max'));
380
		self::unsetIfInvalid($p, 'retour.format', array('min','max'));
382
		self::unsetIfInvalid($p, 'retour.indexBy', array('coste', 'bdtfx'));
381
		self::unsetIfInvalid($p, 'retour.indexBy', array('coste', 'bdtfx'));
383
		self::unsetIfInvalid($p, 'recherche', array('stricte','etendue','floue'));
382
		self::unsetIfInvalid($p, 'recherche', array('stricte','etendue','floue'));
384
 
383
 
385
		if(isset($params['masque.ns'])) $p['masque.ns'] = trim($params['masque.ns']);
384
		if(isset($params['masque.ns'])) $p['masque.ns'] = trim($params['masque.ns']);
386
		if(isset($params['masque.texte'])) $p['masque.texte'] = trim($params['masque.texte']);
385
		if(isset($params['masque.texte'])) $p['masque.texte'] = trim($params['masque.texte']);
387
 
386
 
388
		if(isset($params['masque.famille'])) {
387
		if(isset($params['masque.famille'])) {
389
			// mysql -N<<<"SELECT DISTINCT famille FROM bdtfx_v1_02;"|sed -r "s/(.)/\1\n/g"|sort -u|tr -d "\n"
388
			// mysql -N<<<"SELECT DISTINCT famille FROM bdtfx_v1_02;"|sed -r "s/(.)/\1\n/g"|sort -u|tr -d "\n"
390
			$p['masque.famille'] = preg_replace('/[^a-zA-Z %_]/', '', iconv("UTF-8",
389
			$p['masque.famille'] = preg_replace('/[^a-zA-Z %_]/', '', iconv("UTF-8",
391
																			"ASCII//TRANSLIT",
390
																			"ASCII//TRANSLIT",
392
																			$params['masque.famille']));
391
																			$params['masque.famille']));
393
		}
392
		}
394
 
393
 
395
		// TODO: use filter_input(INPUT_GET);
394
		// TODO: use filter_input(INPUT_GET);
396
		// renvoie FALSE ou NULL si absent ou invalide
395
		// renvoie FALSE ou NULL si absent ou invalide
397
		$p['navigation.limite'] = filter_var(@$params['navigation.limite'],
396
		$p['navigation.limite'] = filter_var(@$params['navigation.limite'],
398
			FILTER_VALIDATE_INT,
397
			FILTER_VALIDATE_INT,
399
			array('options' => array(
398
			array('options' => array(
400
				'default' => NULL,
399
				'default' => NULL,
401
				'min_range' => 1,
400
				'min_range' => 1,
402
				'max_range' => _COSTE_TEXTE_MAX_RESULT_LIMIT)));
401
				'max_range' => _COSTE_TEXTE_MAX_RESULT_LIMIT)));
403
		$p['navigation.depart'] = filter_var(@$params['navigation.depart'],
402
		$p['navigation.depart'] = filter_var(@$params['navigation.depart'],
404
			FILTER_VALIDATE_INT,
403
			FILTER_VALIDATE_INT,
405
			array('options' => array(
404
			array('options' => array(
406
				'default' => NULL,
405
				'default' => NULL,
407
				'min_range' => 0,
406
				'min_range' => 0,
408
				'max_range' => _COSTE_TEXTE_MAX_COSTE_NN)));
407
				'max_range' => _COSTE_TEXTE_MAX_COSTE_NN)));
409
		$p['masque.page'] = filter_var(@$params['masque.page'],
408
		$p['masque.page'] = filter_var(@$params['masque.page'],
410
			FILTER_VALIDATE_INT,
409
			FILTER_VALIDATE_INT,
411
			array('options' => array(
410
			array('options' => array(
412
				'default' => NULL,
411
				'default' => NULL,
413
				'min_range' => 0,
412
				'min_range' => 0,
414
				'max_range' => _COSTE_TEXTE_MAX_COSTE_PAGE)));
413
				'max_range' => _COSTE_TEXTE_MAX_COSTE_PAGE)));
415
		$p['masque.tome'] = filter_var(@$params['masque.tome'],
414
		$p['masque.tome'] = filter_var(@$params['masque.tome'],
416
			FILTER_VALIDATE_INT,
415
			FILTER_VALIDATE_INT,
417
			array('options' => array(
416
			array('options' => array(
418
				'default' => NULL,
417
				'default' => NULL,
419
				'min_range' => 0,
418
				'min_range' => 0,
420
				'max_range' => _COSTE_TEXTE_MAX_COSTE_TOME)));
419
				'max_range' => _COSTE_TEXTE_MAX_COSTE_TOME)));
421
		$p['masque.nt'] = filter_var(@$params['masque.nt'],
420
		$p['masque.nt'] = filter_var(@$params['masque.nt'],
422
			FILTER_VALIDATE_INT,
421
			FILTER_VALIDATE_INT,
423
			array('options' => array(
422
			array('options' => array(
424
				'default' => NULL,
423
				'default' => NULL,
425
				'min_range' => 0,
424
				'min_range' => 0,
426
				'max_range' => _COSTE_TEXTE_MAX_BDTFX_NT)));
425
				'max_range' => _COSTE_TEXTE_MAX_BDTFX_NT)));
427
 
426
 
428
		// on filtre les NULL, FALSE et '', mais pas les 0, d'où le callback()
427
		// on filtre les NULL, FALSE et '', mais pas les 0, d'où le callback()
429
		// TODO: PHP-5.3
428
		// TODO: PHP-5.3
430
		$p = array_filter($p, create_function('$a','return !in_array($a, array("",false,null),true);'));
429
		$p = array_filter($p, create_function('$a','return !in_array($a, array("",false,null),true);'));
431
		$p = array_merge(self::$default_params, $p);
430
		$p = array_merge(self::$default_params, $p);
432
 
431
 
433
		return $p;
432
		return $p;
434
	}
433
	}
435
 
434
 
436
	static function requestFilterIds($uri) {
435
	static function requestFilterIds($uri) {
437
		if(count($uri) != 1) return NULL;
436
		if(count($uri) != 1) return NULL;
438
 
437
 
439
		// getNN* renvoient le num_nom passé comme segment d'URI:
438
		// getNN* renvoient le num_nom passé comme segment d'URI:
440
		// - soit un id selon coste (num_nom dans coste_v2_00)
439
		// - soit un id selon coste (num_nom dans coste_v2_00)
441
		// - soit un id selon bdtfx (num_nom dans bdtfx_v1_02)
440
		// - soit un id selon bdtfx (num_nom dans bdtfx_v1_02)
442
		// ou bien l'extrait du pattern bdtfx.nn:(#id)
441
		// ou bien l'extrait du pattern bdtfx.nn:(#id)
443
		$ids_coste = array_filter(array_map(array(__CLASS__, 'getNNCoste'), explode(',', $uri[0])));
442
		$ids_coste = array_filter(array_map(array(__CLASS__, 'getNNCoste'), explode(',', $uri[0])));
444
		$ids_bdtfx = array_filter(array_map(array(__CLASS__, 'getNNBdtfx'), explode(',', $uri[0])));
443
		$ids_bdtfx = array_filter(array_map(array(__CLASS__, 'getNNBdtfx'), explode(',', $uri[0])));
445
 
444
 
446
		// en cas d'échec (tous les id sont invalides), bail-out
445
		// en cas d'échec (tous les id sont invalides), bail-out
447
		if(!$ids_bdtfx && !$ids_coste) {
446
		if(!$ids_bdtfx && !$ids_coste) {
448
			// http_response_code(500);
447
			// http_response_code(500);
449
			throw new Exception('not supported', 500);
448
			throw new Exception('not supported', 500);
450
		}
449
		}
451
 
450
 
452
		return array(
451
		return array(
453
			'coste' => array_slice($ids_coste, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) ),
452
			'coste' => array_slice($ids_coste, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) ),
454
			'bdtfx' => array_slice($ids_bdtfx, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) )
453
			'bdtfx' => array_slice($ids_bdtfx, 0, intval(_COSTE_TEXTE_MAX_RESULT_LIMIT / 2) )
455
		);
454
		);
456
	}
455
	}
457
 
456
 
458
	static function aide() {
457
	static function aide() {
459
		header("Content-Type: text/plain; charset=utf-8");
458
		header("Content-Type: text/plain; charset=utf-8");
460
		return sprintf("
-
 
461
Service coste/textes:
459
		return sprintf("Service coste/textes:
-
 
460
 
462
Retourne des informations (choisies) à propos d'un taxon donné (à partir de son numéro nomenclatural
461
Retourne des informations (choisies) à propos d'un taxon donné (à partir de son numéro nomenclatural
463
Retourne des informations (choisies) à propos de taxons recherchés (à partir de divers critères)
462
Retourne des informations (choisies) à propos de taxons recherchés (à partir de divers critères)
464
Les résultats sont indexés. La clef par défaut est le num_nom d'après coste (attribut \"coste:nn\")
463
Les résultats sont indexés. La clef par défaut est le num_nom d'après coste (attribut \"coste:nn\")
465
Usage:
-
 
466
			coste/textes/<liste-num_nom>?<params>
464
Usage:  coste/textes[/<liste-num_nom>]?<params>
-
 
465
 
467
* le paramètre \"retour.indexBy\" affecte le mode d'indexation (\"bdtfx\" ou \"coste\" (defaut))
466
* le paramètre \"retour.indexBy\" affecte le mode d'indexation (\"bdtfx\" ou \"coste\" (defaut))
468
* <liste-num_nom> étant une liste de numéros nomenclaturaux de taxons séparés par des virgules au format:
467
* <liste-num_nom> étant une liste de numéros nomenclaturaux de taxons séparés par des virgules au format:
469
 - <#id>: un numéro nomenclatural dans la base coste
468
 - <#id>: un numéro nomenclatural dans la base coste
470
 - <bdtfx.nn:#id>: un numéro nomenclatural dans la base bdtfx
469
 - <bdtfx.nn:#id>: un numéro nomenclatural dans la base bdtfx
471
* retour.champs une liste de champs séparés par des virgules parmi *,%s
470
* retour.champs une liste de champs séparés par des virgules parmi *,%s
472
* les paramètres acceptés sont les suivants: %s
471
* les paramètres acceptés sont les suivants: %s
473
* les champs retournés par défaut sont les suivants: %s
472
* les champs retournés par défaut sont les suivants: %s
474
* le paramètre \"recherche\" affecte les masques \"ns\" et \"texte\"
473
* le paramètre \"recherche\" affecte les masques \"ns\" et \"texte\"
475
* le paramètre \"famille\" est traité via LIKE et accepte les caractères '_' et '%'
474
* le paramètre \"famille\" est traité via LIKE et accepte les caractères '_' et '%%'
476
* le paramètre \"retour.format\" est inutilisé pour l'instant",
475
* le paramètre \"retour.format\" est inutilisé pour l'instant.
-
 
476
 
-
 
477
Exemples:
-
 
478
/service:eflore:0.1/coste/textes/bdtfx.nn:182?retour.champs=titre
-
 
479
	# retourne l'Acer monspessulanum
-
 
480
/service:eflore:0.1/coste/textes/182?retour.champs=titre
-
 
481
	# retourne la Roemeria violacea (bdtfx:nn = 56272)
-
 
482
/service:eflore:0.1/coste/textes/182,bdtfx.nn:182?retour.champs=titre
-
 
483
	# retourne les deux précédents
-
 
484
/service:eflore:0.1/coste/textes?masque.titre=Cla001Thalamiflores&retour.champs=titre
-
 
485
	# retourne la section de Coste relatives aux Thalamiflores
-
 
486
/service:eflore:0.1/coste/textes?masque.titre=Thalamiflores&recherche=floue&retour.champs=titre
-
 
487
	# idem, en utilisant une recherche floue
-
 
488
/service:eflore:0.1/coste/textes?masque.titre=Cla001Thalamiflores&retour.champs=titre&retour.indexBy=bdtfx
-
 
489
	# retourne une erreur de format car cette section de coste n'est associée à aucun taxon de la BDTFX
-
 
490
",
477
			implode(',', array_keys(self::$allow_champs)),
491
			implode(',', array_keys(self::$allow_champs)),
478
			implode(',', self::$allow_params),
492
			implode(',', self::$allow_params),
479
			self::$default_params['retour.champs']
493
			self::$default_params['retour.champs']
480
		);
494
		);
481
	}
495
	}
482
 
496
 
483
	static function getNNCoste($refnn) {
497
	static function getNNCoste($refnn) {
484
		if (is_numeric($refnn)) {
498
		if (is_numeric($refnn)) {
485
			$t = intval($refnn);
499
			$t = intval($refnn);
486
			if ($t >= 1 && $t < _COSTE_TEXTE_MAX_COSTE_NN) return $t;
500
			if ($t >= 1 && $t < _COSTE_TEXTE_MAX_COSTE_NN) return $t;
487
		}
501
		}
488
		return FALSE;
502
		return FALSE;
489
	}
503
	}
490
 
504
 
491
	static function getNNBdtfx($refnn) {
505
	static function getNNBdtfx($refnn) {
492
		if(strpos($refnn, 'bdtfx.nn:') !== 0) return FALSE;
506
		if(strpos($refnn, 'bdtfx.nn:') !== 0) return FALSE;
493
		$t = intval(str_replace('bdtfx.nn:', '', $refnn));
507
		$t = intval(str_replace('bdtfx.nn:', '', $refnn));
494
		if($t >= 1 && $t < _COSTE_TEXTE_MAX_BDTFX_NN) return $t;
508
		if($t >= 1 && $t < _COSTE_TEXTE_MAX_BDTFX_NN) return $t;
495
		return FALSE;
509
		return FALSE;
496
	}
510
	}
497
}
511
}