PageRenderTime 86ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/jelix/init.php

http://github.com/jelix/jelix
PHP | 277 lines | 127 code | 20 blank | 130 comment | 17 complexity | 1324643f84d943906a92ff8e34009cda MD5 | raw file
Possible License(s): BSD-3-Clause, JSON, GPL-3.0, LGPL-3.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Initialize all defines and includes necessary files
  4. *
  5. #if ENABLE_OPTIMIZED_SOURCE
  6. * Some lines of code were get from Copix project (Copix 2.3dev20050901)
  7. * and are copyrighted 2001-2005 CopixTeam (LGPL Licence)
  8. #endif
  9. * @package jelix
  10. * @subpackage core
  11. * @author Laurent Jouanneau
  12. #if ENABLE_OPTIMIZED_SOURCE
  13. * @author Croes Gerald
  14. * @contributor Loic Mathaud, Julien Issler
  15. * @copyright 2005-2012 Laurent Jouanneau
  16. * @copyright 2001-2005 CopixTeam
  17. * @copyright 2006 Loic Mathaud
  18. * @copyright 2007-2009 Julien Issler
  19. * @link http://www.copix.org
  20. #else
  21. * @contributor Loic Mathaud, Julien Issler
  22. * @copyright 2005-2012 Laurent Jouanneau
  23. * @copyright 2007 Julien Issler
  24. #endif
  25. * @link http://www.jelix.org
  26. * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  27. */
  28. #if ENABLE_PHP_JELIX
  29. if(!function_exists('jelix_version')){
  30. die('this edition of Jelix needs jelix php extension.');
  31. }
  32. #endif
  33. /**
  34. * Version number of Jelix
  35. * @name JELIX_VERSION
  36. */
  37. #expand define ('JELIX_VERSION', '__LIB_VERSION__');
  38. #ifnot ENABLE_PHP_JELIX
  39. /**
  40. * base of namespace path used in xml files of jelix
  41. * @name JELIX_NAMESPACE_BASE
  42. */
  43. define ('JELIX_NAMESPACE_BASE' , 'http://jelix.org/ns/');
  44. #endif
  45. define ('JELIX_LIB_PATH', dirname (__FILE__).'/');
  46. define ('JELIX_LIB_CORE_PATH', JELIX_LIB_PATH.'core/');
  47. define ('JELIX_LIB_UTILS_PATH', JELIX_LIB_PATH.'utils/');
  48. define ('LIB_PATH', dirname(JELIX_LIB_PATH).'/');
  49. #if WITH_BYTECODE_CACHE == 'auto'
  50. define ('BYTECODE_CACHE_EXISTS', function_exists('apc_cache_info') || function_exists('eaccelerator_info') || function_exists('xcache_info'));
  51. #elseif WITH_BYTECODE_CACHE
  52. define ('BYTECODE_CACHE_EXISTS', true);
  53. #else
  54. define ('BYTECODE_CACHE_EXISTS', false);
  55. #endif
  56. #if !PHP53ORMORE
  57. if(!defined('E_DEPRECATED'))
  58. define ('E_DEPRECATED',8192);
  59. if(!defined('E_USER_DEPRECATED'))
  60. define ('E_USER_DEPRECATED',16384);
  61. #endif
  62. error_reporting (E_ALL | E_STRICT);
  63. #if ENABLE_OPTIMIZED_SOURCE
  64. #includephp core/jApp.class.php
  65. #ifnot ENABLE_PHP_JELIX
  66. #includephp core/jICoordPlugin.iface.php
  67. #includephp core/jISelector.iface.php
  68. #includephp core/jIUrlEngine.iface.php
  69. #endif
  70. #includephp core/jBasicErrorHandler.class.php
  71. #includephp core/jException.class.php
  72. #includephp core/jContext.class.php
  73. #includephp core/jConfig.class.php
  74. #includephp core/jConfigAutoloader.class.php
  75. #includephp core/jSelector.class.php
  76. #includephp core/jServer.class.php
  77. #includephp core/selector/jSelectorModule.class.php
  78. #includephp core/selector/jSelectorActFast.class.php
  79. #includephp core/selector/jSelectorAct.class.php
  80. #includephp core/selector/jSelectorClass.class.php
  81. #includephp core/selector/jSelectorDao.class.php
  82. #includephp core/selector/jSelectorForm.class.php
  83. #includephp core/selector/jSelectorIface.class.php
  84. #includephp core/selector/jSelectorLoc.class.php
  85. #includephp core/selector/jSelectorTpl.class.php
  86. #includephp core/selector/jSelectorZone.class.php
  87. #includephp core/selector/jSelectorSimpleFile.class.php
  88. #includephp core/selector/jSelectorFile.lib.php
  89. #includephp core/jUrlBase.class.php
  90. #includephp core/jUrlAction.class.php
  91. #includephp core/jUrl.class.php
  92. #includephp core/jCoordinator.class.php
  93. #includephp core/jController.class.php
  94. #includephp core/jRequest.class.php
  95. #includephp core/jResponse.class.php
  96. #includephp core/jBundle.class.php
  97. #includephp core/jLocale.class.php
  98. #includephp core/jLog.class.php
  99. #includephp core/jIncluder.class.php
  100. #includephp core/jSession.class.php
  101. #else
  102. require (JELIX_LIB_CORE_PATH . 'jApp.class.php');
  103. #ifnot ENABLE_PHP_JELIX
  104. require (JELIX_LIB_CORE_PATH . 'jICoordPlugin.iface.php');
  105. require (JELIX_LIB_CORE_PATH . 'jISelector.iface.php');
  106. require (JELIX_LIB_CORE_PATH . 'jIUrlEngine.iface.php');
  107. #endif
  108. require (JELIX_LIB_CORE_PATH . 'jBasicErrorHandler.class.php');
  109. require (JELIX_LIB_CORE_PATH . 'jException.class.php');
  110. require (JELIX_LIB_CORE_PATH . 'jContext.class.php');
  111. require (JELIX_LIB_CORE_PATH . 'jConfig.class.php');
  112. require (JELIX_LIB_CORE_PATH . 'jConfigAutoloader.class.php');
  113. require (JELIX_LIB_CORE_PATH . 'jSelector.class.php');
  114. require (JELIX_LIB_CORE_PATH . 'jServer.class.php');
  115. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorModule.class.php');
  116. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorActFast.class.php');
  117. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorAct.class.php');
  118. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorClass.class.php');
  119. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorDao.class.php');
  120. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorForm.class.php');
  121. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorIface.class.php');
  122. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorLoc.class.php');
  123. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorTpl.class.php');
  124. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorZone.class.php');
  125. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorSimpleFile.class.php');
  126. require (JELIX_LIB_CORE_PATH . 'selector/jSelectorFile.lib.php');
  127. require (JELIX_LIB_CORE_PATH . 'jUrlBase.class.php');
  128. require (JELIX_LIB_CORE_PATH . 'jUrlAction.class.php');
  129. require (JELIX_LIB_CORE_PATH . 'jUrl.class.php');
  130. require (JELIX_LIB_CORE_PATH . 'jCoordinator.class.php');
  131. require (JELIX_LIB_CORE_PATH . 'jController.class.php');
  132. require (JELIX_LIB_CORE_PATH . 'jRequest.class.php');
  133. require (JELIX_LIB_CORE_PATH . 'jResponse.class.php');
  134. require (JELIX_LIB_CORE_PATH . 'jBundle.class.php');
  135. require (JELIX_LIB_CORE_PATH . 'jLocale.class.php');
  136. require (JELIX_LIB_CORE_PATH . 'jLog.class.php');
  137. require (JELIX_LIB_CORE_PATH . 'jIncluder.class.php');
  138. require (JELIX_LIB_CORE_PATH . 'jSession.class.php');
  139. #endif
  140. /**
  141. * The main object of Jelix which process all things
  142. * @global jCoordinator $gJCoord
  143. * @name $gJCoord
  144. * @deprecated use jApp::coord() instead
  145. */
  146. $gJCoord = null;
  147. /**
  148. * Object that contains all configuration values
  149. * @global stdobject $gJConfig
  150. * @name $gJConfig
  151. * @deprecated use jApp::config() instead
  152. */
  153. $gJConfig = null;
  154. /**
  155. * contains path for __autoload function
  156. * @global array $gLibPath
  157. * @name $gLibPath
  158. * @see __autoload()
  159. */
  160. $gLibPath=array('Db'=>JELIX_LIB_PATH.'db/', 'Dao'=>JELIX_LIB_PATH.'dao/',
  161. 'Forms'=>JELIX_LIB_PATH.'forms/', 'Event'=>JELIX_LIB_PATH.'events/',
  162. 'Tpl'=>JELIX_LIB_PATH.'tpl/', 'Controller'=>JELIX_LIB_PATH.'controllers/',
  163. 'Auth'=>JELIX_LIB_PATH.'auth/', 'Installer'=>JELIX_LIB_PATH.'installer/',
  164. 'KV'=>JELIX_LIB_PATH.'kvdb/', 'Pref'=>JELIX_LIB_PATH.'pref/');
  165. /**
  166. * function used by php to try to load an unknown class
  167. */
  168. function jelix_autoload($class) {
  169. if(preg_match('/^j(Dao|Tpl|Event|Db|Controller|Forms|Auth|Installer|KV|Pref).*/i', $class, $m)){
  170. $f=$GLOBALS['gLibPath'][$m[1]].$class.'.class.php';
  171. }
  172. elseif($class == 'jAcl2'){
  173. $f = JELIX_LIB_PATH.'acl/jAcl2.class.php';
  174. }
  175. elseif(preg_match('/^cDao(?:Record)?_(.+)_Jx_(.+)_Jx_(.+)$/', $class, $m)){
  176. // for DAO which are stored in sessions for example
  177. $s = new jSelectorDao($m[1].'~'.$m[2], $m[3], false);
  178. if(jApp::config()->compilation['checkCacheFiletime']){
  179. // if it is needed to check the filetime, then we use jIncluder
  180. // because perhaps we will have to recompile the dao before the include
  181. jIncluder::inc($s);
  182. }else{
  183. $f = $s->getCompiledFilePath();
  184. // we should verify that the file is here and if not, we recompile
  185. // (case where the temp has been cleaned, see bug #6062 on berlios.de)
  186. if (!file_exists($f)) {
  187. jIncluder::inc($s);
  188. }
  189. else
  190. require($f);
  191. }
  192. return;
  193. }else{
  194. $f = JELIX_LIB_UTILS_PATH.$class.'.class.php';
  195. }
  196. if(file_exists($f)){
  197. require($f);
  198. }
  199. }
  200. spl_autoload_register("jelix_autoload");
  201. /**
  202. * check if the application is opened. If not, it displays the yourapp/install/closed.html
  203. * file with a http error (or lib/jelix/installer/closed.html), and exit.
  204. * This function should be called in all entry point, before the creation of the coordinator.
  205. * @see jAppManager
  206. * @todo migrate the code to jAppManager or jApp
  207. */
  208. function checkAppOpened() {
  209. if (!jApp::isInit()) {
  210. header("HTTP/1.1 500 Application not available");
  211. header('Content-type: text/html');
  212. echo "checkAppOpened: jApp is not initialized!";
  213. exit(1);
  214. }
  215. if (file_exists(jApp::configPath('CLOSED'))) {
  216. $message = file_get_contents(jApp::configPath('CLOSED'));
  217. if (jServer::isCLI()) {
  218. echo "Application closed.". ($message?"\n$message\n":"\n");
  219. exit(1);
  220. }
  221. if (file_exists(jApp::appPath('install/closed.html'))) {
  222. $file = jApp::appPath('install/closed.html');
  223. }
  224. else
  225. $file = JELIX_LIB_PATH.'installer/closed.html';
  226. header("HTTP/1.1 500 Application not available");
  227. header('Content-type: text/html');
  228. echo str_replace('%message%', $message, file_get_contents($file));
  229. exit(1);
  230. }
  231. }
  232. /**
  233. * check if the application is not installed. If the app is installed, an
  234. * error message appears and the scripts ends.
  235. * It should be called only by some scripts
  236. * like an installation wizard, not by an entry point.
  237. * @todo migrate the code to jAppManager or jApp
  238. */
  239. function checkAppNotInstalled() {
  240. if (isAppInstalled()) {
  241. if (jServer::isCLI()) {
  242. echo "Application is installed. The script cannot be runned.\n";
  243. }
  244. else {
  245. header("HTTP/1.1 500 Application not available");
  246. header('Content-type: text/plain');
  247. echo "Application is installed. The script cannot be runned.\n";
  248. }
  249. exit(1);
  250. }
  251. }
  252. /**
  253. * @todo migrate the code to jAppManager or jApp
  254. */
  255. function isAppInstalled() {
  256. return file_exists(jApp::configPath('installer.ini.php'));
  257. }