| Line 22... |
Line 22... |
| 22 |
protected $orderby = null;
|
22 |
protected $orderby = null;
|
| 23 |
protected $formatRetour = 'objet';
|
23 |
protected $formatRetour = 'objet';
|
| 24 |
protected $start = 0;
|
24 |
protected $start = 0;
|
| 25 |
protected $limit = 150;
|
25 |
protected $limit = 150;
|
| Line -... |
Line 26... |
| - |
|
26 |
|
| - |
|
27 |
/** pour l'envoi de XML : éventuelle balise dans laquelle placer tout le contenu */
|
| - |
|
28 |
protected $baliseMaitresse;
|
| 26 |
|
29 |
|
| 27 |
public function __construct($config, $demarrer_session = true) {
|
30 |
public function __construct($config, $demarrer_session = true) {
|
| 28 |
// Tableau contenant la config de Jrest
|
31 |
// Tableau contenant la config de Jrest
|
| Line 29... |
Line 32... |
| 29 |
$this->config = $config;
|
32 |
$this->config = $config;
|
| Line 59... |
Line 62... |
| 59 |
protected function envoyerJson($donnees, $encodage = 'utf-8') {
|
62 |
protected function envoyerJson($donnees, $encodage = 'utf-8') {
|
| 60 |
$contenu = json_encode($donnees);
|
63 |
$contenu = json_encode($donnees);
|
| 61 |
$this->envoyer($contenu, 'application/json', $encodage, false);
|
64 |
$this->envoyer($contenu, 'application/json', $encodage, false);
|
| 62 |
}
|
65 |
}
|
| Line -... |
Line 66... |
| - |
|
66 |
|
| - |
|
67 |
/** à l'arrache pour rétrocompatibilité avec le service "annuaire_tela" de eFlore_chatin */
|
| - |
|
68 |
protected function envoyerXml($donnees, $encodage = 'utf-8') {
|
| - |
|
69 |
$xml = '<?xml version="1.0" encoding="' . strtoupper($encodage) . '"?>';
|
| - |
|
70 |
if ($this->baliseMaitresse) {
|
| - |
|
71 |
$xml .= '<' . $this->baliseMaitresse . '>';
|
| - |
|
72 |
}
|
| - |
|
73 |
$xml .= $this->genererXmlAPartirDeTableau($donnees);
|
| - |
|
74 |
if ($this->baliseMaitresse) {
|
| - |
|
75 |
$xml .= '</' . $this->baliseMaitresse . '>';
|
| - |
|
76 |
}
|
| - |
|
77 |
$this->envoyer($xml, 'application/xml', $encodage, false);
|
| - |
|
78 |
}
|
| - |
|
79 |
|
| - |
|
80 |
/**
|
| - |
|
81 |
* Génère un XML minimaliste à partir d'un tableau associatif
|
| - |
|
82 |
* Note : gère mal les indices numériques
|
| - |
|
83 |
* @TODO utiliser une vraie lib
|
| - |
|
84 |
*/
|
| - |
|
85 |
protected function genererXmlAPartirDeTableau($tableau) {
|
| - |
|
86 |
$xml = '';
|
| - |
|
87 |
foreach ($tableau as $balise => $donnee) {
|
| - |
|
88 |
$xml .= '<' . $balise . '>';
|
| - |
|
89 |
if (is_array($donnee)) {
|
| - |
|
90 |
// récurer, balayer, que ce soit toujours pimpant
|
| - |
|
91 |
$xml .= $this->genererXmlAPartirDeTableau($donnee);
|
| - |
|
92 |
} else {
|
| - |
|
93 |
$xml .= $donnee;
|
| - |
|
94 |
}
|
| - |
|
95 |
$xml .= '</' . $balise . '>';
|
| - |
|
96 |
}
|
| - |
|
97 |
return $xml;
|
| - |
|
98 |
}
|
| 63 |
|
99 |
|
| 64 |
protected function envoyerJsonVar($variable, $donnees = null, $encodage = 'utf-8') {
|
100 |
protected function envoyerJsonVar($variable, $donnees = null, $encodage = 'utf-8') {
|
| 65 |
$contenu = "var $variable = ".json_encode($donnees);
|
101 |
$contenu = "var $variable = ".json_encode($donnees);
|
| 66 |
$this->envoyer($contenu, 'text/html', $encodage, false);
|
102 |
$this->envoyer($contenu, 'text/html', $encodage, false);
|
| Line 345... |
Line 381... |
| 345 |
$identifie = true;
|
381 |
$identifie = true;
|
| 346 |
}
|
382 |
}
|
| 347 |
return $identifie;
|
383 |
return $identifie;
|
| 348 |
}
|
384 |
}
|
| Line -... |
Line 385... |
| - |
|
385 |
|
| - |
|
386 |
/**
|
| - |
|
387 |
* Envoie une demande d'authentification HTTP puis compare le couple
|
| - |
|
388 |
* login / mot de passe envoyé par l'utilisateur, à ceux définis dans
|
| - |
|
389 |
* la config (section database_ident).
|
| - |
|
390 |
* En cas d'erreur, sort du programme avec un entête HTTP 401
|
| - |
|
391 |
* @TODO redondant avec les trucs du dessus :'(
|
| - |
|
392 |
*/
|
| - |
|
393 |
protected function authentificationHttpSimple() {
|
| - |
|
394 |
$autorise = true;
|
| - |
|
395 |
// contrôle d'accès
|
| - |
|
396 |
$nomUtil = $_SERVER['PHP_AUTH_USER'];
|
| - |
|
397 |
$mdp = $_SERVER['PHP_AUTH_PW'];
|
| - |
|
398 |
$autorise = (($nomUtil == $this->config['database_ident']['username']) && ($mdp == $this->config['database_ident']['password']));
|
| - |
|
399 |
// entêtes HTTP
|
| - |
|
400 |
if (! $autorise) {
|
| - |
|
401 |
header('WWW-Authenticate: Basic realm="Annuaire de Tela Botanica"');
|
| - |
|
402 |
header('HTTP/1.0 401 Unauthorized');
|
| - |
|
403 |
echo 'Veuillez vous authentifier pour utiliser ce service';
|
| - |
|
404 |
exit;
|
| - |
|
405 |
}
|
| - |
|
406 |
}
|
| 349 |
|
407 |
|
| 350 |
protected function creerCookiePersistant($duree = null, $id = null, $mdp = null) {
|
408 |
protected function creerCookiePersistant($duree = null, $id = null, $mdp = null) {
|
| 351 |
$id = is_null($id) ? $_SERVER['PHP_AUTH_USER'] : $id;
|
409 |
$id = is_null($id) ? $_SERVER['PHP_AUTH_USER'] : $id;
|
| 352 |
$mdp = is_null($mdp) ? $_SERVER['PHP_AUTH_PW'] : $mdp;
|
410 |
$mdp = is_null($mdp) ? $_SERVER['PHP_AUTH_PW'] : $mdp;
|