PageRenderTime 58ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/class.xshell.inc

https://github.com/jcplat/console-seolan
PHP | 1037 lines | 874 code | 75 blank | 88 comment | 250 complexity | 689fa915ee24eea94b6e11455cf32e74 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. @require_once 'Log.php';
  3. @require_once 'Log/file.php';
  4. class XShell implements ISec {
  5. public $tpldata = array();
  6. public $rawdata = array();
  7. public $_debug = false;
  8. public $_starttime=0.0000;
  9. public $_cache = true;
  10. public $_callback = NULL;
  11. public $_function = NULL;
  12. public $_next=NULL; /* dans le cas ou on envisage une redirection apres traitement */
  13. static $_log=NULL;
  14. static $_bdxprefix='0'; // prefix of the back stack
  15. static $_bdx=0; // index of the back stack
  16. function __construct($ar='*',$cache=true) {
  17. $this->_starttime=TZR_START_TIME;
  18. $this->_cache = $cache;
  19. $matches=array();
  20. $this->_loginurl=$GLOBALS['TZR_SELF'].'?';
  21. self::$_log=XLogs::_initLogFile();
  22. }
  23. /// Recupere le bdx en cours
  24. function getBdx(){
  25. if(@$_REQUEST['_bdxnewstack']==1){
  26. XShell::$_bdxprefix=max(array_keys($_SESSION['BACK']))+1;
  27. XShell::$_bdx=0;
  28. }elseif(!empty($_REQUEST['_bdx']) && preg_match('/^([0-9]+)_([0-9]+)$/i',$_REQUEST['_bdx'],$matches)){
  29. if(!empty($matches[2]) || $matches[2]==='0'){
  30. XShell::$_bdxprefix=$matches[1];
  31. XShell::$_bdx=$matches[2];
  32. }else{
  33. XShell::$_bdxprefix='0';
  34. XShell::$_bdx=$matches[1];
  35. }
  36. }
  37. }
  38. /// securite des fonctions accessibles par le web
  39. function secGroups($function, $group=NULL) {
  40. $g=array();
  41. $g['index']=array('none','ro','rw','rwv','admin');
  42. if(isset($g[$function])) {
  43. if(!empty($group)) return in_array($group, $g[$function]);
  44. return $g[$function];
  45. }
  46. return NULL;
  47. }
  48. function secList() {
  49. return array('none','ro','rw','rwv','admin');
  50. }
  51. static public function _function() {
  52. return $GLOBALS['XSHELL']->_function;
  53. }
  54. // Retourne le niveau de traitement à effectuer (0 => tout, 1 => desactive les callbacks, 2 => desactive les menus)
  55. static public function _raw() {
  56. return $GLOBALS['XSHELL']->_raw;
  57. }
  58. // Retourne vrai si la requete exécuté est en mode ajax
  59. static public function _ajax() {
  60. return $GLOBALS['XSHELL']->_ajax;
  61. }
  62. // Retourne vrai si la requete exécuté doit etre traité pour une iframe
  63. static public function _iframeencode() {
  64. return $GLOBALS['XSHELL']->_iframeencode;
  65. }
  66. static public function uniqid(){
  67. if(empty($GLOBALS['XSHELL']->_uniqid)){
  68. if(!empty($_REQUEST['_uniqid'])) $GLOBALS['XSHELL']->_uniqid=$_REQUEST['_uniqid'];
  69. else $GLOBALS['XSHELL']->_uniqid=uniqid();
  70. }
  71. return $GLOBALS['XSHELL']->_uniqid;
  72. }
  73. public function setLoginUrl($url) {
  74. $this->_loginurl=$url;
  75. }
  76. public function getLoginUrl() {
  77. return $this->_loginurl;
  78. }
  79. public static function isRoot() { return getSessionVar('root'); }
  80. public static function admin_mode() { return getSessionVar('ADMIN'); }
  81. public static function getLangData($l=NULL,$redo=false,$unsetcache=false) {
  82. static $computed_lang=NULL;
  83. if(empty($l) && !$redo && !empty($computed_lang)) return $computed_lang;
  84. $lg=TZR_DEFAULT_LANG;
  85. if(XShell::admini_mode()) {
  86. if(!empty($l)) $lg=$l;
  87. elseif(!empty($_REQUEST['LANG_DATA'])) $lg=$_REQUEST['LANG_DATA'];
  88. elseif(!empty($_SESSION['LANG_DATA'])) $lg=$_SESSION['LANG_DATA'];
  89. elseif(!empty($_REQUEST['_lang'])) $lg=$_REQUEST['_lang'];
  90. elseif(!empty($GLOBALS['LANG_DATA'])) $lg=$GLOBALS['LANG_DATA'];
  91. } else {
  92. if(!empty($_REQUEST['LANG_DATA'])) $lg=$_REQUEST['LANG_DATA'];
  93. elseif(!empty($_REQUEST['_lang'])) $lg=$_REQUEST['_lang'];
  94. elseif(!empty($_SESSION['LANG_DATA'])) $lg=$_SESSION['LANG_DATA'];
  95. }
  96. if(!array_key_exists($lg,$GLOBALS['TZR_LANGUAGES'])) $lg=TZR_DEFAULT_LANG;
  97. if(empty($l)) $computed_lang=$lg;
  98. if($unsetcache) $computed_lang=NULL;
  99. return $lg;
  100. }
  101. public static function getLangTrad($l=NULL,$notrad=NULL) {
  102. if(XShell::admini_mode() && empty($_REQUEST['_notrad']) && empty($notrad)) {
  103. $lg=NULL;
  104. if(!empty($l)) $lg=TZR_DEFAULT_LANG;
  105. elseif(!empty($_REQUEST['LANG_TRAD'])) $lg=TZR_DEFAULT_LANG;
  106. elseif(!empty($_SESSION['LANG_TRAD'])) $lg=TZR_DEFAULT_LANG;
  107. if(array_key_exists($lg, $GLOBALS['TZR_LANGUAGES'])) return $lg;
  108. }
  109. return NULL;
  110. }
  111. public static function getLangUser($l=NULL) {
  112. if(empty($l)) {
  113. if(!empty($_REQUEST['LANG_USER'])) $l=$_REQUEST['LANG_USER'];
  114. elseif(!empty($_SESSION['LANG_USER'])) $l=$_SESSION['LANG_USER'];
  115. elseif(!empty($_REQUEST['_lang'])) $l=$_REQUEST['_lang'];
  116. elseif(!empty($GLOBALS['LANG_USER'])) $l=$GLOBALS['LANG_USER'];
  117. }
  118. if(array_key_exists($l, $GLOBALS['TZR_ADMIN_LANGUAGES'])) return $l;
  119. else return TZR_DEFAULT_LANG;
  120. }
  121. /// Recupere le _next en cours
  122. public static function getNext(){
  123. return $GLOBALS['XSHELL']->_next;
  124. }
  125. /// Change le _next
  126. public static function setNext($url=NULL) {
  127. $_REQUEST['_next']='';
  128. if(empty($url)) $GLOBALS['XSHELL']->_next=NULL;
  129. elseif(preg_match('@(^https?://|^/)@',$url)) $GLOBALS['XSHELL']->_next=$url;
  130. else $GLOBALS['XSHELL']->_next=$GLOBALS['TZR_SESSION_MANAGER']::complete_self().$url;
  131. }
  132. /// Ajoute des données au _next
  133. public static function setNextData($var, $value) {
  134. $GLOBALS['XSHELL']->_nextData[$var]=$value;
  135. }
  136. /// Ajoute un fichier au _next
  137. public static function setNextFile($file, $name, $mime) {
  138. $GLOBALS['XSHELL']->_nextData['filename'] = $file;
  139. $GLOBALS['XSHELL']->_nextData['fileoriginalname'] = $name;
  140. $GLOBALS['XSHELL']->_nextData['filemime'] = $mime;
  141. }
  142. /// Vérifie si un _next est positionné
  143. public static function hasNext(){
  144. if(!empty($GLOBALS['XSHELL']->next) || !empty($_REQUEST['_next'])) return true;
  145. return false;
  146. }
  147. static function admini_mode() {
  148. return defined('TZR_ADMINI');
  149. }
  150. function showStack($ar) {
  151. $ar2=debug_backtrace() ;
  152. VarDump($ar2,false,0,2,1);
  153. }
  154. function quit($ar) {
  155. if(XIni::get('debug_die')>0) {
  156. $ar2=debug_backtrace() ;
  157. if(is_string($ar)) $message =$ar;
  158. if(is_array($ar)) $message =$ar['message'];
  159. $level = XIni::get('debug_die');
  160. $details = XIni::get('debug_details');
  161. $ex=VarDump($ar2,false,0,$level,$details,true);
  162. }
  163. XLogs::critical("XShell::quit",' panic '.$message.' '.$_SERVER['QUERY_STRING']).' '.$ex;
  164. exit();
  165. }
  166. /// Affecte une variable smarty $prefix_ (ecrase la valeur existantes)
  167. static function &toScreen1($prefix,&$p1) {
  168. if($prefix!=TZR_RETURN_DATA) $GLOBALS['XSHELL']->tpldata[$prefix]=$p1;
  169. return $p1;
  170. }
  171. /// Affecte une variable smarty $prefix_$p1 (ecrase la valeur existantes)
  172. static function &toScreen2($prefix,$p1,$p2) {
  173. if($prefix!=TZR_RETURN_DATA){
  174. if(!@is_array($GLOBALS['XSHELL']->tpldata[$prefix][$p1])) $GLOBALS['XSHELL']->tpldata[$prefix][$p1]=array();
  175. $GLOBALS['XSHELL']->tpldata[$prefix][$p1]=$p2;
  176. }
  177. return $p2;
  178. }
  179. /// Affecte une variable smarty $prefix_ (merge avec la valeur existantes)
  180. static function toScreen1Merge($prefix,&$p1){
  181. if($prefix!=TZR_RETURN_DATA){
  182. if(is_array($GLOBALS['XSHELL']->tpldata[$prefix]))
  183. $GLOBALS['XSHELL']->tpldata[$prefix]=array_merge_recursive($GLOBALS['XSHELL']->tpldata[$prefix],$p1);
  184. else
  185. $GLOBALS['XSHELL']->tpldata[$prefix]=$p1;
  186. }
  187. return $p1;
  188. }
  189. /// Supprime la variable smarty $prefix_ ou $prefix_$p1
  190. static function clearScreen($prefix,$p1=NULL){
  191. if(!empty($p1)) unset($GLOBALS['XSHELL']->tpldata[$prefix][$p1]);
  192. else unset($GLOBALS['XSHELL']->tpldata[$prefix]);
  193. }
  194. static function &from_screen($prefix,$var=NULL) {
  195. if($prefix==TZR_RETURN_DATA) return NULL;
  196. if(isset($var)) return $GLOBALS['XSHELL']->tpldata[$prefix][$var];
  197. else return $GLOBALS['XSHELL']->tpldata[$prefix];
  198. }
  199. static function exit_tzr($message=NULL) {
  200. XLogs::_closeLogger();
  201. exit();
  202. }
  203. // empile une info dans la pile de la barre de navig
  204. //
  205. function push_navbar($label, $url) {
  206. if(!is_array($this->tpldata['nav'])) $this->tpldata['nav']=array();
  207. if(!is_array($this->tpldata['nav']['url'])) {
  208. $this->tpldata['nav']['url']=array();
  209. $this->tpldata['nav']['label']=array();
  210. }
  211. array_push($this->tpldata['nav']['url'],$url);
  212. array_push($this->tpldata['nav']['label'],$label);
  213. if(empty($this->tpldata['nav']['lastlabel'])) {
  214. $this->tpldata['nav']['lasturl']=$url;
  215. $this->tpldata['nav']['lastlabel']=$label;
  216. }
  217. }
  218. // depile une info dans la pile de la barre de navig
  219. //
  220. function pop_navbar() {
  221. if(is_array($this->tpldata['nav'])) {
  222. $i=count($this->tpldata['nav']['url']);
  223. unset($this->tpldata['nav']['url'][$i-1]);
  224. unset($this->tpldata['nav']['label'][$i-1]);
  225. }
  226. }
  227. function title_navbar($title) {
  228. $this->tpldata['nav']['title']=$title;
  229. }
  230. // nettoyage de la barre de navig
  231. //
  232. function clear_navbar() {
  233. if(@is_array($this->tpldata['nav'])) {
  234. $this->tpldata['nav']['label']=array();
  235. $this->tpldata['nav']['url']=array();
  236. } else {
  237. $this->tpldata['nav']=array();
  238. }
  239. }
  240. public function set_navbar_pagetitle($label, $url) {
  241. $this->tpldata['nav']['lasturl']=$url;
  242. $this->tpldata['nav']['lastlabel']=$label;
  243. }
  244. // appel d'une fonction a chaque affichage de page
  245. function set_callback($f) {
  246. unset($this->_callback);
  247. $this->_callback=array();
  248. $this->_callback[]=$f;
  249. }
  250. function add_callback($f) {
  251. $this->_callback[]=$f;
  252. }
  253. function _load_user($ar=NULL) {
  254. if(issetSessionVar('UID'))
  255. $GLOBALS['XUSER'] = new XUser(array('UID'=>getSessionVar('UID')));
  256. else
  257. $GLOBALS['XUSER'] = new XUser();
  258. $lang = $GLOBALS['XUSER']->language();
  259. if(empty($_SESSION['LANG_DATA'])) {
  260. if(!empty($lang[0])) {
  261. $GLOBALS['LANG_DATA']=$lang[0];
  262. }
  263. if(empty($GLOBALS['LANG_DATA'])) $GLOBALS['LANG_DATA']=TZR_DEFAULT_LANG;
  264. }
  265. if(empty($_SESSION['LANG_USER'])) {
  266. if(!empty($lang[1])) {
  267. $GLOBALS['LANG_USER']=$lang[1];
  268. }
  269. if(empty($GLOBALS['LANG_USER'])) $GLOBALS['LANG_USER']=TZR_DEFAULT_LANG;
  270. }
  271. }
  272. private function security_check($class, $function, $moid, $lang, &$koid, $interactive=false) {
  273. if(is_array($koid)){
  274. $all=$koid;
  275. foreach($all as $k=>&$v){
  276. if(Kernel::isAKoid($k)){
  277. $ok=$this->security_check($class,$function,$moid,$lang,$k,true);
  278. }else{
  279. $ok=$this->security_check($class,$function,$moid,$lang,$v,true);
  280. }
  281. if(!$ok){
  282. unset($koid[$k]);
  283. }
  284. }
  285. unset($v);
  286. if(!empty($koid)) return true;
  287. else{
  288. $ok=false;
  289. $koid=$all;
  290. }
  291. if(!empty($moid)) {
  292. if(!empty($class)) $mod=new $class(array('moid'=>$moid, 'tplentry'=>TZR_RETURN_DATA));
  293. else $mod=&XModule::objectFactory(array('moid'=>$moid, 'tplentry'=>TZR_RETURN_DATA));
  294. }
  295. }else{
  296. // Assure la compatibilité avec d'ancienne url sans moid. Ne fonctionne que si la methode est publique ou en root.
  297. // Si d'autres cas sont rencontrés, il faut faire en sorte de tjs passer par un module..
  298. if(empty($moid) && XUser::secure8class($class,$function)) {
  299. $ok=true;
  300. }else{
  301. $ok=false;
  302. if(!empty($moid)) {
  303. $props=XModule::findParam($moid);
  304. if(!empty($class)) {
  305. $mod=new $class(array('moid'=>$moid, 'tplentry'=>TZR_RETURN_DATA));
  306. $ok=$mod->secure($koid,$function,$GLOBALS['XUSER'],$lang);
  307. } else {
  308. $mod=&XModule::objectFactory(array('moid'=>$moid, 'tplentry'=>TZR_RETURN_DATA));
  309. if(!empty($mod)) $ok=$mod->secure($koid,$function,$GLOBALS['XUSER'],$lang);
  310. }
  311. }
  312. }
  313. }
  314. if($ok) {
  315. debug("access ok |$class|$function|$moid|$lang|$koid|");
  316. if(!XUser::isNobody()){
  317. $suid=getSessionVar('SUID');
  318. if(!empty($suid)){
  319. $xuser=new XUser(array('UID'=>$suid));
  320. XModStats::count($koid, $lang, $moid, $xuser, $function);
  321. }else{
  322. XModStats::count($koid, $lang, $moid, $GLOBALS['XUSER'], $function);
  323. }
  324. }
  325. return true;
  326. }else{
  327. if(!is_array($koid)){
  328. $message=XLabels::getSysLabel('security.permission_denied');
  329. XLogs::update('security',$koid, $message.'<!-- |'.$class.'|'.$function.'|'.$moid.'|'.$lang.'|'.$koid.'| failed -->');
  330. XLogs::critical('security', "access denied |$class|$function|$moid|$lang|$koid| user ".XUser::get_current_user_uid());
  331. }
  332. if(!$interactive) {
  333. // Si mode ajax, on renvoie une erreur 401
  334. if(XShell::_ajax()){
  335. header("HTTP/1.1 401 Unauthorized");
  336. exit(0);
  337. }elseif(XShell::_iframeencode()){
  338. header("HTTP/1.1 401 Unauthorized");
  339. echo '401 Unauthorized';
  340. exit(0);
  341. }
  342. if($_SERVER['REQUEST_METHOD']=='GET') $next=$_SERVER["REQUEST_URI"];
  343. // Authentification CAS
  344. if(@$GLOBALS['CAS_SERVER_URL'] && @$GLOBALS['CAS_SERVER_VERSION']){
  345. debug("cas authentification (access denied |$class|$function|$moid|$lang|$koid|)");
  346. if(empty($next)) {
  347. $moidadmin=XModule::getMoid(XMODADMIN_TOID);
  348. $next=$GLOBALS['TZR_SESSION_MANAGER']::admin_url(false,false).'&template=home.html&function=portail&moid='.$moidadmin.
  349. '&message='.urlencode(XLabels::getSysLabel('xsession.reauth_lost_post'));
  350. }
  351. $cas=AuthCas::getAuthCas(array('server'=>$GLOBALS['CAS_SERVER_URL'],
  352. 'version'=>$GLOBALS['CAS_SERVER_VERSION'],
  353. 'next'=>$next
  354. )
  355. );
  356. $cas->forceAuthentication();
  357. debug("cas authentification OK (access |$class|$function|$moid|$lang|$koid|)");
  358. $sessionclass=$GLOBALS['TZR_SESSION_MANAGER'];
  359. $session=new $sessionclass();
  360. $arauth=array('withcas'=>true,'tplentry'=>TZR_RETURN_DATA);
  361. if(preg_match('/^'.preg_quote(TZR_SHARE_ADMIN_PHP,'/').'/',$GLOBALS['TZR_SESSION_MANAGER']::complete_self()))
  362. $arauth['admin']=$arauth['admini']=true;
  363. $session->procAuth($arauth);
  364. $sec=$this->security_check($class, $function, $moid, $lang, $koid, true);
  365. if(!$sec) $cas->redirectToError();
  366. else {
  367. header('Location: '.$GLOBALS['TZR_SESSION_MANAGER']::makeDomainName().$next);
  368. die();
  369. }
  370. return $sec;
  371. }
  372. if(empty($next)) {
  373. $moidadmin=XModule::getMoid(XMODADMIN_TOID);
  374. $next='&template=home.html&function=portail&moid='.$moidadmin;
  375. }
  376. // on utilise la gestion specifique d'erreur du module si elle existe
  377. if(is_object($mod)) $mod->secFailHandler($function,$koid,NULL,$next,NULL);
  378. // dans tous les cas on ne doit pas aller plus loin
  379. XShell::redirect2auth($message,$next);
  380. } else {
  381. return false;
  382. }
  383. }
  384. return true;
  385. }
  386. static function redirect2auth($message=NULL,$next=NULL){
  387. if(empty($next)) {
  388. $moidadmin=XModule::getMoid(XMODADMIN_TOID);
  389. $next='&template=home.html&function=portail&moid='.$moidadmin;
  390. }
  391. if(empty($message)) $message=XLabels::getSysLabel('security.permission_denied');
  392. header('Location: '.$GLOBALS['XSHELL']->getLoginUrl().'&message='.urlencode($message).'&next='.urlencode($next));
  393. die();
  394. }
  395. static function redirect2error($ar=NULL) {
  396. header('Location: '.$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&skip=1&template=basic/message.html&message='.rawurlencode($ar['message']));
  397. die();
  398. }
  399. // traitement du changement de langue courante
  400. //
  401. protected function _changeLang(){
  402. if(isset($_REQUEST['_lang'])) {
  403. $_SESSION['LANG_DATA'] = $_REQUEST['_lang'];
  404. $_SESSION['LANG_USER'] = $_REQUEST['_lang'];
  405. }
  406. if(isset($_REQUEST['_lang_data'])) {
  407. $_SESSION['LANG_DATA'] = $_REQUEST['_lang_data'];
  408. }
  409. if(isset($_REQUEST['_lang_user'])) {
  410. $_SESSION['LANG_USERS'] = $_REQUEST['_lang_user'];
  411. }
  412. if(isset($_REQUEST['_lang_trad'])) {
  413. $_SESSION['LANG_TRAD'] = $_REQUEST['_lang_trad'];
  414. }
  415. if(isset($_REQUEST['LANG_DATA'])) $_SESSION['LANG_DATA']=$_REQUEST['LANG_DATA'];
  416. if(isset($_REQUEST['LANG_USER'])) $_SESSION['LANG_USER']=$_REQUEST['LANG_USER'];
  417. if(isset($_REQUEST['LANG_TRAD'])) $_SESSION['LANG_TRAD']=$_REQUEST['LANG_TRAD'];
  418. }
  419. function error($ar=NULL) {
  420. $p = new XParam($ar, array("message"=>"Unexpected error"));
  421. $GLOBALS['XSHELL']->tpldata[""]["message"]=$p->get("message");
  422. }
  423. static function getTemplate(){
  424. if(isset($_REQUEST["_template"])) return $_REQUEST["_template"];
  425. elseif(isset($_REQUEST["template"])) return $_REQUEST["template"];
  426. }
  427. /// Définit les templates à utiliser
  428. function setTemplates($temp=NULL,$security2=false) {
  429. static $insidefile_checked=false;
  430. if(empty($temp)) $temp=XShell::getTemplate();
  431. else $_REQUEST["_template"]=$temp;
  432. // Changement des templates
  433. $templates=$temp;
  434. $generic=TZR_DEFAULT_TEMPLATE;
  435. // Test pour eviter que le template ne serve de cross scripting
  436. checkIfTemplateIsSecure($templates,$security2);
  437. // Tests sur insidefile s'il existe
  438. if(!$insidefile_checked && !empty($_REQUEST['insidefile'])) checkIfTemplateIsSecure($_REQUEST['insidefile'],true);
  439. if(!$insidefile_checked && defined('TZR_ALLOW_USER_TEMPLATES') &&
  440. !empty($_REQUEST['insidefile']) && file_exists($GLOBALS['USER_TEMPLATES_DIR'].$_REQUEST['insidefile'])) {
  441. $_REQUEST['insidefile']=$GLOBALS['USER_TEMPLATES_DIR'].$_REQUEST['insidefile'];
  442. }
  443. $insidefile_checked=true;
  444. if(!is_array($templates)) {
  445. if(!file_exists($GLOBALS['TEMPLATES_DIR'].$templates)) {
  446. if(defined('TZR_ALLOW_USER_TEMPLATES') && file_exists($GLOBALS['USER_TEMPLATES_DIR'].$templates)) {
  447. $templates=array(0=>$GLOBALS['USER_TEMPLATES_DIR'].$templates);
  448. }
  449. }
  450. }
  451. if(!empty($_REQUEST['insidefile']))
  452. XLogs::debug('XShell::setTemplates: using insidefile '.$_REQUEST['insidefile']);
  453. if(is_array($templates)) $template=$templates[0];
  454. else $template=$templates;
  455. return array($template,$templates);
  456. }
  457. function run($ar='*') {
  458. XLogs::debug('XShell::run: start');
  459. // creation des variables globales
  460. $GLOBALS['XLANG'] = new XLang;
  461. // verification des numero de version
  462. $this->_checkupgrade();
  463. // Chargement d'une page via l'url du contenu
  464. if(!empty($_REQUEST['_direct'])){
  465. header('Location: '.$GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&moid='.XModule::getMoid(XMODADMIN_TOID).
  466. '&template=home.html&function=portail&gopage='.
  467. urlencode(str_replace('&_direct=1','',$_SERVER['REQUEST_URI'])));
  468. exit(0);
  469. }
  470. // on verifie que le back est enregistre
  471. if(XShell::admini_mode() && empty($_SESSION['BACK'])) $_SESSION['BACK']=array();
  472. if(!XShell::admini_mode() && TZR_COUNT_REFERER) {
  473. XModRef::countRobot();
  474. XModRef::countReferer();
  475. }
  476. // chargement de la classe
  477. $class='';
  478. $moid = (empty($_REQUEST['moid'])?NULL:$_REQUEST['moid']);
  479. if(XShell::admini_mode()){
  480. if(empty($moid)){
  481. if(!empty($_REQUEST['_class'])) $class=$_REQUEST['_class'];
  482. elseif(!empty($_REQUEST['class'])) $class=$_REQUEST['class'];
  483. }
  484. }else{
  485. if(!empty($_REQUEST['_class'])) $class=$_REQUEST['_class'];
  486. elseif(!empty($_REQUEST['class'])) $class=$_REQUEST['class'];
  487. }
  488. // chargement de la function
  489. if(!empty($_REQUEST['_function'])) $f=$_REQUEST['_function'];
  490. elseif(!empty($_REQUEST['function'])) $f=$_REQUEST['function'];
  491. // insertion et traitement du back
  492. if((XShell::admini_mode() || !empty($this->activeHistory)) && ($f!='back')) {
  493. $this->getBdx();
  494. $skip=!empty($_REQUEST['_skip']) || !empty($_REQUEST['skip']) || $f=='goto1';
  495. if(empty($skip)) $this->insert_back();
  496. } elseif($f=='back') {
  497. $this->back();
  498. $this->run($ar);
  499. return;
  500. }
  501. // on regarde si il s'agit d'une url 'simple' c'est a dire qu'on
  502. // ne calcule rien dans les callback etc.
  503. $this->_raw=!empty($_REQUEST['_raw'])?$_REQUEST['_raw']:0;
  504. $this->_ajax=!empty($_REQUEST['_ajax']);
  505. $this->_iframeencode=!empty($_REQUEST['_iframeencode']);
  506. list($template, $templates)=$this->setTemplates();
  507. // test pour eviter que le template ne serve de cross scripting
  508. if(!preg_match('@^([_a-z0-9\./-]*)$@i',$class))
  509. securityWarning("(e3) class <$class> is not secure",true,true);
  510. // dans le cas ou il y a une demande de changement de langue
  511. if(!empty($_REQUEST['_setlang'])) {
  512. $this->_changeLang();
  513. }
  514. // dans le cas ou on veut des chemins absolus pour les donnes
  515. if(!empty($_REQUEST['_fqn'])) {
  516. $GLOBALS['SELF_PREFIX']=$GLOBALS['HOME_ROOT_URL'].$GLOBALS['SELF_PREFIX'];
  517. }
  518. if(!XShell::admini_mode() && XIni::get('site_closed') && ($f!='error') &&
  519. ($template!='auth.html') && ($f!='procAuth'))
  520. $this->redirect2error(array('message'=>'Sorry, at this point the site is closed'));
  521. // determination du type mime de la reponse
  522. // par défaut text/html
  523. $mime='text/html';
  524. $mimes['html']='text/html';
  525. $mimes['xml']='text/xml';
  526. $mimes['svg']='image/svg+xml';
  527. $mimes['css']='text/css';
  528. $mimes['js']='application/x-javascript';
  529. $mimes['downl']='application/x-octet-stream';
  530. $mimes['txt']='text/plain';
  531. $mimes['js']='application/x-javascript';
  532. $mimes['png']='image/png';
  533. $mimes['kml']='application/vnd.google-earth.kml+xml';
  534. $mimes['json']='application/json';
  535. if(empty($_REQUEST['_mime']) && preg_match('/\.([a-z0-9]{1,6})$/i',$template,$eregs)) {
  536. $extension=$eregs[1];
  537. if(!empty($mimes[$extension]))
  538. $mime=$mimes[$extension];
  539. }
  540. if(!empty($_REQUEST['_mime']) && in_array($_REQUEST['_mime'], $mimes)) {
  541. $mime=$_REQUEST['_mime'];
  542. }
  543. $disps=array('attachment','inline');
  544. if(!empty($_REQUEST['_disp']) && in_array($_REQUEST['_disp'], $disps)) {
  545. $_disp=$_REQUEST['_disp'];
  546. }
  547. // si le cache est utilisable (Front)
  548. if($this->_cache) {
  549. $cache = new XCache(XIni::get('cache_timeout'));
  550. $cache->setCachePolicy();
  551. // essayer de servir la page depuis le cache
  552. if ($cache->delivery($template, $mime, $_disp, $ar)) {
  553. XLogs::debug('XShell::run: page delivered by cache');
  554. $this->exit_tzr();
  555. }
  556. }
  557. // ouverture d'une connexion base de donnees globales
  558. if(!isset($GLOBALS['TZR_DB'])) $GLOBALS['TZR_DB']=&DBNewConnection();
  559. // chargement de l'utilisateur
  560. $this->_load_user();
  561. // Creation de l'objet reservation si necessaire
  562. if(XModule::getMoid(XMODLOCK_TOID))
  563. $GLOBALS['XLOCK']=new XModLock();
  564. // creation de l'object de replication si necessaire
  565. if ($replication_moid = XModule::getMoid(XMODREPLICATION_TOID)) {
  566. if (XModReplication::initsetRunning())
  567. die('Initialisation en cours, patientez ...');
  568. $GLOBALS['XREPLI'] = XModule::objectFactory($replication_moid);
  569. }
  570. // creation d'un objet qui permet de charger les labels fonction de la langue
  571. $this->labels = new XLabels();
  572. XLabels::loadLabels('general');
  573. XLabels::loadLabels('xfielddef');
  574. // cas ou il y a une classe
  575. if(!empty($moid) && empty($class)) {
  576. $ob = XModule::objectFactory(array('moid'=>$moid,'interactive'=>true));
  577. XLogs::debug('XShell::run: class is empty, moid='.$moid);
  578. } elseif(!empty($class) && (strtolower($class)!=strtolower(get_class($this)))) {
  579. // dans le cas ou la classe n'existe pas encore, on essaie d'include
  580. // le fichier qui correspond a la classe
  581. if(!class_exists($class)) {
  582. header('Location: /index.php');
  583. exit;
  584. }
  585. XLogs::debug('XShell::run: class is '.$class);
  586. $ob = new $class(array('interactive'=>true));
  587. } else {
  588. XLogs::debug('XShell::run: class is empty and moid is empty');
  589. $ob=$this;
  590. $class=get_class($this);
  591. }
  592. // cas ou il y a une fonction
  593. $LANG_DATA=XShell::getLangData();
  594. if(!empty($f)) {
  595. // verification des droits : on créé un tableau avec tout les elements succeptibles d'etre utilisés
  596. if(isset($_REQUEST['oidit'])) $oid['oidit']=$_REQUEST['oidit'];
  597. if(!empty($_REQUEST['_selectedok']) && $_REQUEST['_selectedok']=='ok' && !empty($_REQUEST['_selected']))
  598. $oid['_selected']=&$_REQUEST['_selected'];
  599. if(!empty($_REQUEST['oid'])) $oid['oids']=&$_REQUEST['oid'];
  600. else $oid['oids']='';
  601. XLogs::notice('uri_decode',@$_SERVER['REQUEST_URI']."->class=$class&function=$f&oid=$oid&template=$template&moid=$moid&lang=$LANG_DATA");
  602. $this->security_check($class, $f, $moid, $LANG_DATA, $oid);
  603. $oid2='';
  604. if(isset($oid['oidit'])) $oid2=$oid['oidit'];
  605. elseif(!empty($oid['oids'])) $oid2=$oid['oids'];
  606. if(method_exists($ob, 'secObjectAccess') && !is_array($oid2)) {
  607. $ob->secObjectAccess($f, $LANG_DATA, $oid2);
  608. }
  609. // mecanisme permettant d'eviter les doubles insert en gerant deux etats
  610. if(isset($_REQUEST["uniqid"])) {
  611. $uniqid=$_REQUEST["uniqid"];
  612. if($_SESSION["LASTCOMMITEDFORM"]==$uniqid){
  613. XLogs::notice('XShell::run','Form already submitted');
  614. XShell::redirect2error(array('message'=>XLabels::getSysLabel('general','operation_duplicated','text')));
  615. }
  616. else
  617. $_SESSION["LASTCOMMITEDFORM"]=$uniqid;
  618. }
  619. }
  620. $ar2=array();
  621. if(!isset($_REQUEST['tplentry'])) $ar2['tplentry']='';
  622. $ar2['interactive']=true;
  623. // appel de la fonction de la page en cours
  624. if(!empty($f)) {
  625. $ob->$f($ar2);
  626. $this->_function=$f;
  627. }
  628. // redirection sur la page next. calcul du next eventuel.
  629. // le next positionne par l'application avec la methode setNext est prioritaire sur
  630. // la query string (_next)
  631. if (empty($this->_next) && !empty($_REQUEST['_next']))
  632. $this->setNext($_REQUEST['_next']);
  633. if(!empty($this->_next)) {
  634. if(XShell::_iframeencode())
  635. XShell::setNextData('_iframeencode',1);
  636. $more='';
  637. if(!empty($this->_nextData))
  638. $more=(strpos($this->_next,'?')===false?'?':'&').http_build_query($this->_nextData);
  639. XLogs::debug('redirect to '.$this->_next.$more);
  640. header('Location: '.$this->_next.$more);
  641. exit(0);
  642. }
  643. if(XShell::admini_mode() && XShell::_raw()<2) {
  644. // generation des menus specifiques des modules
  645. if(method_exists($ob, 'nav')) {
  646. $ar2['_function']=$f;
  647. $ob->nav($ar2);
  648. }
  649. if(method_exists($ob,'actionlist')) {
  650. $navig=&$ob->actionlist1();
  651. XShell::toScreen1('inav', $navig);
  652. }
  653. }
  654. // appel des callback
  655. if(!XShell::_raw() && !empty($this->_callback)) {
  656. for($i=0;$i<count($this->_callback);$i++) {
  657. $func=$this->_callback[$i];
  658. if(!empty($func))
  659. $this->$func();
  660. }
  661. }
  662. // si la réponse est pas déjà caculéé
  663. if (!empty($this->response) && !empty($this->response->complete)) {
  664. $display = $this->response->content;
  665. } else {
  666. list($template,$templates)=$this->setTemplates(NULL,true);
  667. // par defaut instanciation de templetisation
  668. // par defaut template en parametre
  669. if(is_array($templates)) {
  670. $template=$templates[0];
  671. } else $template=$templates;
  672. $xtemplate = new XTemplate($template);
  673. // recherche des libelles en fonction de la langue lorsqu'on est en mode admnistration.
  674. if(issetSessionVar('ADMIN') || ($template=='proc_auth.html')||($template=='auth.html')) {
  675. XLabels::loadLabels('admini');
  676. }
  677. $labels = $this->labels->get_labels(array('selectors'=>array('global'),'local'=>true));
  678. // application du template
  679. // recherche des donnees a transmettre en auto
  680. $xtemplate->set_glob(array('templates'=>&$templates));
  681. if(is_array($ar)) {
  682. $xtemplate->set_glob($ar);
  683. }
  684. if(isset($labels) && is_array($labels)) {
  685. $xtemplate->set_glob(array('labels'=>&$labels));
  686. }
  687. XLogs::debug('XShell::run: before parse file');
  688. $display = $xtemplate->parse($this->tpldata,$this->rawdata);
  689. }
  690. // mettre en cache
  691. if ($this->_cache)
  692. $cache->store($display, $template, $ar);
  693. // Suppression des parametress contextuel en session
  694. if(issetSessionVar('message')) clearSessionVar('message');
  695. if(issetSessionVar('_reloadmenu')) clearSessionVar('_reloadmenu');
  696. if(issetSessionVar('_reloadmods')) clearSessionVar('_reloadmods');
  697. // Met à jour le token d'activité
  698. if(XUser::get_current_user_uid()){
  699. XUser::updateDbSessionDataUPD('last_activity');
  700. }
  701. $charset = XLang::getCharset();
  702. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  703. header('Content-type: '.$mime.'; charset='.strtolower($charset));
  704. if(!empty($_disp)) {
  705. $filename = is_array($templates) ? $templates[0] : $templates;
  706. header('Content-disposition: '.$_disp.'; filename='.$filename);
  707. }
  708. XLogs::debug('XShell::run: start sending file');
  709. if( (empty($_SERVER['HTTP_USER_AGENT']) || substr($_SERVER['HTTP_USER_AGENT'],0,6) != "Smarty") && $charset != TZR_INTERNAL_CHARSET){
  710. convert_charset($display, TZR_INTERNAL_CHARSET, $charset);
  711. }
  712. // Dans le cas d'une soumission d'un formulaire via iframe caché, on me le réultat dans un textarea pour empecher l'execution des scripts dans l'iframe
  713. if(XShell::_iframeencode())
  714. echo '<textarea id="_iframeencode">'.@htmlentities($display,ENT_COMPAT,$charset).'</textarea>';
  715. else
  716. echo $display;
  717. XLogs::debug('XShell::run: end sending file');
  718. XLogs::debug('XShell::run: end');
  719. // log audit infos
  720. XLogs::debug(XAudit::show());
  721. return true;
  722. }
  723. static function changeTemplate($t) {
  724. $_REQUEST["_template"]=$t;
  725. }
  726. /// Insere les données de la page dans la pile historique
  727. function insert_back() {
  728. if(!is_array($_SESSION['BACK'])) $_SESSION['BACK']=array();
  729. $CTXT=array('_REQUEST'=>$_REQUEST,
  730. '_SERVER'=>array('REQUEST_URI'=>@$_SERVER['REQUEST_URI'],'REQUEST_METHOD'=>@$_SERVER['REQUEST_METHOD']));
  731. $_SESSION['BACK'][XShell::$_bdxprefix][XShell::$_bdx]=$CTXT;
  732. XShell::$_bdx++;
  733. // On supprime ce qui est trop vieux dans l'historique pour éviter de faire exploser la pile
  734. unset($_SESSION['BACK'][XShell::$_bdxprefix-TZR_BACK_STACK_SIZE-3]);
  735. unset($_SESSION['BACK'][XShell::$_bdxprefix][XShell::$_bdx-TZR_BACK_STACK_SIZE-3]);
  736. }
  737. function back() {
  738. list($p,$n)=explode('_',$_REQUEST['n']);
  739. $tokeep=array('_iframeencode','_nohistory','_bdxnewstack','LANG_DATA','LANG_TRAD','skip','_skip','_reloadmods','_reloadmenu','message','_tabs','filename','fileoriginalname','filemime');
  740. $tokeepvalues=array();
  741. if(!empty($_SESSION['BACK'][$p][$n])) {
  742. foreach($tokeep as $f) $tokeepvalues[$f]=@$_REQUEST[$f];
  743. $_REQUEST=$_SESSION['BACK'][$p][$n]['_REQUEST'];
  744. $_SERVER=array_merge($_SERVER,$_SESSION['BACK'][$p][$n]['_SERVER']);
  745. foreach($tokeepvalues as $f=>$v){
  746. if($v!==NULL) $_REQUEST[$f]=$v;
  747. else unset($_REQUEST[$f]);
  748. }
  749. } else {
  750. $ar["message"]=XLabels::getSysLabel('xsession.messages','noback');
  751. $this->redirect2error($ar);
  752. die();
  753. }
  754. }
  755. function get_back_url($delta=-1) {
  756. $topback=XShell::$_bdx+$delta-1;
  757. if(isset($_SESSION['BACK'][XShell::$_bdxprefix][$topback]) && is_array($_SESSION['BACK'][XShell::$_bdxprefix][$topback]['_REQUEST'])) {
  758. return $GLOBALS['TZR_SESSION_MANAGER']::complete_self().'&function=back&n='.XShell::$_bdxprefix.'_'.$topback;
  759. } else {
  760. return NULL;
  761. }
  762. }
  763. function redirect($ar) {
  764. if(XShell::admini_mode()) {
  765. $this->_bdx--;
  766. unset($_SESSION['BACK'][XShell::$_bdxprefix][XShell::$_bdx]);
  767. }
  768. if(is_array($ar)) {
  769. reset($ar);
  770. while(list($a, $b)=each($ar)){
  771. $_REQUEST[$a]=$b;
  772. }
  773. }
  774. $this->run($ar);
  775. $this->exit_tzr();
  776. }
  777. // gestion des upgrades
  778. protected function _checkupgrade() {
  779. $current=(int)XIni::get('console_release');
  780. $past=(int)XIni::get('upgrades_release');
  781. if(empty($past) || ($past<112)) {
  782. die('Vous devez upgrader en version 7.1 avant de passer en version 8');
  783. }
  784. if($past<$current) {
  785. if(!getLock('consoleupgrade')) exit('upgrade en cours');
  786. $ini=new XIni();
  787. for($releases=$past+1;$releases<=$current;$releases++) {
  788. XLogs::notice('checkupgrade','upgrading from '.$releases.' to '.$current);
  789. // Fait un dump de la base sans la table de logs pour alleger
  790. $foo=explode(':',$GLOBALS['DATABASE_HOST']);
  791. system('mysqldump --add-drop-table -u'.$GLOBALS['DATABASE_USER'].' -p'.$GLOBALS['DATABASE_PASSWORD'].' '.
  792. '-h'.$foo[0].(!empty($foo[1])?' -P'.$foo[1]:'').' --ignore-table '.$GLOBALS['DATABASE_NAME'].'.LOGS '.
  793. $GLOBALS['DATABASE_NAME'].'>'.TZR_TMP_DIR.'dumppre'.$releases.'.sql');
  794. include('upgrades/'.$releases.'.inc');
  795. $ini->addVariable(array('section'=>'Upgrades',
  796. 'variable'=>'upgrades_release',
  797. 'value'=>$releases));
  798. loadIni(true);
  799. echo $releases;
  800. if (isset($GLOBALS['_REQUEST']) && isset($GLOBALS['_REQUEST']['message'])){
  801. echo $GLOBALS['_REQUEST']['message'];
  802. $tmess = preg_replace("/<br( \/)?>/i", "\n", $GLOBALS['_REQUEST']['message']);
  803. bugWarning("upgrade $releases\n".$tmess, false, false);
  804. } else {
  805. echo ' ok';
  806. }
  807. die();
  808. }
  809. }
  810. }
  811. // decodage de l'url quand on arrive avec une url de la forme
  812. // /toto.html ou toto est un alias, par exemple
  813. //
  814. public function decodeRewriting($url) {
  815. $nurl="index.php?";
  816. if(preg_match('@^/([^/\.]+)\.html$@i',$url) && file_exists(TZR_WWW_DIR.$url)) {
  817. header('Content-type: text/html');
  818. @readfile(TZR_WWW_DIR.$url);
  819. die();
  820. }
  821. if(preg_match('@^/([^/\.]+)\.xml$@i',$url) && file_exists(TZR_WWW_DIR.$url)) {
  822. header('Content-type: text/xml');
  823. @readfile(TZR_WWW_DIR.$url);
  824. die();
  825. }
  826. if(preg_match('@^/GOOGLE([A-Za-z0-9]+)\.html$@',$url)) {
  827. header("HTTP/1.1 404 Not Found");
  828. exit(0);
  829. }
  830. if(preg_match('@^/noexist_([A-Za-z0-9]+)\.html$@',$url)) {
  831. header("HTTP/1.1 404 Not Found");
  832. exit(0);
  833. }
  834. $matches=array();
  835. if(preg_match('/^\/google([A-Za-z0-9]+)\.html$/',$url,$matches)) {
  836. echo 'google-site-verification: google'.$matches[1].'.html';
  837. header("HTTP/1.1 200 OK");
  838. exit(0);
  839. }
  840. if(preg_match('@^/'.TZR_REWRITING_PREFIX.'([^\.]*).(html|xml)@i',$url,$eregs)) {
  841. $rw=&$GLOBALS['TZR_REWRITING'];
  842. foreach($rw as $src => $dst) {
  843. $src=preg_replace('/(%%[0-9]+)/','',$src);
  844. $dst=preg_replace('/\(%%([0-9]+)[^\)]+\)/','{$eregs[$1]}',$dst);
  845. if(preg_match('@'.$src.'@i',$url,$eregs)) {
  846. eval("\$vars=\"$dst\";");
  847. break;
  848. }
  849. }
  850. if(!empty($vars)) {
  851. parse_str($vars, $nvars);
  852. $_REQUEST=array_merge($_REQUEST,$nvars);
  853. $nurl.='&'.$vars;
  854. }
  855. } else {
  856. /* decodage des alias */
  857. $ks = array_keys($GLOBALS['TZR_LANGUAGES']);
  858. $ks1='('.implode('|',$ks).')';
  859. if(preg_match('@^/'.$ks1.'_([^\./]+)\.html$@',$url)) {
  860. if(preg_match('@^/'.$ks1.'_oidit_([^_]+)_([^/\._]+)\.html(.*)$@',$url,$eregs)) {
  861. $params=parse_url($eregs[4]);
  862. $_REQUEST['_lang']=$eregs[1];
  863. $_REQUEST['oidit']=$eregs[2].":".$eregs[3];
  864. $nurl.="_lang=".$eregs[1]."&oidit=".$eregs[2].":".$eregs[3];
  865. } elseif(preg_match('@^/'.$ks1.'_([^_]{1}[^/\.]+)\.html(.*)$@',$url,$eregs)) {
  866. $params=parse_url($eregs[3]);
  867. $_REQUEST['_lang']=$eregs[1];
  868. $_REQUEST['alias']=$eregs[2];
  869. $nurl.="_lang=".$eregs[1]."&alias=".$eregs[2];
  870. }
  871. } else {
  872. if(preg_match('@^/oidit_([^/\._]+)_([^/\._]+)\.html(.*)$@',$url,$eregs)) {
  873. $params=parse_url($eregs[3]);
  874. $_REQUEST['oidit']=$eregs[1].":".$eregs[2];
  875. $nurl.="oidit=".$eregs[1].":".$eregs[2];
  876. } elseif(preg_match('@^/([^/\.]+)\.html(.*)$@',$url,$eregs)) {
  877. $rw = &$GLOBALS['TZR_REWRITING'];
  878. if (array_key_exists($eregs[1], $rw)) {
  879. $params = explode('&', $rw[$eregs[1]]);
  880. foreach ($params as $p) {
  881. list($k, $v) = explode('=', $p);
  882. $_REQUEST[$k] = $v;
  883. }
  884. $params = parse_url($eregs[2]);
  885. } else {
  886. $params=parse_url($eregs[2]);
  887. $_REQUEST['alias']=$eregs[1];
  888. $nurl.="alias=".$eregs[1]."&".$eregs[2];
  889. }
  890. }
  891. }
  892. }
  893. if(!empty($params)) $_REQUEST=array_merge($_REQUEST,$params);
  894. if(!empty($_REQUEST['alias']) && XSystem::tableExists('_REWRITE')){
  895. $lg=XShell::getLangData();
  896. $ors=selectQueryGetOne('select * from _REWRITE where alias="'.$_REQUEST['alias'].'" and LANG="'.$lg.'" limit 1');
  897. if(!empty($ors)){
  898. unset($_REQUEST['alias']);
  899. $_REQUEST['oidit']=$ors['rub'];
  900. parse_str($ors['cplt'],$params);
  901. if(!empty($params)) $_REQUEST=array_merge($_REQUEST,$params);
  902. }
  903. }
  904. if($nurl!="index.php?") {
  905. $_SERVER['REQUEST_URI']="/".$nurl;
  906. $GLOBALS['TZR_SELF']='/index.php';
  907. $_SERVER['SCRIPT_NAME']='/index.php';
  908. }
  909. XShell::_changeLang();
  910. XShell::getLangData(NULL,true);
  911. XLogs::debug('XShell::decoderewriting: <'.$url.'>-><'.$nurl.'>');
  912. }
  913. // encodage d'une url d'une url dynamique vers une url statique
  914. //
  915. public function encodeRewriting(&$html) {
  916. $scriptname=$GLOBALS["TZR_SELF"];
  917. if(substr($scriptname,0,1)=='/') $scriptname=substr($scriptname,1);
  918. $todst='';
  919. if(strpos($scriptname,'index.php')===false && strpos($scriptname,'mobile.php')===false) {
  920. if(preg_match('@^([a-z0-9]+)\.php$@i',$scriptname,$eregs1)) {
  921. $todst=$eregs1[1].'_';
  922. }
  923. }
  924. $limiter='("|;|#)';
  925. $rw=&$GLOBALS['TZR_REWRITING'];
  926. foreach($rw as $src => $dst) {
  927. $dst=preg_replace('/(%%[0-9]+)/','',$dst);
  928. $src=preg_replace('@\(%%([0-9]+)([^\)]+)\)@','\$\\1',$src);
  929. $dst='index.php?&*'.$dst;
  930. $dst=str_replace('?','\?', $dst);
  931. if($GLOBALS['TZR_REWRITING_CASESENSITIVE']) {
  932. $html=preg_replace('@'.$dst.'@', TZR_REWRITING_PREFIX.$src, $html);
  933. XLogs::debug("XShell::encodeRewritingCaseSensitive: $dst -> $src");
  934. } else {
  935. $html=preg_replace('@'.$dst.'@i', TZR_REWRITING_PREFIX.$src, $html);
  936. XLogs::debug("XShell::encodeRewriting: $dst -> $src");
  937. }
  938. }
  939. /* rewriting avec les alias */
  940. if(count($GLOBALS['TZR_LANGUAGES'])>1) {
  941. $html=preg_replace('@'.$scriptname.'\?&*_lang=([A-Z]{2})&amp;alias=([A-Za-z0-9_-]{2,80})("|;|`|\#|<)'.'@',
  942. $todst.'$1_$2.html$3',$html);
  943. $html=preg_replace('@'.$scriptname.'\?&*_lang=([A-Z]{2})&amp;oidit=([A-Za-z0-9:]{2,10}):([A-Za-z0-9]{2,40})("|;|\#|`|<)@',
  944. $todst.'$1_oidit_$2_$3.html$4',$html);
  945. }
  946. $html=preg_replace('@'.$scriptname.'\?&*(amp;)?alias=([A-Za-z0-9_-]{2,80})("|;|`|\#|<)@',$todst.'$2.html$3',$html);
  947. $html=preg_replace('@'.$scriptname.'\?&*(amp;)?oidit=([A-Za-z0-9]{2,10}):([A-Za-z0-9]{2,40})("|`|;|#)@',
  948. $todst.'oidit_$2_$3.html$4',$html);
  949. $html=preg_replace('@'.$scriptname.'\?&*(amp;)?oidit=([A-Za-z0-9:]{2,40})("|`|;|#)@',$todst.'$2.html$3',$html);
  950. }
  951. function index() {
  952. if(is_array($_REQUEST['labels'])){
  953. foreach($_REQUEST['labels'] as $l){
  954. XLabels::loadLabels($l);
  955. }
  956. }
  957. }
  958. function dummy() {
  959. return array(0=>"toto");
  960. }
  961. }
  962. ?>