| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| 2 |
class Wiki {
|
2 |
class Wiki {
|
| 3 |
|
- |
|
| 4 |
const URL_WIKI = 'http://www.tela-botanica.org/wikini/florecoste/api/rest/0.5/pages';
|
- |
|
| 5 |
const URL_WIKI_EFLORE = 'http://www.tela-botanica.org/wikini/Coste/api/rest/0.5/pages';
|
- |
|
| 6 |
const DOSSIER_V2 = '../../../donnees/coste/2.00/';
|
3 |
const DOSSIER_V2 = '../../../donnees/coste/2.00/';
|
| 7 |
const DOSSIER_DSC_TXT = '../../../donnees/coste/descriptions/txt/';
|
4 |
const DOSSIER_DSC_TXT = '../../../donnees/coste/descriptions/txt/';
|
| Line -... |
Line 5... |
| - |
|
5 |
|
| - |
|
6 |
private $URL_WIKI = '';
|
| 8 |
|
7 |
private $URL_WIKI_EFLORE = '';
|
| 9 |
private $conteneur = null;
|
8 |
private $conteneur = null;
|
| 10 |
private $outils = null;
|
9 |
private $outils = null;
|
| 11 |
private $messages = null;
|
10 |
private $messages = null;
|
| 12 |
private $restClient = null;
|
11 |
private $restClient = null;
|
| 13 |
private $dossierBase = '';
|
12 |
private $dossierBase = '';
|
| Line 14... |
Line 13... |
| 14 |
private $index = array();
|
13 |
private $index = array();
|
| 15 |
|
14 |
|
| 16 |
public function __construct(Conteneur $conteneur) {
|
15 |
public function __construct(Conteneur $conteneur) {
|
| 17 |
mb_internal_encoding('UTF-8');
|
16 |
mb_internal_encoding('UTF-8');
|
| - |
|
17 |
setlocale(LC_ALL, 'fr_FR.UTF-8');
|
| - |
|
18 |
$this->conteneur = $conteneur;
|
| 18 |
setlocale(LC_ALL, 'fr_FR.UTF-8');
|
19 |
$this->URL_WIKI = $this->conteneur->getParametre('wiki.travail');
|
| 19 |
$this->conteneur = $conteneur;
|
20 |
$this->URL_WIKI_EFLORE = $this->conteneur->getParametre('wiki.eflore');
|
| 20 |
$this->outils = $conteneur->getOutils();
|
21 |
$this->outils = $conteneur->getOutils();
|
| 21 |
$this->messages = $conteneur->getMessages();
|
22 |
$this->messages = $conteneur->getMessages();
|
| 22 |
$this->restClient = $conteneur->getRestClient();
|
23 |
$this->restClient = $conteneur->getRestClient();
|
| Line 31... |
Line 32... |
| 31 |
if (isset($envoyes[$tag]) == false && preg_match('/^Esp([0-9]{4})/', $tag, $match)) {
|
32 |
if (isset($envoyes[$tag]) == false && preg_match('/^Esp([0-9]{4})/', $tag, $match)) {
|
| 32 |
$fichier = $this->dossierBase.self::DOSSIER_DSC_TXT.$match[1].'.txt';
|
33 |
$fichier = $this->dossierBase.self::DOSSIER_DSC_TXT.$match[1].'.txt';
|
| 33 |
if (file_exists($fichier) === true) {
|
34 |
if (file_exists($fichier) === true) {
|
| 34 |
$txt = file_get_contents($fichier);
|
35 |
$txt = file_get_contents($fichier);
|
| 35 |
$donnees = array('pageTag' => $tag, 'pageContenu' => $txt);
|
36 |
$donnees = array('pageTag' => $tag, 'pageContenu' => $txt);
|
| 36 |
$this->restClient->ajouter(self::URL_WIKI, $donnees);
|
37 |
$this->restClient->ajouter($this->URL_WIKI, $donnees);
|
| 37 |
$envoyes[$tag] = 'OK';
|
38 |
$envoyes[$tag] = 'OK';
|
| 38 |
} else {
|
39 |
} else {
|
| 39 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
40 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
| 40 |
}
|
41 |
}
|
| 41 |
}
|
42 |
}
|
| Line 49... |
Line 50... |
| 49 |
$envoyes = array();
|
50 |
$envoyes = array();
|
| 50 |
foreach ($this->index as $nom) {
|
51 |
foreach ($this->index as $nom) {
|
| 51 |
$tagDsc = $nom['page_wiki_dsc'];
|
52 |
$tagDsc = $nom['page_wiki_dsc'];
|
| 52 |
$tagCle = $nom['page_wiki_cle'];
|
53 |
$tagCle = $nom['page_wiki_cle'];
|
| 53 |
if (isset($envoyes[$tagDsc]) == false) {
|
54 |
if (isset($envoyes[$tagDsc]) == false) {
|
| 54 |
$url = self::URL_WIKI.'/'.$tagDsc;
|
55 |
$url = $this->URL_WIKI.'/'.$tagDsc;
|
| 55 |
$txt = $this->telechargerTxt($url);
|
56 |
$txt = $this->telechargerTxt($url);
|
| 56 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'/dsc/'.$tagDsc.'.txt';
|
57 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'dsc/'.$tagDsc.'.txt';
|
| 57 |
if (file_put_contents($fichier, $txt)) {
|
58 |
if (file_put_contents($fichier, $txt)) {
|
| 58 |
$envoyes[$tagDsc] = 'OK';
|
59 |
$envoyes[$tagDsc] = 'OK';
|
| 59 |
}
|
60 |
}
|
| 60 |
}
|
61 |
}
|
| 61 |
if (isset($envoyes[$tagCle]) == false) {
|
62 |
if (isset($envoyes[$tagCle]) == false) {
|
| 62 |
$url = self::URL_WIKI.'/'.$tagCle;
|
63 |
$url = $this->URL_WIKI.'/'.$tagCle;
|
| 63 |
$txt = $this->telechargerTxt($url);
|
64 |
$txt = $this->telechargerTxt($url);
|
| 64 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'/cle/'.$tagCle.'.txt';
|
65 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'cle/'.$tagCle.'.txt';
|
| 65 |
if (file_put_contents($fichier, $txt)) {
|
66 |
if (file_put_contents($fichier, $txt)) {
|
| 66 |
$envoyes[$tagCle] = 'OK';
|
67 |
$envoyes[$tagCle] = 'OK';
|
| 67 |
}
|
68 |
}
|
| 68 |
}
|
69 |
}
|
| 69 |
$this->messages->afficherAvancement("Download des fichiers en cours");
|
70 |
$this->messages->afficherAvancement("Download des fichiers en cours");
|
| Line 72... |
Line 73... |
| 72 |
}
|
73 |
}
|
| Line 73... |
Line 74... |
| 73 |
|
74 |
|
| 74 |
public function uploaderDansWikiEflore() {
|
75 |
public function uploaderDansWikiEflore() {
|
| 75 |
$this->chargerIndex();
|
76 |
$this->chargerIndex();
|
| - |
|
77 |
$envoyes = array();
|
| 76 |
$envoyes = array();
|
78 |
|
| 77 |
foreach ($this->index as $nom) {
|
79 |
foreach ($this->index as $nom) {
|
| 78 |
$tagDsc = $nom['page_wiki_dsc'];
|
80 |
$tagDsc = $nom['page_wiki_dsc'];
|
| 79 |
if (isset($envoyes[$tagDsc]) == false) {
|
81 |
if (isset($envoyes[$tagDsc]) == false) {
|
| 80 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'/dsc/'.$tagDsc.'.txt';
|
82 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'dsc/'.$tagDsc.'.txt';
|
| 81 |
if (file_exists($fichier) === true) {
|
83 |
if (file_exists($fichier) === true) {
|
| 82 |
$txt = file_get_contents($fichier);
|
84 |
$txt = file_get_contents($fichier);
|
| 83 |
$donnees = array('pageTag' => $tagDsc, 'pageContenu' => $txt);
|
- |
|
| 84 |
$this->restClient->ajouter(self::URL_WIKI_EFLORE, $donnees);
|
85 |
$this->envoyerPage($tagDsc, $txt);
|
| 85 |
$envoyes[$tagDsc] = 'OK';
|
86 |
$envoyes[$tagDsc] = 'OK';
|
| 86 |
} else {
|
87 |
} else {
|
| 87 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
88 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
| 88 |
}
|
89 |
}
|
| Line 89... |
Line 90... |
| 89 |
}
|
90 |
}
|
| 90 |
|
91 |
|
| 91 |
$tagCle = $nom['page_wiki_cle'];
|
92 |
$tagCle = $nom['page_wiki_cle'];
|
| 92 |
if (isset($envoyes[$tagCle]) == false) {
|
93 |
if (isset($envoyes[$tagCle]) == false) {
|
| 93 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'/cle/'.$tagCle.'.txt';
|
94 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'cle/'.$tagCle.'.txt';
|
| 94 |
if (file_exists($fichier) === true) {
|
- |
|
| 95 |
$txt = file_get_contents($fichier);
|
95 |
if (file_exists($fichier) === true) {
|
| 96 |
$donnees = array('pageTag' => $tagCle, 'pageContenu' => $txt);
|
96 |
$txt = file_get_contents($fichier);
|
| 97 |
$this->restClient->ajouter(self::URL_WIKI_EFLORE, $donnees);
|
97 |
$this->envoyerPage($tagDsc, $txt);
|
| 98 |
$envoyes[$tagCle] = 'OK';
|
98 |
$envoyes[$tagCle] = 'OK';
|
| 99 |
} else {
|
99 |
} else {
|
| 100 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
100 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
| 101 |
}
|
101 |
}
|
| 102 |
}
|
102 |
}
|
| 103 |
$this->messages->afficherAvancement("Upload des textes dans le wikini eFlore");
|
103 |
$this->messages->afficherAvancement("Upload des textes dans le wikini eFlore");
|
| 104 |
}
|
104 |
}
|
| Line -... |
Line 105... |
| - |
|
105 |
echo "\n";
|
| - |
|
106 |
}
|
| - |
|
107 |
|
| - |
|
108 |
public function uploaderIndexDansWikiEflore() {
|
| - |
|
109 |
$this->chargerIndex();
|
| - |
|
110 |
$envoyes = array();
|
| - |
|
111 |
$pageIndexFamille = "==Index Famille Coste==\n\n";
|
| - |
|
112 |
$pageIndexGenre = "==Index Genre Coste==\n\n";
|
| - |
|
113 |
$pageIndexEspece = "==Index Espèce Coste==\n\n";
|
| - |
|
114 |
foreach ($this->index as $nom) {
|
| - |
|
115 |
$indentation = $this->getIndentationTxtLien($nom);
|
| - |
|
116 |
$txtLien = $this->getTxtLienGenerique($nom);
|
| - |
|
117 |
|
| - |
|
118 |
$tagDsc = $nom['page_wiki_dsc'];
|
| - |
|
119 |
if (isset($envoyes[$tagDsc]) == false) {
|
| - |
|
120 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'dsc/'.$tagDsc.'.txt';
|
| - |
|
121 |
if (file_exists($fichier) === true) {
|
| - |
|
122 |
if ($nom['rang'] <= 180) {
|
| - |
|
123 |
$pageIndexFamille .= "$indentation- [[$tagDsc $txtLien]]\n";
|
| - |
|
124 |
} elseif ($nom['rang'] == 220) {
|
| - |
|
125 |
$pageIndexGenre .= "$indentation- [[$tagDsc $txtLien]]\n";
|
| - |
|
126 |
} else {
|
| - |
|
127 |
$pageIndexEspece .= "$indentation- [[$tagDsc $txtLien]]\n";
|
| - |
|
128 |
}
|
| - |
|
129 |
$envoyes[$tagDsc] = 'OK';
|
| - |
|
130 |
} else {
|
| - |
|
131 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
| - |
|
132 |
}
|
| - |
|
133 |
}
|
| - |
|
134 |
|
| - |
|
135 |
$tagCle = $nom['page_wiki_cle'];
|
| - |
|
136 |
if (isset($envoyes[$tagCle]) == false) {
|
| - |
|
137 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'cle/'.$tagCle.'.txt';
|
| - |
|
138 |
if (file_exists($fichier) === true) {
|
| - |
|
139 |
$indentation = $indentation.' ';
|
| - |
|
140 |
if ($nom['rang'] == 180) {
|
| - |
|
141 |
$pageIndexFamille = rtrim($pageIndexFamille, "\n");
|
| - |
|
142 |
$pageIndexFamille .= " - [[$tagCle Clé]]\n";
|
| - |
|
143 |
} elseif ($nom['rang'] == 220) {
|
| - |
|
144 |
$pageIndexGenre = rtrim($pageIndexGenre, "\n");
|
| - |
|
145 |
$pageIndexGenre .= " - [[$tagCle Clé]]\n";
|
| - |
|
146 |
}
|
| - |
|
147 |
$envoyes[$tagCle] = 'OK';
|
| - |
|
148 |
} else {
|
| - |
|
149 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
| - |
|
150 |
}
|
| - |
|
151 |
}
|
| - |
|
152 |
$this->messages->afficherAvancement("Upload des index dans le wikini eFlore");
|
| - |
|
153 |
}
|
| - |
|
154 |
$this->envoyerPage('IndexFamille', $pageIndexFamille);
|
| - |
|
155 |
$this->envoyerPage('IndexGenre', $pageIndexGenre);
|
| - |
|
156 |
$this->envoyerPage('IndexEspece', $pageIndexEspece);
|
| - |
|
157 |
echo "\n";
|
| - |
|
158 |
}
|
| - |
|
159 |
|
| - |
|
160 |
private function getIndentationTxtLien($nom) {
|
| - |
|
161 |
$rangs = array('Reg' => 1, 'Emb' => 2, 'Cla' => 3, 'Fam' => 4, 'Gen' => 5, 'Esp' => 6);
|
| - |
|
162 |
$indentation = '';
|
| - |
|
163 |
if (preg_match('/^(Reg|Emb|Cla|Fam|Gen|Esp)[0-9]+/', $nom['page_wiki_dsc'], $match)) {
|
| - |
|
164 |
$type = $match[1];
|
| - |
|
165 |
$indentation = str_repeat(' ', $rangs[$type]);
|
| - |
|
166 |
}
|
| - |
|
167 |
return $indentation;
|
| - |
|
168 |
}
|
| - |
|
169 |
|
| - |
|
170 |
private function getTxtLienGenerique($nom) {
|
| - |
|
171 |
$rangs = array('Reg' => 'Règne', 'Emb' => 'Embranchement', 'Cla' => 'Classe', 'Fam' => 'Famille',
|
| - |
|
172 |
'Gen' => 'Genre', 'Esp' => 'Espèce');
|
| - |
|
173 |
$nomSci = $nom['nom_sci'];
|
| - |
|
174 |
$txtLien = '';
|
| - |
|
175 |
if (preg_match('/^(Reg|Emb|Cla|Fam|Gen|Esp)([0-9]+)/', $nom['page_wiki_dsc'], $match)) {
|
| - |
|
176 |
$numCoste = $match[2];
|
| - |
|
177 |
$type = $match[1];
|
| - |
|
178 |
$nomRang = $rangs[$type];
|
| - |
|
179 |
$txtLien = "$nomRang $numCoste - $nomSci";
|
| - |
|
180 |
}
|
| - |
|
181 |
return $txtLien;
|
| - |
|
182 |
}
|
| - |
|
183 |
|
| - |
|
184 |
private function envoyerPage($titre, $txt) {
|
| - |
|
185 |
$donnees = array('pageTag' => $titre, 'pageContenu' => $txt);
|
| 105 |
echo "\n";
|
186 |
$this->restClient->ajouter($this->URL_WIKI_EFLORE, $donnees);
|
| 106 |
}
|
187 |
}
|
| 107 |
|
188 |
|
| 108 |
private function telechargerTxt($url) {
|
189 |
private function telechargerTxt($url) {
|
| 109 |
$json = $this->restClient->consulter($url);
|
190 |
$json = $this->restClient->consulter($url);
|
| Line 110... |
Line 191... |
| 110 |
$donnees = json_decode($json, true);
|
191 |
$donnees = json_decode($json, true);
|
| 111 |
return $donnees['texte'];
|
192 |
return $donnees['texte'];
|
| 112 |
}
|
193 |
}
|
| 113 |
|
194 |
|
| 114 |
private function chargerIndex() {
|
195 |
private function chargerIndex() {
|
| 115 |
$indexTxt = $this->dossierBase.self::DOSSIER_V2.'index.tsv';
|
196 |
$indexTxt = $this->dossierBase.self::DOSSIER_V2.'coste_v2_00.tsv';
|
| 116 |
$this->index = $this->outils->transformerTxtTsvEnTableau($indexTxt);
|
197 |
$this->index = $this->outils->transformerTxtTsvEnTableau($indexTxt);
|