477 |
jpm |
1 |
<?php
|
|
|
2 |
class Wiki {
|
|
|
3 |
const DOSSIER_V2 = '../../../donnees/coste/2.00/';
|
|
|
4 |
const DOSSIER_DSC_TXT = '../../../donnees/coste/descriptions/txt/';
|
|
|
5 |
|
484 |
jpm |
6 |
private $URL_WIKI = '';
|
|
|
7 |
private $URL_WIKI_EFLORE = '';
|
477 |
jpm |
8 |
private $conteneur = null;
|
|
|
9 |
private $outils = null;
|
|
|
10 |
private $messages = null;
|
|
|
11 |
private $restClient = null;
|
|
|
12 |
private $dossierBase = '';
|
|
|
13 |
private $index = array();
|
|
|
14 |
|
|
|
15 |
public function __construct(Conteneur $conteneur) {
|
|
|
16 |
mb_internal_encoding('UTF-8');
|
|
|
17 |
setlocale(LC_ALL, 'fr_FR.UTF-8');
|
484 |
jpm |
18 |
$this->conteneur = $conteneur;
|
|
|
19 |
$this->URL_WIKI = $this->conteneur->getParametre('wiki.travail');
|
|
|
20 |
$this->URL_WIKI_EFLORE = $this->conteneur->getParametre('wiki.eflore');
|
477 |
jpm |
21 |
$this->outils = $conteneur->getOutils();
|
|
|
22 |
$this->messages = $conteneur->getMessages();
|
|
|
23 |
$this->restClient = $conteneur->getRestClient();
|
|
|
24 |
$this->dossierBase = dirname(__FILE__).'/';
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
public function uploaderFichiersSp() {
|
|
|
28 |
$this->chargerIndex();
|
|
|
29 |
$envoyes = array();
|
|
|
30 |
foreach ($this->index as $nom) {
|
|
|
31 |
$tag = $nom['page_wiki_dsc'];
|
|
|
32 |
if (isset($envoyes[$tag]) == false && preg_match('/^Esp([0-9]{4})/', $tag, $match)) {
|
|
|
33 |
$fichier = $this->dossierBase.self::DOSSIER_DSC_TXT.$match[1].'.txt';
|
|
|
34 |
if (file_exists($fichier) === true) {
|
|
|
35 |
$txt = file_get_contents($fichier);
|
|
|
36 |
$donnees = array('pageTag' => $tag, 'pageContenu' => $txt);
|
484 |
jpm |
37 |
$this->restClient->ajouter($this->URL_WIKI, $donnees);
|
477 |
jpm |
38 |
$envoyes[$tag] = 'OK';
|
|
|
39 |
} else {
|
|
|
40 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
|
|
41 |
}
|
|
|
42 |
}
|
478 |
jpm |
43 |
$this->messages->afficherAvancement("Upload des fichiers d'espèce dans le wikini");
|
477 |
jpm |
44 |
}
|
478 |
jpm |
45 |
echo "\n";
|
477 |
jpm |
46 |
}
|
|
|
47 |
|
|
|
48 |
public function dowloaderPagesWiki() {
|
|
|
49 |
$this->chargerIndex();
|
|
|
50 |
$envoyes = array();
|
|
|
51 |
foreach ($this->index as $nom) {
|
|
|
52 |
$tagDsc = $nom['page_wiki_dsc'];
|
|
|
53 |
$tagCle = $nom['page_wiki_cle'];
|
|
|
54 |
if (isset($envoyes[$tagDsc]) == false) {
|
484 |
jpm |
55 |
$url = $this->URL_WIKI.'/'.$tagDsc;
|
477 |
jpm |
56 |
$txt = $this->telechargerTxt($url);
|
484 |
jpm |
57 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'dsc/'.$tagDsc.'.txt';
|
477 |
jpm |
58 |
if (file_put_contents($fichier, $txt)) {
|
|
|
59 |
$envoyes[$tagDsc] = 'OK';
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
if (isset($envoyes[$tagCle]) == false) {
|
484 |
jpm |
63 |
$url = $this->URL_WIKI.'/'.$tagCle;
|
477 |
jpm |
64 |
$txt = $this->telechargerTxt($url);
|
484 |
jpm |
65 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'cle/'.$tagCle.'.txt';
|
477 |
jpm |
66 |
if (file_put_contents($fichier, $txt)) {
|
|
|
67 |
$envoyes[$tagCle] = 'OK';
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
$this->messages->afficherAvancement("Download des fichiers en cours");
|
|
|
71 |
}
|
478 |
jpm |
72 |
echo "\n";
|
477 |
jpm |
73 |
}
|
|
|
74 |
|
478 |
jpm |
75 |
public function uploaderDansWikiEflore() {
|
|
|
76 |
$this->chargerIndex();
|
|
|
77 |
$envoyes = array();
|
484 |
jpm |
78 |
|
478 |
jpm |
79 |
foreach ($this->index as $nom) {
|
|
|
80 |
$tagDsc = $nom['page_wiki_dsc'];
|
|
|
81 |
if (isset($envoyes[$tagDsc]) == false) {
|
484 |
jpm |
82 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'dsc/'.$tagDsc.'.txt';
|
478 |
jpm |
83 |
if (file_exists($fichier) === true) {
|
|
|
84 |
$txt = file_get_contents($fichier);
|
484 |
jpm |
85 |
$this->envoyerPage($tagDsc, $txt);
|
478 |
jpm |
86 |
$envoyes[$tagDsc] = 'OK';
|
|
|
87 |
} else {
|
|
|
88 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
$tagCle = $nom['page_wiki_cle'];
|
|
|
93 |
if (isset($envoyes[$tagCle]) == false) {
|
484 |
jpm |
94 |
$fichier = $this->dossierBase.self::DOSSIER_V2.'cle/'.$tagCle.'.txt';
|
478 |
jpm |
95 |
if (file_exists($fichier) === true) {
|
|
|
96 |
$txt = file_get_contents($fichier);
|
484 |
jpm |
97 |
$this->envoyerPage($tagDsc, $txt);
|
478 |
jpm |
98 |
$envoyes[$tagCle] = 'OK';
|
|
|
99 |
} else {
|
|
|
100 |
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
$this->messages->afficherAvancement("Upload des textes dans le wikini eFlore");
|
|
|
104 |
}
|
|
|
105 |
echo "\n";
|
|
|
106 |
}
|
|
|
107 |
|
484 |
jpm |
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);
|
|
|
186 |
$this->restClient->ajouter($this->URL_WIKI_EFLORE, $donnees);
|
|
|
187 |
}
|
|
|
188 |
|
477 |
jpm |
189 |
private function telechargerTxt($url) {
|
|
|
190 |
$json = $this->restClient->consulter($url);
|
|
|
191 |
$donnees = json_decode($json, true);
|
|
|
192 |
return $donnees['texte'];
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
private function chargerIndex() {
|
484 |
jpm |
196 |
$indexTxt = $this->dossierBase.self::DOSSIER_V2.'coste_v2_00.tsv';
|
477 |
jpm |
197 |
$this->index = $this->outils->transformerTxtTsvEnTableau($indexTxt);
|
|
|
198 |
}
|
|
|
199 |
}
|
|
|
200 |
?>
|