Subversion Repositories Applications.wikini

Rev

Rev 33 | Rev 36 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33 Rev 35
Line 17... Line 17...
17
	private $wiki = null;
17
	private $wiki = null;
18
	private $pageNom = null;
18
	private $pageNom = null;
19
	private $section = null;
19
	private $section = null;
Line 20... Line 20...
20
	
20
	
21
	private $retour = 'txt';
21
	private $retour = 'txt';
22
	private $formats_retour = array('txt','html');
22
	private $formats_retour = array('text/plain','text/html');
Line 23... Line 23...
23
	private $format_texte;
23
	private $format_texte;
24
	
24
	
25
	const MIME_JSON = 'application/json';
25
	const MIME_JSON = 'application/json';
Line 31... Line 31...
31
		try {
31
		try {
32
			$this->definirValeurParDefautDesParametres();
32
			$this->definirValeurParDefautDesParametres();
33
			$this->verifierParametres($parametres);
33
			$this->verifierParametres($parametres);
34
			$this->analyserParametres($ressources, $parametres);
34
			$this->analyserParametres($ressources, $parametres);
Line 35... Line 35...
35
			
35
			
36
			$page = $this->consulterPage($this->pageNom);
36
			$page = $this->consulterPage($this->pageNom, $this->section);
Line 37... Line 37...
37
			$retour = $this->formaterRetour($page);
37
			$retour = $this->formaterRetour($page);
38
			
38
			
39
			$this->envoyerContenuJson($retour);
39
			$this->envoyerContenuJson($retour);
Line 51... Line 51...
51
	private function verifierParametres($parametres) {
51
	private function verifierParametres($parametres) {
52
		$erreurs = array();
52
		$erreurs = array();
Line 53... Line 53...
53
		
53
		
54
		if (isset($parametres['txt_format'])) {
54
		if (isset($parametres['txt_format'])) {
55
			if(!in_array($parametres['txt_format'], $this->formats_retour)) {
55
			if(!in_array($parametres['txt_format'], $this->formats_retour)) {
56
				$message = "La valeur du paramètre 'txt.format' peut seulement prendre les valeurs : txt et html.";
56
				$message = "La valeur du paramètre 'txt.format' peut seulement prendre les valeurs : text/plain et text/html.";
57
				$erreurs[] = $message;
57
				$erreurs[] = $message;
58
			}
58
			}
Line 59... Line 59...
59
		}
59
		}
Line 86... Line 86...
86
		if (isset($parametres['txt_format'])) {
86
		if (isset($parametres['txt_format'])) {
87
			$this->retour = $parametres['txt_format'];
87
			$this->retour = $parametres['txt_format'];
88
		}
88
		}
89
	}
89
	}
Line 90... Line 90...
90
	
90
	
91
	private function consulterPage($page) {
91
	private function consulterPage($page, $section = null) {
92
		$this->wiki = Registre::get('wikiApi');
92
		$this->wiki = Registre::get('wikiApi');
93
		$this->wiki->setPageCourante($this->pageNom);
93
		$this->wiki->setPageCourante($this->pageNom);
94
		$page = $this->wiki->LoadPage($page);
-
 
95
		
94
		$page = $this->wiki->LoadPage($page);
96
		// attention les wikis sont en ISO !
-
 
97
		if(Config::get('encodage_appli') != Config::get('encodage_wiki')) {
95
		// attention les wikis sont en ISO !
98
			$page["body"] = mb_convert_encoding($page['body'],Config::get('encodage_appli'),Config::get('encodage_wiki'));
-
 
Line 99... Line 96...
99
		}
96
		$page["body"] = $this->convertirTexteWikiVersEncodageAppli($page['body']);
100
	
97
	
101
		if($this->section != null) {
98
		if($section != null) {
Line 102... Line 99...
102
			$page["body"] = $this->découperPageSection($page["body"], $this->section);
99
			$page["body"] = $this->decouperPageSection($page["body"], $section);
103
		}
100
		}
Line 104... Line 101...
104
	
101
	
Line 105... Line 102...
105
		return $page;
102
		return $page;
Line 106... Line 103...
106
	}
103
	}
107
	
104
	
Line 153... Line 150...
153
		$reg_exp = '/((=[=]+)[ ]*'.preg_quote(trim($titre), '/').'[ ]*=[=]+)[.]*/i';
150
		$reg_exp = '/((=[=]+)[ ]*'.preg_quote(trim($titre), '/').'[ ]*=[=]+)[.]*/i';
154
		$match = preg_split($reg_exp, $page, 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
151
		$match = preg_split($reg_exp, $page, 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
Line 155... Line 152...
155
		
152
		
156
		if(count($match) > 3) {
153
		if(count($match) > 3) {
157
			$section = explode(trim($match[2]), $match[3], 2);
154
			$section = explode(trim($match[2]), $match[3], 2);
158
			$section = $match[1].' '.$section[0];
155
			$section = $match[1].$section[0];
159
		} elseif(count($match) == 2) {
156
		} elseif(count($match) == 2) {
160
			$section = explode(trim($match[1]), $match[2], 2);
157
			$section = explode(trim($match[1]), $match[2], 2);
161
			$section = $match[0].' '.$section[0];
158
			$section = $match[0].$section[0];
162
		} else {
159
		} else {
163
			$section = "";
160
			$section = "";
Line 164... Line 161...
164
		}
161
		}
Line 170... Line 167...
170
 
167
 
171
		$mime = null;
168
		$mime = null;
Line 172... Line 169...
172
		$texte = '';
169
		$texte = '';
173
		
170
		
174
		switch($this->retour) {
171
		switch($this->retour) {
175
			case 'html':
172
			case self::MIME_HTML:
176
				$texte = $this->wiki->Format($page["body"], "wakka");
173
				$texte = $this->wiki->Format($page["body"], "wakka");
177
				$mime = self::MIME_HTML;
174
				$mime = self::MIME_HTML;
178
				break;
175
				break;
179
			default:
176
			default:
180
				$texte = $page["body"];
177
				$texte = $page["body"];
Line -... Line 178...
-
 
178
				$mime = self::MIME_TEXT;
-
 
179
		}
181
				$mime = self::MIME_TEXT;
180
		
182
		}
181
		$url = $this->wiki->Href("", $this->pageNom);
183
		
182
		
184
		$retour = array('id' => $this->pageNom,
183
		$retour = array('id' => $this->pageNom,
185
				'titre' => $this->pageNom,
184
				'titre' => $this->pageNom,
Line 186... Line 185...
186
				'mime' => $mime,
185
				'mime' => $mime,
187
				'texte' => $texte,
186
				'texte' => $texte,
-
 
187
				'href' => $url);
-
 
188
		
-
 
189
		return $retour;
-
 
190
	}
-
 
191
	
-
 
192
	public function ajouter($ressources, $requeteDonnees) {
-
 
193
		return $this->modifier($ressources, $requeteDonnees);
-
 
194
	}
-
 
195
	
-
 
196
	public function modifier($ressources, $requeteDonnees) {
-
 
197
	
-
 
198
		$this->pageNom = $ressources[0];
-
 
199
		$this->wiki = Registre::get('wikiApi');
-
 
200
		$this->wiki->setPageCourante($this->pageNom);
-
 
201
		
-
 
202
		$section = (isset($requeteDonnees['txt.section.titre']) && trim($requeteDonnees['txt.section.titre']) != "") ? $requeteDonnees['txt.section.titre'] : null;
-
 
203
		$texte = $requeteDonnees['texte'];
-
 
204
		
-
 
205
		$page = $this->consulterPage($this->pageNom);
-
 
206
		$corps = $page['body'];
-
 
207
		$section_page_originale = $corps;
-
 
208
		
-
 
209
		if($section != null) {
-
 
210
			$section_page_originale = $this->decouperPageSection($corps, $section);
-
 
211
		}	
-
 
212
		
-
 
213
		$page_remplacee = str_replace($section_page_originale, $texte, $corps);
-
 
214
		
-
 
215
		$texte_encode = $this->convertirTexteAppliVersEncodageWiki($page_remplacee);
-
 
216
		$ecriture = $this->wiki->SavePage($this->pageNom, $texte_encode, "", true);
-
 
217
	
-
 
218
		if($ecriture) {
-
 
219
			$this->envoyerCreationEffectuee();
-
 
220
		} else {
-
 
221
			$this->envoyerErreurServeur();
-
 
222
		}
-
 
223
		
-
 
224
		return $ecriture;
-
 
225
	}
-
 
226
	
-
 
227
	private function convertirTexteWikiVersEncodageAppli($texte) {
-
 
228
		if(Config::get('encodage_appli') != Config::get('encodage_wiki')) {
-
 
229
			$texte = mb_convert_encoding($texte,Config::get('encodage_appli'),Config::get('encodage_wiki'));
-
 
230
		}
-
 
231
		return $texte;
-
 
232
	}
-
 
233
	
-
 
234
	private function convertirTexteAppliVersEncodageWiki($texte) {
-
 
235
		if(Config::get('encodage_appli') != Config::get('encodage_wiki')) {
188
				'href' => '');
236
			$texte = mb_convert_encoding($texte,Config::get('encodage_wiki'),Config::get('encodage_appli'));
189
		
237
		}
190
		return $retour;
238
		return $texte;