Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 1307 → Rev 1308

/trunk/services/modules/0.1/plantuse/Textes.php
New file
0,0 → 1,95
<?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?action=parse&format=json
&section=0&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 obtenirTextes() {
$retour = "";
$json = file_gets_content($this->plantuseurl.$this->parametres['retour.format']);
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;
}
}
/trunk/services/configurations/config.defaut.ini
78,7 → 78,7
; +------------------------------------------------------------------------------------------------------+
; Infos sur les projets
; Liste des projets disponibles
projetsDispo = "bdtre,lbf,sophy,apd,sptba,nvps,bdnt,bdtfx,bdtxa,chorodep,coste,eflore,fournier,insee-d,iso-3166-1,iso-639-1,nvjfl,cel,lion1906,wikipedia,osm,prometheus,bibliobota,photoflora,baseflor,baseveg,sptb,isfan,nva,moissonnage,nasa-srtm,coord-transfo,liste-rouge"
projetsDispo = "plantuse,bdtre,lbf,sophy,apd,sptba,nvps,bdnt,bdtfx,bdtxa,chorodep,coste,eflore,fournier,insee-d,iso-3166-1,iso-639-1,nvjfl,cel,lion1906,wikipedia,osm,prometheus,bibliobota,photoflora,baseflor,baseveg,sptb,isfan,nva,moissonnage,nasa-srtm,coord-transfo,liste-rouge"
 
; +------------------------------------------------------------------------------------------------------+
; Infos sur le cache