Source for file init.php

Documentation is available at init.php

  1. <?php
  2. /**
  3. * Initialize all defines and includes necessary files
  4. *
  5. @package  jelix
  6. @subpackage core
  7. @author   Laurent Jouanneau
  8. @contributor Loic Mathaud, Julien Issler
  9. @copyright 2005-2010 Laurent Jouanneau
  10. @copyright 2007 Julien Issler
  11. @link     http://www.jelix.org
  12. @licence  GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  13. */
  14.  
  15.  
  16. /**
  17.  * Version number of Jelix
  18.  * @name  JELIX_VERSION
  19.  */
  20. define ('JELIX_VERSION''1.2.13');
  21.  
  22. /**
  23.  * base of namespace path used in xml files of jelix
  24.  * @name  JELIX_NAMESPACE_BASE
  25.  */
  26. define ('JELIX_NAMESPACE_BASE' 'http://jelix.org/ns/');
  27.  
  28. define ('JELIX_LIB_PATH',         dirname (__FILE__).'/');
  29. define ('JELIX_LIB_CORE_PATH',    JELIX_LIB_PATH.'core/');
  30. define ('JELIX_LIB_UTILS_PATH',   JELIX_LIB_PATH.'utils/');
  31. define ('LIB_PATH',               dirname(JELIX_LIB_PATH).'/');
  32.  
  33. define ('BYTECODE_CACHE_EXISTS'function_exists('apc_cache_info'|| function_exists('eaccelerator_info'|| function_exists('xcache_info'));
  34.  
  35. if(!defined('E_DEPRECATED'))
  36.     define ('E_DEPRECATED',8192);
  37. if(!defined('E_USER_DEPRECATED'))
  38.     define ('E_USER_DEPRECATED',16384);
  39. error_reporting (E_ALL E_STRICT);
  40.  
  41.  
  42. require (JELIX_LIB_CORE_PATH 'jICoordPlugin.iface.php');
  43. require (JELIX_LIB_CORE_PATH 'jISelector.iface.php');
  44. require (JELIX_LIB_CORE_PATH 'jIUrlEngine.iface.php');
  45. require (JELIX_LIB_CORE_PATH 'jErrorHandler.lib.php');
  46. require (JELIX_LIB_CORE_PATH 'jException.lib.php');
  47. require (JELIX_LIB_CORE_PATH 'jContext.class.php');
  48. require (JELIX_LIB_CORE_PATH 'jConfig.class.php');
  49. require (JELIX_LIB_CORE_PATH 'jSelector.class.php');
  50. require (JELIX_LIB_CORE_PATH 'selector/jSelectorModule.class.php');
  51. require (JELIX_LIB_CORE_PATH 'selector/jSelectorActFast.class.php');
  52. require (JELIX_LIB_CORE_PATH 'selector/jSelectorAct.class.php');
  53. require (JELIX_LIB_CORE_PATH 'selector/jSelectorClass.class.php');
  54. require (JELIX_LIB_CORE_PATH 'selector/jSelectorDao.class.php');
  55. require (JELIX_LIB_CORE_PATH 'selector/jSelectorForm.class.php');
  56. require (JELIX_LIB_CORE_PATH 'selector/jSelectorIface.class.php');
  57. require (JELIX_LIB_CORE_PATH 'selector/jSelectorLoc.class.php');
  58. require (JELIX_LIB_CORE_PATH 'selector/jSelectorTpl.class.php');
  59. require (JELIX_LIB_CORE_PATH 'selector/jSelectorZone.class.php');
  60. require (JELIX_LIB_CORE_PATH 'selector/jSelectorSimpleFile.class.php');
  61. require (JELIX_LIB_CORE_PATH 'selector/jSelectorFile.lib.php');
  62. require (JELIX_LIB_CORE_PATH 'jUrlBase.class.php');
  63. require (JELIX_LIB_CORE_PATH 'jUrlAction.class.php');
  64. require (JELIX_LIB_CORE_PATH 'jUrl.class.php');
  65. require (JELIX_LIB_CORE_PATH 'jCoordinator.class.php');
  66. require (JELIX_LIB_CORE_PATH 'jController.class.php');
  67. require (JELIX_LIB_CORE_PATH 'jRequest.class.php');
  68. require (JELIX_LIB_CORE_PATH 'jResponse.class.php');
  69. require (JELIX_LIB_CORE_PATH 'jBundle.class.php');
  70. require (JELIX_LIB_CORE_PATH 'jLocale.class.php');
  71. require (JELIX_LIB_CORE_PATH 'jIncluder.class.php');
  72. require (JELIX_LIB_CORE_PATH 'jSession.class.php');
  73.  
  74. /**
  75.  * The main object of Jelix which process all things
  76.  * @global jCoordinator $gJCoord 
  77.  * @name $gJCoord
  78.  */
  79. $gJCoord null;
  80.  
  81. /**
  82.  * Object that contains all configuration values
  83.  * @global stdobject $gJConfig 
  84.  * @name $gJConfig
  85.  */
  86. $gJConfig null;
  87.  
  88. /**
  89.  * contains path for __autoload function
  90.  * @global array $gLibPath 
  91.  * @name $gLibPath
  92.  * @see __autoload()
  93.  */
  94. $gLibPath=array('Db'=>JELIX_LIB_PATH.'db/''Dao'=>JELIX_LIB_PATH.'dao/',
  95.  'Forms'=>JELIX_LIB_PATH.'forms/''Event'=>JELIX_LIB_PATH.'events/',
  96.  'Tpl'=>JELIX_LIB_PATH.'tpl/''Acl'=>JELIX_LIB_PATH.'acl/''Controller'=>JELIX_LIB_PATH.'controllers/',
  97.  'Auth'=>JELIX_LIB_PATH.'auth/''Installer'=>JELIX_LIB_PATH.'installer/',
  98.  'KV'=>JELIX_LIB_PATH.'kvdb/');
  99.  
  100. /**
  101.  * function used by php to try to load an unknown class
  102.  */
  103. function jelix_autoload($class{
  104.     if(preg_match('/^j(Dao|Tpl|Acl|Event|Db|Controller|Forms|Auth|Installer|KV).*/i'$class$m)){
  105.         $f=$GLOBALS['gLibPath'][$m[1]].$class.'.class.php';
  106.     }elseif(preg_match('/^cDao(?:Record)?_(.+)_Jx_(.+)_Jx_(.+)$/'$class$m)){
  107.         // for DAO which are stored in sessions for example
  108.         $s new jSelectorDao($m[1].'~'.$m[2]$m[3]false);
  109.         if($GLOBALS['gJConfig']->compilation['checkCacheFiletime']){
  110.             // if it is needed to check the filetime, then we use jIncluder
  111.             // because perhaps we will have to recompile the dao before the include
  112.             jIncluder::inc($s);
  113.         }else{
  114.             $f $s->getCompiledFilePath();
  115.             // we should verify that the file is here and if not, we recompile
  116.             // (case where the temp has been cleaned, see bug #6062 on berlios.de)
  117.             if (!file_exists($f)) {
  118.                 jIncluder::inc($s);
  119.             }
  120.             else
  121.                 require($f);
  122.         }
  123.         return;
  124.     }else{
  125.         $f JELIX_LIB_UTILS_PATH.$class.'.class.php';
  126.     }
  127.  
  128.     if(file_exists($f)){
  129.         require($f);
  130.     }
  131. }
  132.  
  133. spl_autoload_register("jelix_autoload");
  134.  
  135. /**
  136.  * check if the application is opened. If not, it displays the yourapp/install/closed.html
  137.  * file with a http error (or lib/jelix/installer/closed.html), and exit.
  138.  * This function should be called in all entry point, before the creation of the coordinator.
  139.  * @see jAppManager
  140.  */
  141. function checkAppOpened(){
  142.     if (file_exists(JELIX_APP_CONFIG_PATH.'CLOSED')) {
  143.         $message file_get_contents(JELIX_APP_CONFIG_PATH.'CLOSED');
  144.  
  145.         if (php_sapi_name(== 'cli'{
  146.             echo "Application closed."($message?"\n$message\n":"\n");
  147.             exit(1);
  148.         }
  149.  
  150.         if (file_exists(JELIX_APP_PATH.'install/closed.html')) {
  151.             $file JELIX_APP_PATH.'install/closed.html';
  152.         }
  153.         else
  154.             $file JELIX_LIB_PATH.'installer/closed.html';
  155.  
  156.         header("HTTP/1.1 500 Application not available");
  157.         header('Content-type: text/html');
  158.         echo str_replace('%message%'$messagefile_get_contents($file));
  159.         exit(1);
  160.     }
  161. }
  162.  
  163.  
  164. /**
  165.  * check if the application is not installed. If the app is installed, an
  166.  * error message appears and the scripts ends.
  167.  * It should be called only by some scripts
  168.  * like an installation wizard, not by entry point.
  169.  */
  170. function checkAppNotInstalled({
  171.     if (isAppInstalled()) {
  172.          if (php_sapi_name(== 'cli'{
  173.             echo "Application is installed. The script cannot be runned.\n";
  174.         }
  175.         else {
  176.             header("HTTP/1.1 500 Application not available");
  177.             header('Content-type: text/plain');
  178.             echo "Application is installed. The script cannot be runned.\n";
  179.         }
  180.         exit(1);
  181.     }
  182. }
  183.  
  184. function isAppInstalled({
  185.     return file_exists(JELIX_APP_CONFIG_PATH.'installer.ini.php');
  186. }

Documentation generated on Thu, 19 Sep 2013 00:01:58 +0200 by phpDocumentor 1.4.3