| Line 21... |
Line 21... |
| 21 |
|
21 |
|
| 22 |
|
22 |
|
| 23 |
/* restore_error_handler();
|
23 |
/* restore_error_handler();
|
| - |
|
24 |
error_reporting(E_ALL); */
|
| - |
|
25 |
class Textes {
|
| 24 |
error_reporting(E_ALL); */
|
26 |
|
| 25 |
class Textes {
|
27 |
const MIME_JSON = 'application/json';
|
| Line 26... |
Line 28... |
| 26 |
private $plantuseurl = 'https://uses.plantnet-project.org/f/api.php?section=0&action=parse&format=json
|
28 |
private $plantuseurl = 'https://uses.plantnet-project.org/f/api.php?section=0&action=parse&format=json'.
|
| 27 |
&prop=wikitext&disabletoc=1&disableeditsection=1&disablelimitreport=1&page=';
|
29 |
'&prop=wikitext&disabletoc=1&disableeditsection=1&disablelimitreport=1&page=';
|
| 28 |
|
30 |
|
| Line 45... |
Line 47... |
| 45 |
|
47 |
|
| Line 46... |
Line 48... |
| 46 |
$this->definirValeurParDefautDesParametres();
|
48 |
$this->definirValeurParDefautDesParametres();
|
| 47 |
|
49 |
|
| 48 |
$this->format = (isset($this->parametres['retour.format']) && $this->parametres['retour.format'] != '') ? $this->parametres['retour.format'] : $this->format;
|
50 |
$this->format = (isset($this->parametres['retour.format']) && $this->parametres['retour.format'] != '') ? $this->parametres['retour.format'] : $this->format;
|
| 49 |
$this->retour_mime = (isset($this->parametres['retour']) && $this->parametres['retour'] != '') ? $this->parametres['retour'] : $this->retour_mime;
|
- |
|
| 50 |
$textes = $this->obtenirTextes();
|
- |
|
| 51 |
$this->nbreTextes = count($textes);
|
- |
|
| 52 |
$textes_formatees = $this->formaterRetourJson($textes);
|
51 |
$this->retour_mime = (isset($this->parametres['retour']) && $this->parametres['retour'] != '') ? $this->parametres['retour'] : $this->retour_mime;
|
| 53 |
$resultat = $textes_formatees;
|
52 |
$resultat = $this->obtenirTextes();
|
| Line 54... |
Line 53... |
| 54 |
$entete = $this->construireEntete();
|
53 |
$entete = $this->construireEntete();
|
| 55 |
return array('entete' => $entete, 'resultats' => $resultat);
|
54 |
return array('entete' => $entete, 'resultats' => $resultat);
|
| 56 |
|
55 |
|
| Line 57... |
Line 56... |
| 57 |
}
|
56 |
}
|
| 58 |
private function construireEntete() {
|
57 |
private function construireEntete() {
|
| 59 |
$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0);
|
58 |
$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0);
|
| 60 |
|
- |
|
| Line 61... |
Line 59... |
| 61 |
$entete['masque'] = $this->recupererMasque();
|
59 |
|
| 62 |
$entete['depart'] = (int) $this->parametres['navigation.depart'];
|
60 |
$entete['masque'] = $this->recupererMasque();
|
| Line 63... |
Line 61... |
| 63 |
$entete['limite'] = (int) $this->parametres['navigation.limite'];
|
61 |
$entete['depart'] = (int) $this->parametres['navigation.depart'];
|
| Line 94... |
Line 92... |
| 94 |
}
|
92 |
}
|
| 95 |
}
|
93 |
}
|
| Line 96... |
Line 94... |
| 96 |
|
94 |
|
| 97 |
private function obtenirTextes() {
|
95 |
private function obtenirTextes() {
|
| - |
|
96 |
$retour = "";
|
| - |
|
97 |
if ($this->parametres['masque'] != "") {
|
| 98 |
$retour = "";
|
98 |
$this->parametres['masque'] = str_replace(" ", "_", $this->parametres['masque']);
|
| 99 |
$json = file_gets_content($this->plantuseurl.$this->parametres['masque']);
|
99 |
$json = file_get_contents($this->plantuseurl.$this->parametres['masque']);
|
| 100 |
if ($json != false) {
|
100 |
if ($json != false) {
|
| 101 |
$tableau = json_decode($json);
|
101 |
$tableau = json_decode($json, TRUE);
|
| 102 |
if (isset($tableau['parse']['wikitext']['*'])) {
|
102 |
if (isset($tableau['parse']['wikitext']['*'])) {
|
| 103 |
$texte = $tableau['parse']['wikitext']['*'];
|
103 |
$texte = $tableau['parse']['wikitext']['*'];
|
| 104 |
$retour = substr($texte, strpos($texte, "{{Encadré\n|color=lightgreen\n|titre=Résumé des usages\n|texte="+62, -2), 0);
|
104 |
$retour = substr($texte, strpos($texte, "{{Encadré\n|color=lightgreen\n|titre=Résumé des usages\n|texte="+63), -2);
|
| - |
|
105 |
|
| 105 |
|
106 |
}
|
| 106 |
}
|
107 |
}
|
| 107 |
}
|
108 |
}
|
| 108 |
return $retour;
|
109 |
return $retour;
|
| 109 |
}
|
110 |
}
|