PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/include/helpers/inc_front_chain_lang.php

https://github.com/timschofield/2.8
PHP | 186 lines | 113 code | 33 blank | 40 comment | 43 complexity | 99a0c7c9b306120031bf1b0f8644eab1 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?php
  2. # To see how the script locking is implemented in this script see /development/dev_docs/script_locking.txt
  3. #------begin------ This protection code was suggested by Luki R. luki@karet.org ----
  4. if (stristr($PHP_SELF,'inc_front_chain_lang.php')) die('<meta http-equiv="refresh" content="0; url=../">');
  5. #------end-----
  6. # Set to TRUE if you want to disable the time-out feature,
  7. # Once this value is taken from the database, this will be used as the last resort default value
  8. $TIME_OUT_INACTIVE=FALSE;
  9. # Set for the time out value. The format is MinutesSeconds, e.g. 530 = 5 minutes, 20 seconds or e.g. 2000 = 20 minutes, 00 seconds
  10. # Once the time-out value is taken from the database, this will be used as the last resort default value
  11. $TIME_OUT_TIME=1500;
  12. # Establish db connection
  13. require_once('inc_db_makelink.php');
  14. # The function getLang gets the language code and stores it to the lang variable
  15. # The ck_language variable is a cookie which holds the language code stored at the beginning of
  16. # browser's session. After acquiring the language code, the existence of the language table is
  17. # checked. If language table does not exist, function returns 0.
  18. #
  19. # param chk_file = filename of the language table
  20. # return = 1 if language table exists
  21. function getLang($chk_file) {
  22. global $lang, $sid;
  23. if(!isset($lang)||empty($lang)) {
  24. $ck_lang_buffer='ck_lang'.$sid;
  25. if(!isset($_COOKIE[$ck_lang_buffer])||empty($_COOKIE[$ck_lang_buffer])) include(CARE_BASE .'/include/helpers/chklang.php');
  26. else $lang=$_COOKIE[$ck_lang_buffer];
  27. }
  28. if(file_exists(CARE_BASE .'language/'.$lang.'/lang_'.$lang.'_'.$chk_file)) return 1;
  29. else return 0;
  30. }
  31. function getLangModular($chk_file) {
  32. global $lang, $sid ;
  33. if(!isset($lang)||empty($lang)) {
  34. $ck_lang_buffer='ck_lang'.$sid;
  35. if(!isset($_COOKIE[$ck_lang_buffer])||empty($_COOKIE[$ck_lang_buffer]))
  36. include(CARE_BASE .'/include/helpers/chklang.php');
  37. else
  38. $lang=$_COOKIE[$ck_lang_buffer];
  39. }
  40. if(file_exists(CARE_BASE .'modules/' . MODULE . '/language/' .$lang.'/'.LANG_FILE_MODULAR))
  41. return 1;
  42. else
  43. return 0;
  44. }
  45. # The following lines of code is the script chaining detector. It compares the sid values propagated via
  46. # the relative url with the ck_sid+sid (decrypted) cookie values. If the two don't match, a warning message will apear and
  47. # the script exits stopping the execution. If the caller script does not require chaining, it must set the
  48. # constant NO_CHAIN to 1 before including this script.
  49. if(!defined('NO_CHAIN')||NO_CHAIN!=1){
  50. $no_valid=0;
  51. if(!isset($sid)) $sid=NULL;
  52. $ck_sid_buffer='ck_sid'.$sid;
  53. define('INIT_DECODE',1); # set flag to decrypt
  54. include('inc_init_crypt.php'); # initialize crypt
  55. $clear_ck_sid = $dec_hcemd5->DecodeMimeSelfRand($_COOKIE[$ck_sid_buffer]);
  56. $tnow=date('His');
  57. // echo $tnow."<p>";
  58. $time_out=FALSE;
  59. if(!defined('NO_2LEVEL_CHK')||NO_2LEVEL_CHK!=1){
  60. # Let us check if the calling script is the time-out configuration script, if yes, then we skip the time out
  61. if (!stristr('admin_system_timeout.php',$PHP_SELF)) {
  62. # Load the global time out configs
  63. include_once(CARE_BASE .'include/core/class_globalconfig.php');
  64. if(!isset($GLOBAL_CONFIG)) $GLOBAL_CONFIG=array();
  65. $gc_obj= new GlobalConfig($GLOBAL_CONFIG);
  66. $gc_obj->getConfig('timeout_%');
  67. # If config data available, use it
  68. if($GLOBAL_CONFIG['timeout_inactive']) $TIME_OUT_INACTIVE=$GLOBAL_CONFIG['timeout_inactive'];
  69. if((int)$GLOBAL_CONFIG['timeout_time']) $TIME_OUT_TIME=(int)$GLOBAL_CONFIG['timeout_time'];
  70. if(!$TIME_OUT_INACTIVE){
  71. //echo $tnow."<br>";
  72. //echo $_SESSION['sess_tos']."<br>";
  73. //echo ($tnow-$_SESSION['sess_tos'])."<br>";
  74. # Check if session is still valid
  75. if(isset($_SESSION['sess_tos'])||isset($_SESSION['sess_tos'])){
  76. # Check if time out value is positive or not zero
  77. # current time minus start time
  78. if(($tnow - $_SESSION['sess_tos']) >= $TIME_OUT_TIME) $time_out=TRUE;
  79. else $_SESSION['sess_tos']=$tnow;
  80. }else{
  81. $time_out=TRUE;
  82. }
  83. if($time_out||!$_SESSION['sess_tos']){
  84. # Show session time out warning and exit the script to stop the module
  85. include(CARE_BASE ."include/helpers/inc_session_timeout_warning.php");
  86. exit;
  87. }else{
  88. # Reset the time-out start time
  89. $_SESSION['sess_tos']=$tnow;
  90. }
  91. }
  92. }
  93. # Decrypt the second level cookie sid and compare to sid
  94. $dec_2level = new Crypt_HCEMD5($key_2level, '');
  95. $clear_2sid = $dec_2level->DecodeMimeSelfRand($_COOKIE[('ck_2level_sid'.$sid)]);
  96. if( !$sid ||(
  97. $sid!=$clear_ck_sid)||
  98. ($sid!=$clear_2sid)||
  99. !isset($_COOKIE[$local_user.$sid])||
  100. empty($_COOKIE[$local_user.$sid])
  101. ) {
  102. $no_valid=1;
  103. }
  104. }elseif (!$sid||($sid!=$clear_ck_sid)){
  105. $no_valid=1;
  106. }else{
  107. # Reset the time-out start time
  108. $_SESSION['sess_tos']=$tnow;
  109. }
  110. if ($no_valid) {
  111. if(getLang('invalid-access-warning.php')) {
  112. header('Location:'.CARE_GUI .'language/'.$lang.'/lang_'.$lang.'_invalid-access-warning.php');
  113. }
  114. else {
  115. header('Location:'.CARE_GUI .'language/'.LANG_DEFAULT.'/lang_'.LANG_DEFAULT.'_invalid-access-warning.php');
  116. }
  117. exit;
  118. }
  119. }
  120. # The constant LANG_FILE contains the file name of the language table without the lang_xx_ component.
  121. # This constant must be set by the script that calls this file.
  122. # If the calling script does not need a language table, the constant LANG_FILE must be set to empty string ''
  123. if(defined('LANG_FILE') && LANG_FILE!='') {
  124. if(getLang(LANG_FILE)) include(CARE_BASE .'language/'.$lang.'/lang_'.$lang.'_'.LANG_FILE);
  125. else include (CARE_BASE .'language/'.LANG_DEFAULT.'/lang_'.LANG_DEFAULT.'_'.LANG_FILE);
  126. }
  127. if(defined('LANG_FILE_MODULAR') && LANG_FILE_MODULAR != '') {
  128. if(getLangModular(LANG_FILE_MODULAR))
  129. include (CARE_BASE .'modules/' . MODULE . '/language/' .$lang.'/'.LANG_FILE_MODULAR);
  130. else
  131. include (CARE_BASE .'modules/' . MODULE . '/language/' .LANG_DEFAULT.'/'.LANG_FILE_MODULAR);
  132. }
  133. # Load additional language tables
  134. /* This routine includes the language tables which are listed in the array $lang_tables */
  135. if(isset($lang_tables)&&is_array($lang_tables)&&sizeof($lang_tables)) {
  136. for($tc=0;$tc<sizeof($lang_tables);$tc++) {
  137. if(file_exists(CARE_BASE .'language/'.$lang.'/lang_'.$lang.'_'.$lang_tables[$tc]))
  138. include(CARE_BASE .'language/'.$lang.'/lang_'.$lang.'_'.$lang_tables[$tc]);
  139. else
  140. include(CARE_BASE .'language/'.LANG_DEFAULT.'/lang_'.LANG_DEFAULT.'_'.$lang_tables[$tc]);
  141. }
  142. }
  143. # Load additional environment files
  144. include_once(CARE_BASE . '/include/core/class_userconfig.php');
  145. $cfg_obj=new UserConfig;
  146. if(is_object($cfg_obj)) {
  147. $cfg_obj->getConfig($_COOKIE['ck_config']);
  148. $cfg=&$cfg_obj->buffer;
  149. }
  150. require_once('inc_img_fx.php'); # image functions
  151. # Resolve the template theme
  152. if(isset($cfg['template_theme'])&&!empty($cfg['template_theme'])) $template_theme=$cfg['template_theme'];
  153. else $template_theme = 'default';