Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 853 Rev 965
Line 134... Line 134...
134
		$xml='<?xml version="1.0" ?><TAXONS SUBJECT="XML">';
134
		$xml='<?xml version="1.0" ?><TAXONS SUBJECT="XML">';
135
		$rest = new RestClient();
135
		$rest = new RestClient();
136
		foreach ($this->contenu_fichier as $id=>$taxon) {
136
		foreach ($this->contenu_fichier as $id=>$taxon) {
137
			$infos_taxon = $this->rechercherInfosTaxon($rest, $taxon[$criteres_label["nom scientifique"]]);
137
			$infos_taxon = $this->rechercherInfosTaxon($rest, $taxon[$criteres_label["nom scientifique"]]);
138
			$xml .= '<TAXON id="'.$id.'" value="'.
138
			$xml .= '<TAXON id="'.$id.'" value="'.
139
				ucfirst($taxon[$criteres_label["nom vernaculaire"]]).'" sciName="'.$taxon[$criteres_label["nom scientifique"]].'" groupe="1">
139
				ucfirst($taxon[$criteres_label["nom vernaculaire"]]).'" sciName="'.trim($taxon[$criteres_label["nom scientifique"]]).'" groupe="1">
140
			<DESCRIPTION>'.$infos_taxon["description"].'</DESCRIPTION>
140
			<DESCRIPTION>'.$infos_taxon["description"].'</DESCRIPTION>
141
			<PICTURES>';
141
			<PICTURES>';
142
			if ($infos_taxon["images"] != array()) {
142
			if ($infos_taxon["images"] != array()) {
143
				foreach ($infos_taxon["images"] as $image) {
143
				foreach ($infos_taxon["images"] as $image) {
144
					$xml .= '<PICTURE media="'.$image["binaire.href"].'"><author>'.$image["auteur.libelle"].'</author></PICTURE>';
144
					$xml .= '<PICTURE media="'.$image["binaire.href"].'"><author>'.$image["auteur.libelle"].'</author></PICTURE>';
Line 156... Line 156...
156
		return $xml;
156
		return $xml;
157
	}
157
	}
Line 158... Line 158...
158
	
158
	
159
	private function rechercherInfosTaxon($rest, $ns) {
159
	private function rechercherInfosTaxon($rest, $ns) {
-
 
160
		$info = array("description" => "", "images" => array());
160
		$info = array("description" => "", "images" => array());
161
		
-
 
162
		$reponse = $this->consulterWebService($rest, "bdtfx", 
161
		$reponse = $this->consulterWebService($rest, "bdtfx", "taxons", "?masque=".urlencode(rtrim($ns)));
163
			"noms", "?retour.champs=nom_retenu.id,num_taxonomique&retour.tri=retenu&masque=".urlencode(trim($ns)));
-
 
164
		if (is_array($reponse["resultat"])) {
-
 
165
			$num_nom = $reponse["resultat"][key($reponse["resultat"])]["nom_retenu.id"];
-
 
166
			$num_taxon = $reponse["resultat"][key($reponse["resultat"])]['num_taxonomique'];
-
 
167
		}
-
 
168
		
-
 
169
		$url_wiki = "http://www.tela-botanica.org/wikini/eFloreRedaction/api/rest/0.5/pages/SmartFloreBDTFXnt".
-
 
170
					$num_taxon."?txt.format=text/plain&txt.section.titre=Comment%20la%20reconnaître%20%3F";
162
		if (is_array($reponse["resultat"])) {
171
		$wiki = $rest->consulter($url_wiki); $wiki = json_decode($wiki, true);
-
 
172
		if ($wiki['texte'] != ""){
163
			$id = key($reponse["resultat"]);
173
			$info["description"] = $this->formaterSmatflore($wiki['texte']);
164
		} else {
174
		} else {
165
			$reponse = $this->consulterWebService($rest, "bdtfx", "noms", "?retour.champs=nom_retenu.id&masque=".urlencode(rtrim($ns)));
175
			$coste = $this->consulterWebService($rest, "coste", "textes", "/bdtfx.nn:".$num_nom);
166
			if (is_array($reponse["resultat"])) {
176
			if ($coste['resultats'] != array() && $coste['resultats'][key($coste["resultats"])]['texte'] != "") {
-
 
177
				$texte = str_replace("**", "", $coste['resultats'][key($coste["resultats"])]['texte']);
-
 
178
				$texte = str_replace("//", "", $texte);
-
 
179
				$texte = explode(" – ", $texte);
-
 
180
				unset($texte[0],$texte[1]);
-
 
181
				if (strpos($texte[2], ";") === false) {unset($texte[2]);} //else {print_r($texte[2]);}
-
 
182
				
-
 
183
				if (preg_match('/^[\w|\s|\-|,]*\.*\s*$/', $texte[2]) == true) {print_r($texte[2]); unset($texte[2]);}
-
 
184
				$info["description"] = implode(" – ", $texte);
-
 
185
			} else {
-
 
186
				$baseflor = $this->consulterWebService($rest, "baseflor", "informations", "/bdtfx.nn:".$num_nom);
167
				$id = $reponse["resultat"][key($reponse["resultat"])]["nom_retenu.id"];
187
				$info["description"] = $this->formaterBaseflor($baseflor);
168
			}
188
			}
169
		}
-
 
170
		$reponse = $this->consulterWebService($rest, "coste", "textes", "/bdtfx.nn:".$id);
-
 
171
		if ($reponse['texte'] != ""){
-
 
172
			$texte = str_replace("**", "", $reponse['texte']);
-
 
173
			$texte = str_replace("//", "", $texte);
-
 
174
			$texte = explode(" – ", $texte);
-
 
175
			unset($texte[0],$texte[1]);
-
 
176
			if (strpos($texte[2], ";") === false) {unset($texte[2]);} else {print_r($texte[2]);}
-
 
177
			
-
 
178
			if (preg_match('/^[\w|\s|\-|,]*\.*\s*$/', $texte[2]) == true) {print_r($texte[2]); unset($texte[2]);}
189
		}
179
			$info["description"] = implode(" – ", $texte);
190
		if ($info["description"] == "En cours de rédaction.") {echo $num_nom." ".$ns;
180
		} else {
-
 
181
			$reponse = $this->consulterWebService($rest, "baseflor", "informations", "/bdtfx.nn:".$id);
-
 
182
			$info["description"] = $this->formaterBaseflor($reponse);
191
			print_r($coste);
183
		}
192
		}
184
		$reponse = $this->consulterWebService($rest, "cel", "images", "?navigation.limite=5&retour.format=CRS&masque.nn=".$id);
193
		$reponse = $this->consulterWebService($rest, "cel", "images", "?navigation.limite=5&retour.format=CRS&masque.nn=".$num_nom);
185
		$info["images"] = $reponse["resultats"];
194
		$info["images"] = $reponse["resultats"];
186
		return $info;
195
		return $info;
Line -... Line 196...
-
 
196
	}
-
 
197
	
-
 
198
			
-
 
199
 
-
 
200
	private function formaterSmatflore($texte) {
-
 
201
		$a_enlever = array(Chr(10).'=', '='.Chr(10), Chr(10).''.Chr(10));
-
 
202
		$texte = str_replace($a_enlever, '', $texte);
-
 
203
		$texte = str_replace(Chr(10), '<br />', $texte);
-
 
204
		return $texte;
187
	}
205
	}
188
	
206
	
189
	private function formaterBaseflor($reponse) {
207
	private function formaterBaseflor($reponse) {
190
		$description = "En cours de rédaction.";
208
		$description = "En cours de rédaction.";
191
		if ($reponse["idiotaxon"] != "") {
209
		if ($reponse["nom_sci"] != "") {
192
			$description = "Formation végétale : ".$reponse["form_vegetale"]."; ".
210
			$description = "Formation végétale : ".$reponse["form_vegetale"]."; ".
193
							"Inflorescence : ".$reponse["inflorescence"]."; ".
211
							"Inflorescence : ".$reponse["inflorescence"]."; ".
194
							"Couleur de la fleur : ".$reponse["couleur_fleur"]."; ".
212
							"Couleur de la fleur : ".$reponse["couleur_fleur"]."; ".