Subversion Repositories Applications.wikini

Rev

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

Rev 30 Rev 33
Line 4... Line 4...
4
	//+----------------------------------------------------------------------------------------------------------------+
4
	//+----------------------------------------------------------------------------------------------------------------+
5
	// GESTION de l'ENVOIE au NAVIGATEUR
5
	// GESTION de l'ENVOIE au NAVIGATEUR
Line 6... Line 6...
6
 
6
 
7
	protected function formaterEnJsonp($donnees = null, $encodage = 'utf-8') {
7
	protected function formaterEnJsonp($donnees = null, $encodage = 'utf-8') {
8
		$contenu = $_GET['callback'].'('.json_encode($donnees).');';
-
 
9
		return $this->preparerEnvoie($contenu, 'text/html', $encodage);
-
 
10
	}
-
 
11
	
-
 
12
	protected function formaterEnJson($donnees = null, $encodage = 'utf-8') {
-
 
13
		$contenu = json_encode($donnees);
-
 
14
		return $this->preparerEnvoie($contenu, 'application/json', $encodage);
-
 
15
	}
-
 
16
	
-
 
17
	private function preparerEnvoie($sortie = 'OK', $mime = 'text/html', $encodage = 'utf-8') {
-
 
18
		$this->envoyerEnteteContenu($encodage, $mime);
8
		$contenu = $_GET['callback'].'('.json_encode($donnees).');';
19
		return $sortie;
9
		return $contenu;
Line 20... Line 10...
20
	}
10
	}
21
 
11
 
22
	private function envoyerEnteteContenu($encodage, $mime) {
12
	private function envoyerEnteteContenu($encodage, $mime) {
23
		if (!is_null($mime) && !is_null($encodage)) {
13
		if (!is_null($mime) && !is_null($encodage)) {
24
			header("Content-Type: $mime; charset=$encodage");
14
			header("Content-Type: $mime; charset=$encodage");
25
		} else if (!is_null($mime) && is_null($encodage)) {
15
		} else if (!is_null($mime) && is_null($encodage)) {
26
			header("Content-Type: $mime");
16
			header("Content-Type: $mime");
-
 
17
		}
-
 
18
	}
-
 
19
	
-
 
20
	public function envoyerContenuJson($donnees = null, $encodage = 'utf-8') {
-
 
21
		$contenu = json_encode($donnees);
-
 
22
		$this->envoyerEnteteContenu($encodage, 'application/json');
-
 
23
		echo $contenu;
Line 27... Line 24...
27
		}
24
		exit;
28
	}
25
	}
29
		
26
		
30
	protected function envoyerAuth($message_accueil, $message_echec) {
27
	protected function envoyerAuth($message_accueil, $message_echec) {
31
		header('HTTP/1.0 401 Unauthorized');
28
		header('HTTP/1.0 401 Unauthorized');
32
		header('WWW-Authenticate: Basic realm="'.mb_convert_encoding($message_accueil, 'ISO-8859-1', 'UTF-8').'"');
29
		header('WWW-Authenticate: Basic realm="'.mb_convert_encoding($message_accueil, 'ISO-8859-1', 'UTF-8').'"');
33
		header('Content-type: text/plain; charset=UTF-8');
30
		header('Content-type: text/plain; charset=UTF-8');
-
 
31
		print $message_echec;
-
 
32
		exit(0);
-
 
33
	}
-
 
34
	
-
 
35
	protected function envoyerErreur($e) {
34
		print $message_echec;
36
		header($e->getCode());
35
		exit(0);
37
		echo $e->getMessage();
36
	}
38
	}