10 |
jpm |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* AppControleur est le controlleur principal de l'application.
|
|
|
5 |
* Elle repartie les demandes utilisateurs dans les différents modules, executent les actions et redistribue le code
|
|
|
6 |
* html dans les différentes fonctions d'affichage.
|
|
|
7 |
* C'est une Singleton.
|
|
|
8 |
*
|
|
|
9 |
* @category PHP 5.2
|
|
|
10 |
* @package eflore-consultation
|
|
|
11 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
12 |
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
|
|
|
13 |
* @copyright 2011 Tela-Botanica
|
|
|
14 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
|
|
|
15 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
|
|
|
16 |
* @version $Id$
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
class AppControleur extends Controleur {
|
11 |
jpm |
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Instance de la classe pointant sur elle même (pour le pattern singleton)
|
|
|
23 |
*/
|
|
|
24 |
private static $instance = null;
|
|
|
25 |
|
|
|
26 |
/**
|
41 |
jpm |
27 |
* Paramètres d'AppControleur
|
11 |
jpm |
28 |
*/
|
|
|
29 |
private static $parametres = array();
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Constructeur vide
|
|
|
33 |
*/
|
|
|
34 |
public function __construct() {
|
|
|
35 |
$sortie = array('titre' => '', 'description' => '', 'tags' => '',
|
16 |
jpm |
36 |
'corps' => '', 'tete' => '', 'pied' => '',
|
|
|
37 |
'navigation' => '', 'menu' => '');
|
61 |
jpm |
38 |
|
11 |
jpm |
39 |
self::$parametres = array(
|
61 |
jpm |
40 |
'referentiel' => Config::get('referentiel_defaut'),
|
11 |
jpm |
41 |
'module' => Config::get('module_defaut'),
|
|
|
42 |
'action' => Config::get('action_defaut'),
|
61 |
jpm |
43 |
'niveau' => Config::get('niveau_defaut'),
|
|
|
44 |
'sortie' => $sortie);
|
11 |
jpm |
45 |
parent::__construct();
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Initialisation du controleur principal en fonction des paramêtres de l'url.
|
|
|
50 |
*/
|
|
|
51 |
public static function initialiser() {
|
|
|
52 |
self::verifierCreationInstance();
|
|
|
53 |
self::gererSession();
|
27 |
jpm |
54 |
|
41 |
jpm |
55 |
self::nettoyerGet();
|
27 |
jpm |
56 |
self::capturerParametres();
|
41 |
jpm |
57 |
self::initialiserRegistre();
|
68 |
jpm |
58 |
self::chargerConfigReferentiel();
|
41 |
jpm |
59 |
|
27 |
jpm |
60 |
spl_autoload_register(array(get_class(), 'chargerClasse'));
|
11 |
jpm |
61 |
|
27 |
jpm |
62 |
self::executerModule();
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
private static function verifierCreationInstance() {
|
|
|
66 |
if (empty(self::$instance)) {
|
|
|
67 |
self::$instance = new AppControleur();
|
16 |
jpm |
68 |
}
|
11 |
jpm |
69 |
}
|
|
|
70 |
|
|
|
71 |
private static function gererSession() {
|
|
|
72 |
if (Config::get('session_demarrage')) {
|
|
|
73 |
// Attribution d'un nom à la session
|
|
|
74 |
session_name(Config::get('session_nom'));
|
|
|
75 |
// Démarrage de la session
|
|
|
76 |
session_start();
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
41 |
jpm |
80 |
private static function nettoyerGet() {
|
|
|
81 |
foreach ($_GET as $cle => $valeur) {
|
|
|
82 |
$verifier = array('NULL', "\n", "\r", "\\", "'", '"', "\x00", "\x1a", ';');
|
|
|
83 |
$_GET[$cle] = strip_tags(str_replace($verifier, '', $valeur));
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
27 |
jpm |
87 |
private static function capturerParametres() {
|
41 |
jpm |
88 |
if (isset($_GET['referentiel'])) {
|
|
|
89 |
self::$parametres['referentiel'] = $_GET['referentiel'];
|
|
|
90 |
}
|
27 |
jpm |
91 |
if (isset($_GET['module'])) {
|
|
|
92 |
self::$parametres['module'] = $_GET['module'];
|
|
|
93 |
}
|
|
|
94 |
if (isset($_GET['action'])) {
|
|
|
95 |
self::$parametres['action'] = $_GET['action'];
|
|
|
96 |
}
|
47 |
jpm |
97 |
if (isset($_GET['niveau'])) {
|
|
|
98 |
self::$parametres['niveau'] = $_GET['niveau'];
|
|
|
99 |
}
|
27 |
jpm |
100 |
}
|
|
|
101 |
|
41 |
jpm |
102 |
private static function initialiserRegistre() {
|
67 |
delphine |
103 |
Registre::set('eFlore.urlBase', new Url(Config::get('base_url_application_index')));
|
61 |
jpm |
104 |
Registre::set('eFlore.urlCourante', self::getUrlCourante());
|
|
|
105 |
Registre::set('eFlore.urlRedirection', self::getUrlRedirection());
|
|
|
106 |
|
68 |
jpm |
107 |
Registre::set('parametres.referentiel', self::$parametres['referentiel']);
|
|
|
108 |
Registre::set('parametres.module', self::$parametres['module']);
|
|
|
109 |
Registre::set('parametres.action', self::$parametres['action']);
|
|
|
110 |
Registre::set('parametres.niveau', self::$parametres['niveau']);
|
41 |
jpm |
111 |
}
|
|
|
112 |
|
68 |
jpm |
113 |
private static function chargerConfigReferentiel() {
|
|
|
114 |
$chemin = Config::get('chemin_configurations').strtolower(self::$parametres['referentiel']).'.ini';
|
|
|
115 |
Config::charger($chemin);
|
|
|
116 |
}
|
|
|
117 |
|
61 |
jpm |
118 |
private static function getUrlCourante() {
|
|
|
119 |
$url = false;
|
|
|
120 |
if (isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['QUERY_STRING'])) {
|
|
|
121 |
$url = $_SERVER['REQUEST_URI'].'?'.$_SERVER['QUERY_STRING'];
|
|
|
122 |
} else {
|
|
|
123 |
$url = $_SERVER['REQUEST_URI'];
|
|
|
124 |
}
|
|
|
125 |
return ($url) ? new Url($url) : $url;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
private static function getUrlRedirection() {
|
|
|
129 |
$url = false;
|
|
|
130 |
if (isset($_SERVER['REDIRECT_URL']) && !empty($_SERVER['REDIRECT_URL'])) {
|
|
|
131 |
if (isset($_SERVER['REDIRECT_QUERY_STRING']) && !empty($_SERVER['REDIRECT_QUERY_STRING'])) {
|
|
|
132 |
$url = $_SERVER['REDIRECT_URL'].'?'.$_SERVER['REDIRECT_QUERY_STRING'];
|
|
|
133 |
} else {
|
|
|
134 |
$url = $_SERVER['REDIRECT_URL'];
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
return ($url) ? new Url($url) : $url;
|
|
|
138 |
}
|
|
|
139 |
|
27 |
jpm |
140 |
private static function chargerClasse($nom_classe) {
|
47 |
jpm |
141 |
$dossiers_classes = array(Config::get('chemin_modules').self::getNomDossierModuleCourrant().DS,
|
|
|
142 |
Config::get('chemin_modeles').'api_0.1'.DS);
|
|
|
143 |
|
27 |
jpm |
144 |
foreach ($dossiers_classes as $chemin) {
|
|
|
145 |
$fichier_a_tester = $chemin.$nom_classe.'.php';
|
|
|
146 |
if (file_exists($fichier_a_tester)) {
|
|
|
147 |
include_once $fichier_a_tester;
|
|
|
148 |
return null;
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
|
34 |
jpm |
153 |
public static function getNomDossierDepuisParametre($parametre) {
|
|
|
154 |
$dossier = str_replace('-', '_', strtolower($parametre));
|
|
|
155 |
return $dossier;
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
public static function getNomDossierDepuisClasse($nomClasse) {
|
|
|
159 |
$dossier = str_replace(' ', '_', strtolower(preg_replace('/(?<!^)([A-Z])/',' $0', $nomClasse)));
|
|
|
160 |
return $dossier;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
private static function getNomDossierModuleCourrant() {
|
|
|
164 |
$dossier = self::getNomDossierDepuisParametre(self::$parametres['module']);
|
|
|
165 |
return $dossier;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
private static function getNomClasseModule() {
|
|
|
169 |
$dossier = str_replace(' ', '', ucwords(str_replace('-', ' ', strtolower(self::$parametres['module']))));
|
|
|
170 |
return $dossier;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
private static function getNomMethodeAction() {
|
|
|
174 |
$methode = 'executer'.
|
|
|
175 |
str_replace(' ', '', ucwords(str_replace('-', ' ', strtolower(self::$parametres['action']))));
|
|
|
176 |
return $methode;
|
|
|
177 |
}
|
|
|
178 |
|
27 |
jpm |
179 |
private static function executerModule() {
|
34 |
jpm |
180 |
$classeModule = self::getNomClasseModule();
|
|
|
181 |
$action = self::getNomMethodeAction();
|
27 |
jpm |
182 |
// Nous vérifions que le module existe
|
|
|
183 |
if (class_exists($classeModule)) {
|
|
|
184 |
$module = new $classeModule();
|
41 |
jpm |
185 |
|
|
|
186 |
// Chargement Entete et Pied de page par défaut
|
47 |
jpm |
187 |
$module->chargerEnteteGeneral();
|
|
|
188 |
$module->chargerMenuGeneral();
|
|
|
189 |
$module->chargerPiedGeneral();
|
41 |
jpm |
190 |
|
|
|
191 |
// Initialisation du module demandé
|
|
|
192 |
if (method_exists($module, 'initialiser')) {
|
|
|
193 |
$module->initialiser();
|
|
|
194 |
}
|
|
|
195 |
// Lancement de l'action demandé du module chargé
|
|
|
196 |
if (method_exists($module, $action)) {
|
|
|
197 |
$module->$action();
|
|
|
198 |
} else {
|
|
|
199 |
$m = "La méthode '$action' du controleur '$classeModule' est introuvable.";
|
|
|
200 |
trigger_error($m, E_USER_ERROR);
|
|
|
201 |
}
|
|
|
202 |
|
27 |
jpm |
203 |
self::fusionnerSortie($module->getSortie());
|
|
|
204 |
} else {
|
41 |
jpm |
205 |
$m = "La classe du controleur '$classeModule' est introuvable.";
|
|
|
206 |
trigger_error($m, E_USER_ERROR);
|
27 |
jpm |
207 |
}
|
|
|
208 |
}
|
|
|
209 |
|
11 |
jpm |
210 |
/**
|
|
|
211 |
* Fusionne un tableau de sortie par défaut avec le tableau renvoyé par l'action du module.
|
|
|
212 |
* @param array le tableau à fusionner
|
|
|
213 |
*/
|
|
|
214 |
private static function fusionnerSortie($sortie) {
|
|
|
215 |
self::$parametres['sortie'] = array_merge(self::$parametres['sortie'], $sortie);
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
/**
|
|
|
219 |
* Retourne le titre du contenu de l'application.
|
|
|
220 |
*/
|
|
|
221 |
public static function getMetaTitre() {
|
|
|
222 |
$contenu = self::$parametres['sortie']['titre'];
|
|
|
223 |
$sortie = self::convertirEncodage($contenu);
|
|
|
224 |
return $sortie;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
/**
|
|
|
228 |
* Retourne la description du contenu de l'application.
|
|
|
229 |
*/
|
|
|
230 |
public static function getMetaDescription() {
|
|
|
231 |
$contenu = self::$parametres['sortie']['description'];
|
|
|
232 |
$sortie = self::convertirEncodage($contenu);
|
|
|
233 |
return $sortie;
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
/**
|
|
|
237 |
* Retourne les mots-clés (tags) du contenu de l'application.
|
|
|
238 |
*/
|
|
|
239 |
public static function getMetaTags() {
|
|
|
240 |
$contenu = self::$parametres['sortie']['tags'];
|
|
|
241 |
$sortie = self::convertirEncodage($contenu);
|
|
|
242 |
return $sortie;
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
/**
|
|
|
246 |
* Retourne le contenu du corps de l'application.
|
|
|
247 |
*/
|
|
|
248 |
public static function getContenuCorps() {
|
|
|
249 |
$contenu = self::$parametres['sortie']['corps'];
|
|
|
250 |
$sortie = self::convertirEncodage($contenu);
|
|
|
251 |
return $sortie;
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
/**
|
|
|
255 |
* Retourne le contenu de la tête de l'application.
|
|
|
256 |
*/
|
|
|
257 |
public static function getContenuTete() {
|
|
|
258 |
$contenu = self::$parametres['sortie']['tete'];
|
|
|
259 |
$sortie = self::convertirEncodage($contenu);
|
|
|
260 |
return $sortie;
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
/**
|
|
|
264 |
* Retourne le contenu du pied de l'application.
|
|
|
265 |
*/
|
|
|
266 |
public static function getContenuPied() {
|
|
|
267 |
$contenu = self::$parametres['sortie']['pied'];
|
|
|
268 |
$sortie = self::convertirEncodage($contenu);
|
|
|
269 |
return $sortie;
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
/**
|
14 |
jpm |
273 |
* Retourne les éléments de navigation (onglet, fils d'ariane) de l'application.
|
11 |
jpm |
274 |
*/
|
|
|
275 |
public static function getContenuNavigation() {
|
|
|
276 |
$contenu = self::$parametres['sortie']['navigation'];
|
|
|
277 |
$sortie = self::convertirEncodage($contenu);
|
|
|
278 |
return $sortie;
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
/**
|
14 |
jpm |
282 |
* Retourne les éléments du menu de l'application.
|
|
|
283 |
*/
|
|
|
284 |
public static function getContenuMenu() {
|
|
|
285 |
$contenu = self::$parametres['sortie']['menu'];
|
|
|
286 |
$sortie = self::convertirEncodage($contenu);
|
|
|
287 |
return $sortie;
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
/**
|
11 |
jpm |
291 |
* Retourne les chronos pris dans l'appli
|
|
|
292 |
*/
|
|
|
293 |
public static function getChrono() {
|
|
|
294 |
$sortie = '';
|
|
|
295 |
if (Config::get('benchmark_chrono')) {
|
|
|
296 |
$chrono = Chronometre::afficherChrono();
|
|
|
297 |
$sortie = self::convertirEncodage($chrono);
|
|
|
298 |
}
|
|
|
299 |
return $sortie;
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
/**
|
|
|
303 |
* Retourne les messages d'exceptions et d'erreurs.
|
|
|
304 |
*/
|
|
|
305 |
public static function getExceptions() {
|
|
|
306 |
$contenu = (Config::get('debogage')) ? GestionnaireException::getExceptions() : '';
|
|
|
307 |
$sortie = self::convertirEncodage($contenu);
|
|
|
308 |
return $sortie;
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
/**
|
|
|
312 |
* Convertion du contenu de l'application (voir fichier config.ini : appli_encodage),
|
|
|
313 |
* dans le format de sortie désiré (voir fichier config.ini : sortie_encodage).
|
|
|
314 |
* Cette convertion a lieu seulement si les formats sont différents.
|
|
|
315 |
*/
|
|
|
316 |
private static function convertirEncodage($contenu) {
|
|
|
317 |
if (Config::get('sortie_encodage') != Config::get('appli_encodage')) {
|
|
|
318 |
$contenu = mb_convert_encoding($contenu, Config::get('sortie_encodage'), Config::get('appli_encodage'));
|
|
|
319 |
}
|
|
|
320 |
return $contenu;
|
|
|
321 |
}
|
10 |
jpm |
322 |
}
|
|
|
323 |
?>
|