Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 477 | Rev 484 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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