Subversion Repositories Applications.wikini

Rev

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

Rev 31 Rev 33
Line 18... Line 18...
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');
-
 
23
	private $format_texte;
-
 
24
	
-
 
25
	const MIME_JSON = 'application/json';
-
 
26
	const MIME_HTML = 'text/html';
Line 22... Line 27...
22
	private $formats_retour = array('txt','html');
27
	const MIME_TEXT = 'text/plain';
-
 
28
	
-
 
29
	public function consulter($ressources, $parametres) {
23
	
30
		
24
	public function consulter($ressources, $parametres) {
31
		try {
25
		header('Content-type: text/plain');
-
 
26
		$verifOk = $this->verifierParametres($parametres);
32
			$this->definirValeurParDefautDesParametres();
-
 
33
			$this->verifierParametres($parametres);
27
		if ($verifOk) {
34
			$this->analyserParametres($ressources, $parametres);
28
			$this->pageNom = $ressources[0];
35
			
-
 
36
			$page = $this->consulterPage($this->pageNom);
-
 
37
			$retour = $this->formaterRetour($page);
29
			$page = $this->consulterPage($ressources[0]);
38
			
30
			return $this->formaterRetour($page);
39
			$this->envoyerContenuJson($retour);
31
		} else {
40
		} catch (Exception $e) {
32
			RestServeur::envoyerEnteteStatutHttp(RestServeur::HTTP_CODE_MAUVAISE_REQUETE);		
41
			$this->envoyerErreur($e);
Line 33... Line 42...
33
		}
42
		}
34
	}
-
 
35
	
-
 
36
	private function definirValeurParDefautDesParametres() {
-
 
37
		if (isset($this->parametres['retour']) == false) {
43
	}
38
			$this->parametres['retour'] = self::MIME_JSON;
44
	
39
		}
45
	private function definirValeurParDefautDesParametres() {
40
		if (isset($this->parametres['txt_format']) == false) {
46
		if (isset($this->parametres['txt_format']) == false) {
Line 41... Line 47...
41
			$this->parametres['txt_format'] = 'txt';
47
			$this->parametres['txt_format'] = 'txt';
42
		}
48
		}
-
 
49
	}
43
	}
50
	
44
	
51
	private function verifierParametres($parametres) {
45
	private function verifierParametres($parametres) {
52
		$erreurs = array();
46
		$ok = true;
53
		
47
		if (isset($parametres['txt_format'])) {
-
 
48
			if(!in_array($parametres['txt_format'], $this->formats_retour)) {
-
 
49
				$message = "La valeur du paramètre 'txt.format' peut seulement prendre les valeurs : txt et html.";
-
 
50
				$this->ajouterMessage($message);
54
		if (isset($parametres['txt_format'])) {
51
				$ok = false;
55
			if(!in_array($parametres['txt_format'], $this->formats_retour)) {
Line 52... Line 56...
52
			} else {
56
				$message = "La valeur du paramètre 'txt.format' peut seulement prendre les valeurs : txt et html.";
53
				$this->retour = $parametres['txt_format'];
57
				$erreurs[] = $message;
-
 
58
			}
54
			}
59
		}
Line -... Line 60...
-
 
60
		
-
 
61
		if(isset($parametres['txt_section_position']) && !is_numeric($parametres['txt_section_position'])) {
-
 
62
			$message = "La valeur du paramètre 'txt.section.position' peut seulement prendre des valeurs numeriques";
-
 
63
			$erreurs[] = $message;
-
 
64
		}
-
 
65
		
-
 
66
		if(isset($parametres['txt_section_titre']) && trim($parametres['txt_section_titre']) == '') {
-
 
67
			$message = "La valeur du paramètre 'txt.section.titre' ne peut pas être vide si celui-ci est présent";
-
 
68
			$erreurs[] = $message;
-
 
69
		}
-
 
70
				
-
 
71
		if (count($erreurs) > 0) {
-
 
72
			$message = implode('<br />', $erreurs);
-
 
73
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
55
		}
74
			throw new Exception($message, $code);
56
		
75
		}
57
		if(isset($parametres['txt_section_position'])) {
76
	}
-
 
77
	
-
 
78
	private function analyserParametres($ressources, $parametres) {	
58
			$this->section = $parametres['txt_section_position'];
79
		$this->pageNom = $ressources[0];
-
 
80
		if(isset($parametres['txt_section_titre'])) {
59
		}
81
			$this->section = $parametres['txt_section_titre'];
-
 
82
		}
60
		
83
		if(isset($parametres['txt_section_position'])) {
Line 61... Line 84...
61
		if(isset($parametres['txt_section_titre'])) {
84
			$this->section = $parametres['txt_section_position'];
62
			$this->section = $parametres['txt_section_titre'];
85
		}
63
		}
86
		if (isset($parametres['txt_format'])) {
Line 143... Line 166...
143
		return $section;
166
		return $section;
144
	}
167
	}
Line 145... Line 168...
145
	
168
	
Line -... Line 169...
-
 
169
	private function formaterRetour($page) {
-
 
170
 
-
 
171
		$mime = null;
146
	private function formaterRetour($page) {
172
		$texte = '';
147
 
173
		
148
		switch($this->retour) {
174
		switch($this->retour) {
-
 
175
			case 'html':
149
			case 'html':
176
				$texte = $this->wiki->Format($page["body"], "wakka");
150
				$retour = $this->wiki->Format($page["body"], "wakka");
177
				$mime = self::MIME_HTML;
151
				break;
178
				break;
-
 
179
			default:
152
			default:
180
				$texte = $page["body"];
-
 
181
				$mime = self::MIME_TEXT;
-
 
182
		}
-
 
183
		
-
 
184
		$retour = array('id' => $this->pageNom,
-
 
185
				'titre' => $this->pageNom,
-
 
186
				'mime' => $mime,
-
 
187
				'texte' => $texte,
153
				$retour = $page["body"];
188
				'href' => '');
154
		}
189
		
155
		return $retour;
-
 
156
	}
-
 
157
	
-
 
158
	private function formaterRetourHtml($retour) {
-
 
159
	
190
		return $retour;
160
	}
191
	}
161
}	
192
}