Rev 1308 | Rev 1311 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/** @copyright 2013 Tela Botanica (accueil@tela-botanica.org)* @author Raphaël Droz <raphael@tela-botanica.org>* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>** pattern: /service:eflore:0.1/coste/textes/bdtfx.nn:182,631* params: txt.format=(htm|txt) , retour.champs=(titre,texte,...) , retour.format=(min|max), ...** Ce webservice est censé pouvoir:* 1) retourner des informations (choisies) à propos d'un ou plusieurs taxon(s) donné(s)* (à partir de son numéro nomenclatural* 2) retourner des informations (choisies) à propos de taxons recherchés* (à partir de divers critères)** TODO: masque.titre => masque.tag* TODO: clarifier l'attribut "tag" retourné (tag de la description ou des clefs de détermination)**//* restore_error_handler();error_reporting(E_ALL); */class Textes {private $plantuseurl = 'https://uses.plantnet-project.org/f/api.php?section=0&action=parse&format=json&prop=wikitext&disabletoc=1&disableeditsection=1&disablelimitreport=1&page=';private $parametres = array();private $ressources = array();private $Bdd;private $format = 'min';private $retour_mime = 'application/json';private $nbreTextes = '0';public function __construct(Bdd $bdd = null, Array $config = null) {$this->config = is_null($config) ? Config::get('Textes') : $config;$this->Bdd = is_null($bdd) ? new Bdd() : $bdd;}public function consulter($ressources, $parametres) {$this->parametres = $parametres;$this->ressources = $ressources;$this->definirValeurParDefautDesParametres();$this->format = (isset($this->parametres['retour.format']) && $this->parametres['retour.format'] != '') ? $this->parametres['retour.format'] : $this->format;$this->retour_mime = (isset($this->parametres['retour']) && $this->parametres['retour'] != '') ? $this->parametres['retour'] : $this->retour_mime;$textes = $this->obtenirTextes();$this->nbreTextes = count($textes);$textes_formatees = $this->formaterRetourJson($textes);$resultat = $textes_formatees;$entete = $this->construireEntete();return array('entete' => $entete, 'resultats' => $resultat);}private function construireEntete() {$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0);$entete['masque'] = $this->recupererMasque();$entete['depart'] = (int) $this->parametres['navigation.depart'];$entete['limite'] = (int) $this->parametres['navigation.limite'];$entete['total'] = $this->nbreTextes;return $entete;}private function recupererMasque() {$masqueEntete = '';foreach ($this->parametres as $param => $cle) {if ($param == 'masque') {$masqueEntete = 'masque='.$cle.',';} elseif (substr($param, 0, 7) == 'masque.') {$masqueEntete .= substr($param, 7).'='.$cle.',';}}$masqueEntete = rtrim($masqueEntete,',');return $masqueEntete;}private function definirValeurParDefautDesParametres() {if (isset($this->parametres['retour']) == false) {$this->parametres['retour'] = self::MIME_JSON;}if (isset($this->parametres['retour.format']) == false) {$this->parametres['retour.format'] = 'min';}if (isset($this->parametres['navigation.depart']) == false) {$this->parametres['navigation.depart'] = 0;}if (isset($this->parametres['navigation.limite']) == false) {$this->parametres['navigation.limite'] = 100;}}private function obtenirTextes() {$retour = "";$json = file_gets_content($this->plantuseurl.$this->parametres['masque']);if ($json != false) {$tableau = json_decode($json);if (isset($tableau['parse']['wikitext']['*'])) {$texte = $tableau['parse']['wikitext']['*'];$retour = substr($texte, strpos($texte, "{{Encadré\n|color=lightgreen\n|titre=Résumé des usages\n|texte="+62, -2), 0);}}return $retour;}}