PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/site/system/core/CodeIgniter.php

https://bitbucket.org/thiscode/thiscode-shop
PHP | 402 lines | 141 code | 50 blank | 211 comment | 27 complexity | 1b14d0f4d129ab266f8fd4e887fa8d70 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * System Initialization File
  18. *
  19. * Loads the base classes and executes the request.
  20. *
  21. * @package CodeIgniter
  22. * @subpackage codeigniter
  23. * @category Front-controller
  24. * @author ExpressionEngine Dev Team
  25. * @link http://codeigniter.com/user_guide/
  26. */
  27. /**
  28. * CodeIgniter Version
  29. *
  30. * @var string
  31. *
  32. */
  33. define('CI_VERSION', '2.1.2');
  34. /**
  35. * CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
  36. *
  37. * @var boolean
  38. *
  39. */
  40. define('CI_CORE', FALSE);
  41. /*
  42. * ------------------------------------------------------
  43. * Load the global functions
  44. * ------------------------------------------------------
  45. */
  46. require(BASEPATH.'core/Common.php');
  47. /*
  48. * ------------------------------------------------------
  49. * Load the framework constants
  50. * ------------------------------------------------------
  51. */
  52. if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
  53. {
  54. require(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
  55. }
  56. else
  57. {
  58. require(APPPATH.'config/constants.php');
  59. }
  60. /*
  61. * ------------------------------------------------------
  62. * Define a custom error handler so we can log PHP errors
  63. * ------------------------------------------------------
  64. */
  65. set_error_handler('_exception_handler');
  66. if ( ! is_php('5.3'))
  67. {
  68. @set_magic_quotes_runtime(0); // Kill magic quotes
  69. }
  70. /*
  71. * ------------------------------------------------------
  72. * Set the subclass_prefix
  73. * ------------------------------------------------------
  74. *
  75. * Normally the "subclass_prefix" is set in the config file.
  76. * The subclass prefix allows CI to know if a core class is
  77. * being extended via a library in the local application
  78. * "libraries" folder. Since CI allows config items to be
  79. * overriden via data set in the main index. php file,
  80. * before proceeding we need to know if a subclass_prefix
  81. * override exists. If so, we will set this value now,
  82. * before any classes are loaded
  83. * Note: Since the config file data is cached it doesn't
  84. * hurt to load it here.
  85. */
  86. if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
  87. {
  88. get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
  89. }
  90. /*
  91. * ------------------------------------------------------
  92. * Set a liberal script execution time limit
  93. * ------------------------------------------------------
  94. */
  95. if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
  96. {
  97. @set_time_limit(300);
  98. }
  99. /*
  100. * ------------------------------------------------------
  101. * Start the timer... tick tock tick tock...
  102. * ------------------------------------------------------
  103. */
  104. $BM =& load_class('Benchmark', 'core');
  105. $BM->mark('total_execution_time_start');
  106. $BM->mark('loading_time:_base_classes_start');
  107. /*
  108. * ------------------------------------------------------
  109. * Instantiate the hooks class
  110. * ------------------------------------------------------
  111. */
  112. $EXT =& load_class('Hooks', 'core');
  113. /*
  114. * ------------------------------------------------------
  115. * Is there a "pre_system" hook?
  116. * ------------------------------------------------------
  117. */
  118. $EXT->_call_hook('pre_system');
  119. /*
  120. * ------------------------------------------------------
  121. * Instantiate the config class
  122. * ------------------------------------------------------
  123. */
  124. $CFG =& load_class('Config', 'core');
  125. // Do we have any manually set config items in the index.php file?
  126. if (isset($assign_to_config))
  127. {
  128. $CFG->_assign_to_config($assign_to_config);
  129. }
  130. /*
  131. * ------------------------------------------------------
  132. * Instantiate the UTF-8 class
  133. * ------------------------------------------------------
  134. *
  135. * Note: Order here is rather important as the UTF-8
  136. * class needs to be used very early on, but it cannot
  137. * properly determine if UTf-8 can be supported until
  138. * after the Config class is instantiated.
  139. *
  140. */
  141. $UNI =& load_class('Utf8', 'core');
  142. /*
  143. * ------------------------------------------------------
  144. * Instantiate the URI class
  145. * ------------------------------------------------------
  146. */
  147. $URI =& load_class('URI', 'core');
  148. /*
  149. * ------------------------------------------------------
  150. * Instantiate the routing class and set the routing
  151. * ------------------------------------------------------
  152. */
  153. $RTR =& load_class('Router', 'core');
  154. $RTR->_set_routing();
  155. // Set any routing overrides that may exist in the main index file
  156. if (isset($routing))
  157. {
  158. $RTR->_set_overrides($routing);
  159. }
  160. /*
  161. * ------------------------------------------------------
  162. * Instantiate the output class
  163. * ------------------------------------------------------
  164. */
  165. $OUT =& load_class('Output', 'core');
  166. /*
  167. * ------------------------------------------------------
  168. * Is there a valid cache file? If so, we're done...
  169. * ------------------------------------------------------
  170. */
  171. if ($EXT->_call_hook('cache_override') === FALSE)
  172. {
  173. if ($OUT->_display_cache($CFG, $URI) == TRUE)
  174. {
  175. exit;
  176. }
  177. }
  178. /*
  179. * -----------------------------------------------------
  180. * Load the security class for xss and csrf support
  181. * -----------------------------------------------------
  182. */
  183. $SEC =& load_class('Security', 'core');
  184. /*
  185. * ------------------------------------------------------
  186. * Load the Input class and sanitize globals
  187. * ------------------------------------------------------
  188. */
  189. $IN =& load_class('Input', 'core');
  190. /*
  191. * ------------------------------------------------------
  192. * Load the Language class
  193. * ------------------------------------------------------
  194. */
  195. $LANG =& load_class('Lang', 'core');
  196. /*
  197. * ------------------------------------------------------
  198. * Load the app controller and local controller
  199. * ------------------------------------------------------
  200. *
  201. */
  202. // Load the base controller class
  203. require BASEPATH.'core/Controller.php';
  204. function &get_instance()
  205. {
  206. return CI_Controller::get_instance();
  207. }
  208. if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
  209. {
  210. require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
  211. }
  212. // Load the local application controller
  213. // Note: The Router class automatically validates the controller path using the router->_validate_request().
  214. // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
  215. if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
  216. {
  217. show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
  218. }
  219. include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
  220. // Set a mark point for benchmarking
  221. $BM->mark('loading_time:_base_classes_end');
  222. /*
  223. * ------------------------------------------------------
  224. * Security check
  225. * ------------------------------------------------------
  226. *
  227. * None of the functions in the app controller or the
  228. * loader class can be called via the URI, nor can
  229. * controller functions that begin with an underscore
  230. */
  231. $class = $RTR->fetch_class();
  232. $method = $RTR->fetch_method();
  233. if ( ! class_exists($class)
  234. OR strncmp($method, '_', 1) == 0
  235. OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
  236. )
  237. {
  238. if ( ! empty($RTR->routes['404_override']))
  239. {
  240. $x = explode('/', $RTR->routes['404_override']);
  241. $class = $x[0];
  242. $method = (isset($x[1]) ? $x[1] : 'index');
  243. if ( ! class_exists($class))
  244. {
  245. if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
  246. {
  247. show_404("{$class}/{$method}");
  248. }
  249. include_once(APPPATH.'controllers/'.$class.'.php');
  250. }
  251. }
  252. else
  253. {
  254. show_404("{$class}/{$method}");
  255. }
  256. }
  257. /*
  258. * ------------------------------------------------------
  259. * Is there a "pre_controller" hook?
  260. * ------------------------------------------------------
  261. */
  262. $EXT->_call_hook('pre_controller');
  263. /*
  264. * ------------------------------------------------------
  265. * Instantiate the requested controller
  266. * ------------------------------------------------------
  267. */
  268. // Mark a start point so we can benchmark the controller
  269. $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
  270. $CI = new $class();
  271. /*
  272. * ------------------------------------------------------
  273. * Is there a "post_controller_constructor" hook?
  274. * ------------------------------------------------------
  275. */
  276. $EXT->_call_hook('post_controller_constructor');
  277. /*
  278. * ------------------------------------------------------
  279. * Call the requested method
  280. * ------------------------------------------------------
  281. */
  282. // Is there a "remap" function? If so, we call it instead
  283. if (method_exists($CI, '_remap'))
  284. {
  285. $CI->_remap($method, array_slice($URI->rsegments, 2));
  286. }
  287. else
  288. {
  289. // is_callable() returns TRUE on some versions of PHP 5 for private and protected
  290. // methods, so we'll use this workaround for consistent behavior
  291. if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
  292. {
  293. // Check and see if we are using a 404 override and use it.
  294. if ( ! empty($RTR->routes['404_override']))
  295. {
  296. $x = explode('/', $RTR->routes['404_override']);
  297. $class = $x[0];
  298. $method = (isset($x[1]) ? $x[1] : 'index');
  299. if ( ! class_exists($class))
  300. {
  301. if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
  302. {
  303. show_404("{$class}/{$method}");
  304. }
  305. include_once(APPPATH.'controllers/'.$class.'.php');
  306. unset($CI);
  307. $CI = new $class();
  308. }
  309. }
  310. else
  311. {
  312. show_404("{$class}/{$method}");
  313. }
  314. }
  315. // Call the requested method.
  316. // Any URI segments present (besides the class/function) will be passed to the method for convenience
  317. call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
  318. }
  319. // Mark a benchmark end point
  320. $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
  321. /*
  322. * ------------------------------------------------------
  323. * Is there a "post_controller" hook?
  324. * ------------------------------------------------------
  325. */
  326. $EXT->_call_hook('post_controller');
  327. /*
  328. * ------------------------------------------------------
  329. * Send the final rendered output to the browser
  330. * ------------------------------------------------------
  331. */
  332. if ($EXT->_call_hook('display_override') === FALSE)
  333. {
  334. $OUT->_display();
  335. }
  336. /*
  337. * ------------------------------------------------------
  338. * Is there a "post_system" hook?
  339. * ------------------------------------------------------
  340. */
  341. $EXT->_call_hook('post_system');
  342. /*
  343. * ------------------------------------------------------
  344. * Close the DB connection if one exists
  345. * ------------------------------------------------------
  346. */
  347. if (class_exists('CI_DB') AND isset($CI->db))
  348. {
  349. $CI->db->close();
  350. }
  351. /* End of file CodeIgniter.php */
  352. /* Location: ./system/core/CodeIgniter.php */