PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/system/core/CodeIgniter.php

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