Advertisement
pisio

/* Location: ./system/core/CodeIgniter.php */

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