blob: 4eb918b1587e11ae596a4a11bef67434a04c1754 [file] [log] [blame]
Derek Jones4b9c6292011-07-01 17:40:48 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Greg Aker0711dc82011-01-05 10:49:40 -06009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
Derek Jones218876c2010-03-02 13:11:00 -060019 * System Initialization File
Derek Allard2067d1a2008-11-13 22:59:24 +000020 *
21 * Loads the base classes and executes the request.
22 *
23 * @package CodeIgniter
24 * @subpackage codeigniter
25 * @category Front-controller
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/
28 */
29
Derek Jones218876c2010-03-02 13:11:00 -060030/*
31 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -050032 * Define the CodeIgniter Version
Derek Jones218876c2010-03-02 13:11:00 -060033 * ------------------------------------------------------
34 */
root83e7a8e2011-08-14 19:55:57 +020035 /**
36 * CodeIgniter Version
37 *
38 * @var string
39 *
40 */
Greg Akerbfbcf742011-04-07 18:33:29 -050041 define('CI_VERSION', '2.0.2');
Derek Allard2067d1a2008-11-13 22:59:24 +000042
43/*
44 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -050045 * Define the CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
Phil Sturgeonbabfb292011-03-08 21:56:08 +000046 * ------------------------------------------------------
47 */
root83e7a8e2011-08-14 19:55:57 +020048
49 /**
50 * CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
51 *
52 * @var string
53 *
54 */
Phil Sturgeon2f8b27e2011-03-08 21:56:08 +000055 define('CI_CORE', FALSE);
Phil Sturgeonbabfb292011-03-08 21:56:08 +000056
57/*
58 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -050059 * Load the global functions
Derek Allard2067d1a2008-11-13 22:59:24 +000060 * ------------------------------------------------------
61 */
Greg Aker3a746652011-04-19 10:59:47 -050062 require(BASEPATH.'core/Common.php');
Derek Allard2067d1a2008-11-13 22:59:24 +000063
64/*
65 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -050066 * Load the framework constants
Derek Allard2067d1a2008-11-13 22:59:24 +000067 * ------------------------------------------------------
68 */
Greg Aker3a746652011-04-19 10:59:47 -050069 if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
Phil Sturgeon35f64912011-03-15 21:01:39 +000070 {
Greg Aker3a746652011-04-19 10:59:47 -050071 require(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
Phil Sturgeon35f64912011-03-15 21:01:39 +000072 }
73 else
74 {
Greg Aker3a746652011-04-19 10:59:47 -050075 require(APPPATH.'config/constants.php');
Phil Sturgeon35f64912011-03-15 21:01:39 +000076 }
Derek Allard2067d1a2008-11-13 22:59:24 +000077
78/*
79 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -050080 * Define a custom error handler so we can log PHP errors
Derek Allard2067d1a2008-11-13 22:59:24 +000081 * ------------------------------------------------------
82 */
Derek Jones218876c2010-03-02 13:11:00 -060083 set_error_handler('_exception_handler');
Barry Mienydd671972010-10-04 16:33:58 +020084
Derek Jones218876c2010-03-02 13:11:00 -060085 if ( ! is_php('5.3'))
86 {
Barry Mienydd671972010-10-04 16:33:58 +020087 @set_magic_quotes_runtime(0); // Kill magic quotes
Derek Jones218876c2010-03-02 13:11:00 -060088 }
Derek Jones962d2252009-08-05 04:26:11 +000089
Derek Jones218876c2010-03-02 13:11:00 -060090/*
91 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -050092 * Set the subclass_prefix
Derek Jones218876c2010-03-02 13:11:00 -060093 * ------------------------------------------------------
94 *
Barry Mienydd671972010-10-04 16:33:58 +020095 * Normally the "subclass_prefix" is set in the config file.
96 * The subclass prefix allows CI to know if a core class is
Derek Jones218876c2010-03-02 13:11:00 -060097 * being extended via a library in the local application
Barry Mienydd671972010-10-04 16:33:58 +020098 * "libraries" folder. Since CI allows config items to be
99 * overriden via data set in the main index. php file,
100 * before proceeding we need to know if a subclass_prefix
Derek Jones4b9c6292011-07-01 17:40:48 -0500101 * override exists. If so, we will set this value now,
Derek Jones218876c2010-03-02 13:11:00 -0600102 * before any classes are loaded
Barry Mienydd671972010-10-04 16:33:58 +0200103 * Note: Since the config file data is cached it doesn't
Derek Jones218876c2010-03-02 13:11:00 -0600104 * hurt to load it here.
105 */
Barry Mienydd671972010-10-04 16:33:58 +0200106 if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
Derek Jones218876c2010-03-02 13:11:00 -0600107 {
108 get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
109 }
Eric Barnesc5bf6162011-01-30 21:17:11 -0500110
Pascal Krietef566af52010-11-09 13:03:26 -0500111/*
112 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500113 * Set a liberal script execution time limit
Pascal Krietef566af52010-11-09 13:03:26 -0500114 * ------------------------------------------------------
115 */
116 if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
117 {
118 @set_time_limit(300);
119 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000120
121/*
122 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500123 * Start the timer... tick tock tick tock...
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 * ------------------------------------------------------
125 */
Derek Jones218876c2010-03-02 13:11:00 -0600126 $BM =& load_class('Benchmark', 'core');
127 $BM->mark('total_execution_time_start');
128 $BM->mark('loading_time:_base_classes_start');
Derek Allard2067d1a2008-11-13 22:59:24 +0000129
130/*
131 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500132 * Instantiate the hooks class
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 * ------------------------------------------------------
134 */
Derek Jones218876c2010-03-02 13:11:00 -0600135 $EXT =& load_class('Hooks', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000136
137/*
138 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500139 * Is there a "pre_system" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 * ------------------------------------------------------
141 */
Derek Jones218876c2010-03-02 13:11:00 -0600142 $EXT->_call_hook('pre_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000143
144/*
145 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500146 * Instantiate the config class
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200148 */
Derek Jones218876c2010-03-02 13:11:00 -0600149 $CFG =& load_class('Config', 'core');
150
151 // Do we have any manually set config items in the index.php file?
152 if (isset($assign_to_config))
Barry Mienydd671972010-10-04 16:33:58 +0200153 {
Derek Jones218876c2010-03-02 13:11:00 -0600154 $CFG->_assign_to_config($assign_to_config);
155 }
156
157/*
158 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500159 * Instantiate the UTF-8 class
Derek Jones218876c2010-03-02 13:11:00 -0600160 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200161 *
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500162 * Note: Order here is rather important as the UTF-8
Derek Jones218876c2010-03-02 13:11:00 -0600163 * class needs to be used very early on, but it cannot
Barry Mienydd671972010-10-04 16:33:58 +0200164 * properly determine if UTf-8 can be supported until
Derek Jones218876c2010-03-02 13:11:00 -0600165 * after the Config class is instantiated.
Barry Mienydd671972010-10-04 16:33:58 +0200166 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 */
168
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500169 $UNI =& load_class('Utf8', 'core');
Barry Mienydd671972010-10-04 16:33:58 +0200170
Derek Jones218876c2010-03-02 13:11:00 -0600171/*
172 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500173 * Instantiate the URI class
Derek Jones218876c2010-03-02 13:11:00 -0600174 * ------------------------------------------------------
175 */
176 $URI =& load_class('URI', 'core');
177
178/*
179 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500180 * Instantiate the routing class and set the routing
Derek Jones218876c2010-03-02 13:11:00 -0600181 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200182 */
Derek Jones218876c2010-03-02 13:11:00 -0600183 $RTR =& load_class('Router', 'core');
184 $RTR->_set_routing();
Barry Mienydd671972010-10-04 16:33:58 +0200185
Derek Jones218876c2010-03-02 13:11:00 -0600186 // Set any routing overrides that may exist in the main index file
187 if (isset($routing))
188 {
189 $RTR->_set_overrides($routing);
190 }
191
192/*
193 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500194 * Instantiate the output class
Derek Jones218876c2010-03-02 13:11:00 -0600195 * ------------------------------------------------------
196 */
197 $OUT =& load_class('Output', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000198
199/*
200 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500201 * Is there a valid cache file? If so, we're done...
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 * ------------------------------------------------------
203 */
Derek Jones218876c2010-03-02 13:11:00 -0600204 if ($EXT->_call_hook('cache_override') === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000205 {
Derek Jones218876c2010-03-02 13:11:00 -0600206 if ($OUT->_display_cache($CFG, $URI) == TRUE)
207 {
208 exit;
209 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000211
212/*
Pascal Kriete14a0ac62011-04-05 14:55:56 -0400213 * -----------------------------------------------------
214 * Load the security class for xss and csrf support
215 * -----------------------------------------------------
216 */
217 $SEC =& load_class('Security', 'core');
218
219/*
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500221 * Load the Input class and sanitize globals
Derek Allard2067d1a2008-11-13 22:59:24 +0000222 * ------------------------------------------------------
223 */
Barry Mienydd671972010-10-04 16:33:58 +0200224 $IN =& load_class('Input', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000225
Derek Jones218876c2010-03-02 13:11:00 -0600226/*
227 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500228 * Load the Language class
Derek Jones218876c2010-03-02 13:11:00 -0600229 * ------------------------------------------------------
230 */
231 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000232
233/*
234 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500235 * Load the app controller and local controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 * ------------------------------------------------------
237 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 */
Derek Jones218876c2010-03-02 13:11:00 -0600239 // Load the base controller class
Greg Aker3a746652011-04-19 10:59:47 -0500240 require BASEPATH.'core/Controller.php';
Barry Mienydd671972010-10-04 16:33:58 +0200241
Greg Aker4abfa682010-11-10 14:44:26 -0600242 function &get_instance()
243 {
244 return CI_Controller::get_instance();
245 }
246
247
Greg Aker3a746652011-04-19 10:59:47 -0500248 if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
Greg Akerfa281352010-03-22 14:41:27 -0500249 {
Greg Aker3a746652011-04-19 10:59:47 -0500250 require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
Greg Akerfa281352010-03-22 14:41:27 -0500251 }
Barry Mienydd671972010-10-04 16:33:58 +0200252
Derek Jones218876c2010-03-02 13:11:00 -0600253 // Load the local application controller
Barry Mienydd671972010-10-04 16:33:58 +0200254 // Note: The Router class automatically validates the controller path using the router->_validate_request().
Derek Jones218876c2010-03-02 13:11:00 -0600255 // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
Greg Aker3a746652011-04-19 10:59:47 -0500256 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
Derek Jones218876c2010-03-02 13:11:00 -0600257 {
Pascal Krieteebb6f4b2010-11-10 17:09:21 -0500258 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
Derek Jones218876c2010-03-02 13:11:00 -0600259 }
Barry Mienydd671972010-10-04 16:33:58 +0200260
Greg Aker3a746652011-04-19 10:59:47 -0500261 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
Barry Mienydd671972010-10-04 16:33:58 +0200262
Derek Jones218876c2010-03-02 13:11:00 -0600263 // Set a mark point for benchmarking
264 $BM->mark('loading_time:_base_classes_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000265
266/*
267 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500268 * Security check
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 * ------------------------------------------------------
270 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500271 * None of the functions in the app controller or the
272 * loader class can be called via the URI, nor can
273 * controller functions that begin with an underscore
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 */
Derek Jones4b9c6292011-07-01 17:40:48 -0500275 $class = $RTR->fetch_class();
Derek Jones218876c2010-03-02 13:11:00 -0600276 $method = $RTR->fetch_method();
Barry Mienydd671972010-10-04 16:33:58 +0200277
Derek Jones218876c2010-03-02 13:11:00 -0600278 if ( ! class_exists($class)
Derek Jones218876c2010-03-02 13:11:00 -0600279 OR strncmp($method, '_', 1) == 0
Greg Aker63277b82010-11-09 13:46:13 -0600280 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
Derek Jones218876c2010-03-02 13:11:00 -0600281 )
282 {
283 show_404("{$class}/{$method}");
284 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000285
286/*
287 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500288 * Is there a "pre_controller" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 * ------------------------------------------------------
290 */
Derek Jones218876c2010-03-02 13:11:00 -0600291 $EXT->_call_hook('pre_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000292
293/*
294 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500295 * Instantiate the requested controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 * ------------------------------------------------------
297 */
Derek Jones218876c2010-03-02 13:11:00 -0600298 // Mark a start point so we can benchmark the controller
299 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
Barry Mienydd671972010-10-04 16:33:58 +0200300
Derek Jones218876c2010-03-02 13:11:00 -0600301 $CI = new $class();
302
303/*
304 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500305 * Is there a "post_controller_constructor" hook?
Derek Jones218876c2010-03-02 13:11:00 -0600306 * ------------------------------------------------------
307 */
308 $EXT->_call_hook('post_controller_constructor');
309
310/*
311 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500312 * Call the requested method
Derek Jones218876c2010-03-02 13:11:00 -0600313 * ------------------------------------------------------
314 */
315 // Is there a "remap" function? If so, we call it instead
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 if (method_exists($CI, '_remap'))
317 {
Pascal Kriete3431ae32010-11-09 15:19:50 -0500318 $CI->_remap($method, array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 }
320 else
321 {
322 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
323 // methods, so we'll use this workaround for consistent behavior
324 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
325 {
Eric Barnesc5bf6162011-01-30 21:17:11 -0500326 // Check and see if we are using a 404 override and use it.
327 if ( ! empty($RTR->routes['404_override']))
328 {
329 $x = explode('/', $RTR->routes['404_override']);
330 $class = $x[0];
331 $method = (isset($x[1]) ? $x[1] : 'index');
Eric Barnes5519e3d2011-02-01 13:07:37 -0500332 if ( ! class_exists($class))
333 {
Greg Aker3a746652011-04-19 10:59:47 -0500334 if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
Eric Barnes5519e3d2011-02-01 13:07:37 -0500335 {
336 show_404("{$class}/{$method}");
337 }
338
Greg Aker3a746652011-04-19 10:59:47 -0500339 include_once(APPPATH.'controllers/'.$class.'.php');
Eric Barnes5519e3d2011-02-01 13:07:37 -0500340 unset($CI);
341 $CI = new $class();
342 }
Eric Barnesc5bf6162011-01-30 21:17:11 -0500343 }
344 else
345 {
346 show_404("{$class}/{$method}");
347 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 }
349
350 // Call the requested method.
Barry Mienydd671972010-10-04 16:33:58 +0200351 // Any URI segments present (besides the class/function) will be passed to the method for convenience
352 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000354
Barry Mienydd671972010-10-04 16:33:58 +0200355
Derek Jones218876c2010-03-02 13:11:00 -0600356 // Mark a benchmark end point
357 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000358
359/*
360 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500361 * Is there a "post_controller" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 * ------------------------------------------------------
363 */
Derek Jones218876c2010-03-02 13:11:00 -0600364 $EXT->_call_hook('post_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000365
366/*
367 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500368 * Send the final rendered output to the browser
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 * ------------------------------------------------------
370 */
Derek Jones218876c2010-03-02 13:11:00 -0600371 if ($EXT->_call_hook('display_override') === FALSE)
372 {
373 $OUT->_display();
374 }
Barry Mienydd671972010-10-04 16:33:58 +0200375
Derek Allard2067d1a2008-11-13 22:59:24 +0000376/*
377 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500378 * Is there a "post_system" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 * ------------------------------------------------------
380 */
Derek Jones218876c2010-03-02 13:11:00 -0600381 $EXT->_call_hook('post_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000382
383/*
384 * ------------------------------------------------------
Derek Jones4b9c6292011-07-01 17:40:48 -0500385 * Close the DB connection if one exists
Derek Allard2067d1a2008-11-13 22:59:24 +0000386 * ------------------------------------------------------
387 */
Derek Jones218876c2010-03-02 13:11:00 -0600388 if (class_exists('CI_DB') AND isset($CI->db))
389 {
390 $CI->db->close();
391 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000392
393
394/* End of file CodeIgniter.php */
Phil Sturgeon35f64912011-03-15 21:01:39 +0000395/* Location: ./system/core/CodeIgniter.php */