25 static protected $_oRequest;
26 static protected $_oCache;
27 static protected $_oCacheVar;
28 static protected $_oAuth;
29 static protected $_oUrlrewriting;
30 static protected $_oLog;
32 static protected $_tConfigFilename;
33 static protected $_tRequestTab;
34 static public $tAutoload;
36 static public $tConfigVar;
37 static protected $_tGlobalVar;
38 static protected $_tObject;
40 static protected $_oACL;
42 static protected $_bSessionStarted=0;
50 self::$tConfigVar=array();
52 self::$tConfigVar[
'path']=array(
54 'lib' =>
'lib/framework/',
57 'module' =>
'module/',
62 'cache'=>
'data/cache/',
63 'layout'=>
'site/layout/',
67 self::$_tConfigFilename=array();
77 public static function addConf($sConfig,$sCat=null){
78 self::$_tConfigFilename[]=array($sConfig,$sCat);
86 $bConfCacheEnabled=(int)self::getConfigVar(
'cache.conf.enabled');
87 $sCacheFilename=self::getConfigVar(
'path.cache').
'conf.php';
88 if($bConfCacheEnabled==1 and file_exists($sCacheFilename) ){
89 include $sCacheFilename;
93 $tConfigVar=self::$tConfigVar;
95 foreach(self::$_tConfigFilename as $tConfig){
97 $sCatFilter=$tConfig[1];
100 $tIniBrut=parse_ini_file($sConfig,
true);
102 if($sCatFilter!=null){
103 $tIni[$sCatFilter]=$tIniBrut[$sCatFilter];
107 $tConfigVar=self::arrayMergeRecursive($tConfigVar,$tIni);
110 self::$tConfigVar=$tConfigVar;
113 if($bConfCacheEnabled==1){
114 $sCodeCache=
'<?php _root::$tConfigVar='.var_export(self::$tConfigVar,
true).
';';
115 file_put_contents($sCacheFilename,$sCodeCache);
118 }
catch(Exception $e){
119 self::erreurLog($e->getMessage().
"\n".$e->getTraceAsString());
123 public static function arrayMergeRecursive($tArray,$tNewArray){
125 foreach($tNewArray as $sKey => $tValue){
126 foreach($tValue as $sChildKey => $sChildValue){
127 $tArray[$sKey][$sChildKey]=$sChildValue;
140 include_once self::getConfigVar(
'path.i18n').
'date_'.self::getConfigVar(
'language.default').
'.php';
144 public static function nullbyteprotect($string){
146 $string=trim($string);
148 return preg_replace(
'/\\x00/',
'', preg_replace(
'/\\\0/',
'',$string));
151 public static function startSession(){
152 if(self::$_bSessionStarted){
154 }
else if( (
int)self::getConfigVar(
'auth.session.use_cookies') == 1 ){
156 if((
int)self::getConfigVar(
'auth.session.cookie_httponly')==1){
160 if((
int)self::getConfigVar(
'auth.session.cookie_secure')==1 and isset($_SERVER[
'HTTPS']) ){
163 session_set_cookie_params(
164 (
int)self::getConfigVar(
'auth.session.cookie_lifetime',0),
165 self::getConfigVar(
'auth.session.cookie_path',null),
166 self::getConfigVar(
'auth.session.cookie_domain',null),
172 self::$_bSessionStarted=1;
185 self::loadAutoload();
189 if(self::getConfigVar(
'site.mode')==
'dev'){
190 error_reporting(E_ALL);
195 self::getLog()->setInformation((
int)self::getConfigVar(
'log.information'));
196 self::getLog()->setWarning((
int)self::getConfigVar(
'log.warning'));
197 self::getLog()->setError((
int)self::getConfigVar(
'log.error'));
198 self::getLog()->setApplication((
int)self::getConfigVar(
'log.application'));
202 date_default_timezone_set(self::getConfigVar(
'site.timezone'));
204 if( (
int)self::getConfigVar(
'auth.enabled') == 1 ){
205 self::getAuth()->enable();
209 if (get_magic_quotes_gpc()) {
210 $_POST = array_map(
'stripslashes_deep', $_POST);
211 $_GET = array_map(
'stripslashes_deep', $_GET);
212 $_COOKIE = array_map(
'stripslashes_deep', $_COOKIE);
216 if( (
int)self::getConfigVar(
'urlrewriting.enabled') == 1 ){
217 self::getUrlRewriting()->parseUrl($_SERVER[
'REQUEST_URI']);
220 $sModuleToLoad=self::getRequest()->getModule();
221 $sModuleActionToLoad=self::getRequest()->getAction();
223 self::getLog()->info(
'module a appeler ['.$sModuleToLoad.
'::'.$sModuleActionToLoad.
']');
226 $sClassModule=
'module_'.$sModuleToLoad;
228 $oModule=
new $sClassModule;
230 if( method_exists($oModule,
'_'.$sModuleActionToLoad) ){
232 self::getLog()->info(
'appel module ['.$sModuleToLoad.
'::before]');
236 if( method_exists($oModule,
'before_'.$sModuleActionToLoad) ){
237 self::getLog()->info(
'appel module ['.$sModuleToLoad.
'::before_'.$sModuleActionToLoad.
']');
238 $sActionBefore=
'before_'.$sModuleActionToLoad;
239 $oModule->$sActionBefore();
243 if( (
int)self::getConfigVar(
'cache.enabled') == 1 ){
245 $sNomPageCache=
'cache_'.str_replace(
'::',
'_',implode(
'_',self::getRequest()->getParams())).
'.html';
246 $oFichierCache=
new _file(self::getConfigVar(
'path.cache').$sNomPageCache);
249 ( $oFichierCache->exist() and (
int)self::getConfigVar(
'cache.lifetime') == 0 )
251 ( $oFichierCache->exist() and time()-$oFichierCache->filemtime() < (int)self::getConfigVar(
'cache.lifetime') )
253 self::getLog()->info(
'utilisation page en cache ['.$sNomPageCache.
']');
254 echo $oFichierCache->getContent();
260 $sAction=
'_'.$sModuleActionToLoad;
262 self::getLog()->info(
'appel module ['.$sModuleToLoad.
'::'.$sAction.
']');
263 $oModule->$sAction();
266 if( method_exists($oModule,
'after_'.$sModuleActionToLoad) ){
267 self::getLog()->info(
'appel module ['.$sModuleToLoad.
'::after_'.$sModuleActionToLoad.
']');
269 $sActionAfter=
'after_'.$sModuleActionToLoad;
270 $oModule->$sActionAfter();
274 self::getLog()->info(
'appel module ['.$sModuleToLoad.
'::after]');
278 if( (
int)self::getConfigVar(
'cache.enabled')== 1 ){
280 $sSortie=ob_get_contents();
283 $oFichierCache->write($sSortie.
"\n<!--cache -->");
290 'Erreur dans module/'.$sModuleToLoad.
'/main.php',
291 'Pas de méthode _'.$sModuleActionToLoad.
'() dans le module "'.$sModuleToLoad.
'" à charger',
292 'Note: vous pouvez modifier le couple module/action par defaut ',
293 'en modifiant la section [navigation] dans le fichier conf/site.ini.php',
295 throw new Exception(implode(
"\n",$tErreur));
298 }
catch(Exception $e){
299 self::erreurLog($e->getMessage().
"\n".self::showException($e),$e);
304 public static function showException(Exception $e) {
305 $tTrace = $e->getTrace();
306 $result=$e->getTraceAsString();
309 $result.=
"\n\nDetail:\n";
311 foreach($tTrace as $i=> $trace){
313 if(isset($trace[
'file'])){$result.=$trace[
'file'];}
314 if(isset($trace[
'line'])){$result.=
' ('.$trace[
'line'].
') '.
"\n";}
317 if(isset($trace[
'class'])){
318 $result.=$trace[
'class'].
' '.$trace[
'type'].
' '.$trace[
'function'].
'( ';
320 $result.=$trace[
'function'].
'( ';
324 if(isset($trace[
'args']) and is_array($trace[
'args'])){
326 foreach($trace[
'args'] as $j => $arg){
328 if($j>0){ $result.=
' , ';}
331 $result.=preg_replace(
'/\n|\r/',
' ',
335 if(is_null($arg)){ $result.=
'NULL';}
348 $result.=
'#'.($i+1).
' {main}';
354 private function loadAutoload(){
355 if((
int)self::getConfigVar(
'cache.autoload.enabled')==1){
356 $sCacheFilename=self::getConfigVar(
'path.cache').
'autoload.php';
357 if(file_exists($sCacheFilename)){
358 include $sCacheFilename;
362 'lib' => self::getConfigVar(
'path.lib'),
363 'abstract' => self::getConfigVar(
'path.lib').
'abstract/',
364 'sgbd' => self::getConfigVar(
'path.lib').
'sgbd/',
365 'sgbd_pdo' => self::getConfigVar(
'path.lib').
'sgbd/pdo/',
366 'sgbd_syntax' => self::getConfigVar(
'path.lib').
'sgbd/syntax/',
367 'plugin' => self::getConfigVar(
'path.plugin'),
368 'model' => self::getConfigVar(
'path.model'),
369 'module' => self::getConfigVar(
'path.module'),
374 foreach($tDir as $sType => $sDir){
376 if(in_array($sType,array(
386 $oDir=
new _dir($sDir);
388 $tFile=$oDir->getListFile();
389 foreach($tFile as $oFile){
390 $sFilename=$oFile->getName();
391 $tFilename=preg_split(
'/_/',$sFilename);
393 $tAutoload[
'_'.substr($tFilename[1],0,-4) ]=$sDir.$sFilename;
395 $tAutoload[ substr($sFilename,0,-4) ]=$sDir.$sFilename;
399 }
else if($sType==
'module'){
400 $oDir=
new _dir($sDir);
402 $tModuleDir=$oDir->getListDir();
403 foreach($tModuleDir as $oModuleDir){
404 $sModuleDirname=$oModuleDir->getName();
405 $tAutoload[
'module_'.$sModuleDirname]=$sDir.$sModuleDirname.
'/main.php';
410 $sCodeCache=
'<?php _root::$tAutoload='.var_export($tAutoload,
true).
';';
411 file_put_contents($sCacheFilename,$sCodeCache);
412 self::$tAutoload=$tAutoload;
424 $tab=preg_split(
'/_/',$sClass);
425 if(isset(self::$tAutoload[$sClass])){
426 include self::$tAutoload[$sClass];
427 }
else if($sClass[0]==
'_'){
428 include self::getConfigVar(
'path.lib').
'class'.$sClass.
'.php';
429 }
else if(in_array($tab[0],array(
'plugin',
'model',
'abstract'))){
430 include self::getConfigVar(
'path.'.$tab[0]).$sClass.
'.php';
431 }
else if($tab[0]==
'module'){
432 include self::getConfigVar(
'path.module').substr($sClass,7).
'/main.php';
433 }
else if($tab[0]==
'row'){
434 include self::getConfigVar(
'path.model').
'model_'.substr($sClass,4).
'.php';
435 }
else if($tab[0]==
'sgbd' and in_array($tab[1],array(
'syntax',
'pdo'))){
436 include self::getConfigVar(
'path.lib').
'sgbd/'.$tab[1].
'/'.$sClass.
'.php';
437 }
else if($tab[0]==
'sgbd'){
438 include self::getConfigVar(
'path.lib').
'sgbd/'.$sClass.
'.php';
454 self::getRequest()->setParam($sVar,$uValue);
465 public static function getParam($sVar,$uElse=null){
466 return self::getRequest()->getParam($sVar,$uElse);
476 self::getRequest()->setParamNav($sNav);
485 return self::getRequest()->getParamNav();
494 return self::getRequest()->getModule();
503 return self::getRequest()->getAction();
513 self::$_tRequestTab[]=$tRequest;
516 public static function loadRequest(){
517 if(self::$_oRequest==null){
520 foreach(self::$_tRequestTab as $tRequest){
521 foreach($tRequest as $sVar => $sVal){
522 self::getRequest()->setParam($sVar,$sVal);
532 self::$_oRequest=null;
533 self::$_tRequestTab=array();
542 return self::$_oRequest;
551 if(self::$_oCache==null){ self::$_oCache=
new _cache(); }
552 return self::$_oCache;
560 if(self::$_oCacheVar==null){ self::$_oCacheVar=
new _cacheVar(); }
561 return self::$_oCacheVar;
569 if(self::$_oAuth==null){
570 $sClassAuth=self::getConfigVar(
'auth.class');
571 self::$_oAuth=
new $sClassAuth;
573 return self::$_oAuth;
582 if(self::$_oACL==null){
583 $sClassACL=self::getConfigVar(
'acl.class');
584 self::$_oACL=
new $sClassACL;
596 if(self::$_oUrlrewriting==null){
597 $sClassUrlrewriting=self::getConfigVar(
'urlrewriting.class');
598 self::$_oUrlrewriting=
new $sClassUrlrewriting;
600 return self::$_oUrlrewriting;
611 if(self::$_oLog==null){
612 $sClassLog=self::getConfigVar(
'log.class');
615 'Il vous manque un bloc dans votre fichier conf/site.ini',
624 self::erreurLog(implode(
"\n",$tErreur));
626 self::$_oLog=
new $sClassLog;
638 if(preg_match(
'/\./',$sCatAndVar)){
639 list($sCategory,$sVar)=preg_split(
'/\./',$sCatAndVar,2);
640 self::$tConfigVar[$sCategory][$sVar]=$uValue;
642 self::$tConfigVar[$sCatAndVar]=$uValue;
656 if(preg_match(
'/\./',$sCatAndVar)){
657 list($sCategory,$sVar)=preg_split(
'/\./',$sCatAndVar,2);
659 if(in_array($sVar,array(
'sgbd',
'abstract',
'sgbd_pdo',
'sgbd_syntax'))){
660 if(preg_match(
'/_/',$sVar)){
661 $sVar=preg_replace(
'/_/',
'/',$sVar);
663 return self::$tConfigVar[
'path'][
'lib'].$sVar.
'/';
665 else if(isset(self::$tConfigVar[$sCategory][$sVar])){
666 return self::$tConfigVar[$sCategory][$sVar];
669 }
else if(isset(self::$tConfigVar[$sCatAndVar])){
670 return self::$tConfigVar[$sCatAndVar];
682 self::$_tGlobalVar[$sVar]=$sValue;
692 if(isset(self::$_tGlobalVar[$sVar])){
693 return self::$_tGlobalVar[$sVar];
705 self::$_tObject[$sObj]=$oObj;
715 if(isset(self::$_tObject[$sObj])){
716 return self::$_tObject[$sObj];
727 public static function redirect($uNav,$tParam=null){
728 self::getLog()->info(
'redirection ['.self::getLink($uNav,$tParam,
false).
']');
729 header(
'Location:'.self::getLink($uNav,$tParam,
false));
740 $tOriginParam=self::getRequest()->getParamsGET();
743 $tNewParam=array_merge($tOriginParam,$tParam);
744 $sNav=self::getParamNav();
746 return self::getLink($sNav,$tNewParam,$bAmp);
756 public static function getLink($uNav,$tParam=null,$bAmp=
true){
766 if( (
int)self::getConfigVar(
'urlrewriting.enabled') ==1 ){
767 return self::getUrlRewriting()->getLink($sNav,$tParam);
769 return self::getLinkString($sNav,$tParam,$bAmp);
781 if(is_array($tParam)){
782 foreach($tParam as $sKey => $sVal){
790 $sLink.=$sKey.
'='.$sVal;
792 if(isset($tParam[
'#'])){
793 $sLink.=
'#'.$tParam[
'#'];
797 return self::getConfigVar(
'navigation.scriptname').
'?'.self::getConfigVar(
'navigation.var').
'='.$sNav.$sLink;
801 public static function erreurLog($sText,$e=null){
802 if(self::getConfigVar(
'site.mode')==
'dev'){
804 if(self::getConfigVar(
'debug.class')){
805 $sClass=self::getConfigVar(
'debug.class');
807 $oDebug->show($sText,$e);
809 $sText=nl2br($sText);
810 include self::getConfigVar(
'path.layout').
'erreur.php';
814 include self::getConfigVar(
'navigation.layout.erreur',
'../layout/erreurprod.php');
816 if(self::getConfigVar(
'log.apache.enabled',1)==1){
817 error_log(
'[quiet error]:'.$sText);
819 if(self::getConfigVar(
'log.file.enabled',1)==1){
820 $open=fopen(self::getConfigVar(
'path.log',
'data/log').date(
'Y-m-d').
'.txt',
'a+');
825 }
catch(Exception $e){
835 function stripslashes_deep($value){
836 if(is_array($value)){
837 return array_map(
'stripslashes_deep', $value);
839 return stripslashes($value);
842 function customHtmlentities($string){
843 if(is_array($string)){
return array_map(
'customHtmlentities',$string) ;}
844 return _root::nullbyteprotect(htmlentities(
static getConfigVar($sCatAndVar, $uDefaut=null)
static setGlobalVar($sVar, $sValue)
static getLink($uNav, $tParam=null, $bAmp=true)
static setConfigVar($sCatAndVar, $uValue)
static addRequest($tRequest)
static getParam($sVar, $uElse=null)
static setParamNav($sNav)
static getLinkString($sNav, $tParam=null, $bAmp=true)
static setInstanceOf($sObj, $oObj)
static setParam($sVar, $uValue)
static addConf($sConfig, $sCat=null)
static getLinkWithCurrent($tParam=null, $bAmp=true)
static redirect($uNav, $tParam=null)
static getObject($sObj, $defaut=null)
static getGlobalVar($sVar, $defaut=null)