blob: 03b25ab9eaf98d23c81888182e90b01312bf5a6f [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
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 * ------------------------------------------------------
32 * Define the CodeIgniter Version
33 * ------------------------------------------------------
34 */
Greg Akerbfbcf742011-04-07 18:33:29 -050035 define('CI_VERSION', '2.0.2');
Derek Allard2067d1a2008-11-13 22:59:24 +000036
37/*
38 * ------------------------------------------------------
Phil Sturgeonbabfb292011-03-08 21:56:08 +000039 * Define the CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
40 * ------------------------------------------------------
41 */
Phil Sturgeon2f8b27e2011-03-08 21:56:08 +000042 define('CI_CORE', FALSE);
Phil Sturgeonbabfb292011-03-08 21:56:08 +000043
44/*
45 * ------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +000046 * Load the global functions
47 * ------------------------------------------------------
48 */
Greg Aker3a746652011-04-19 10:59:47 -050049 require(BASEPATH.'core/Common.php');
Derek Allard2067d1a2008-11-13 22:59:24 +000050
51/*
52 * ------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +000053 * Load the framework constants
54 * ------------------------------------------------------
55 */
Greg Aker3a746652011-04-19 10:59:47 -050056 if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
Phil Sturgeon35f64912011-03-15 21:01:39 +000057 {
Greg Aker3a746652011-04-19 10:59:47 -050058 require(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
Phil Sturgeon35f64912011-03-15 21:01:39 +000059 }
60 else
61 {
Greg Aker3a746652011-04-19 10:59:47 -050062 require(APPPATH.'config/constants.php');
Phil Sturgeon35f64912011-03-15 21:01:39 +000063 }
Derek Allard2067d1a2008-11-13 22:59:24 +000064
65/*
66 * ------------------------------------------------------
67 * Define a custom error handler so we can log PHP errors
68 * ------------------------------------------------------
69 */
Derek Jones218876c2010-03-02 13:11:00 -060070 set_error_handler('_exception_handler');
Barry Mienydd671972010-10-04 16:33:58 +020071
Derek Jones218876c2010-03-02 13:11:00 -060072 if ( ! is_php('5.3'))
73 {
Barry Mienydd671972010-10-04 16:33:58 +020074 @set_magic_quotes_runtime(0); // Kill magic quotes
Derek Jones218876c2010-03-02 13:11:00 -060075 }
Derek Jones962d2252009-08-05 04:26:11 +000076
Derek Jones218876c2010-03-02 13:11:00 -060077/*
78 * ------------------------------------------------------
79 * Set the subclass_prefix
80 * ------------------------------------------------------
81 *
Barry Mienydd671972010-10-04 16:33:58 +020082 * Normally the "subclass_prefix" is set in the config file.
83 * The subclass prefix allows CI to know if a core class is
Derek Jones218876c2010-03-02 13:11:00 -060084 * being extended via a library in the local application
Barry Mienydd671972010-10-04 16:33:58 +020085 * "libraries" folder. Since CI allows config items to be
86 * overriden via data set in the main index. php file,
87 * before proceeding we need to know if a subclass_prefix
Derek Jones218876c2010-03-02 13:11:00 -060088 * override exists. If so, we will set this value now,
89 * before any classes are loaded
Barry Mienydd671972010-10-04 16:33:58 +020090 * Note: Since the config file data is cached it doesn't
Derek Jones218876c2010-03-02 13:11:00 -060091 * hurt to load it here.
92 */
Barry Mienydd671972010-10-04 16:33:58 +020093 if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
Derek Jones218876c2010-03-02 13:11:00 -060094 {
95 get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
96 }
Eric Barnesc5bf6162011-01-30 21:17:11 -050097
Pascal Krietef566af52010-11-09 13:03:26 -050098/*
99 * ------------------------------------------------------
100 * Set a liberal script execution time limit
101 * ------------------------------------------------------
102 */
103 if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
104 {
105 @set_time_limit(300);
106 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000107
108/*
109 * ------------------------------------------------------
110 * Start the timer... tick tock tick tock...
111 * ------------------------------------------------------
112 */
Derek Jones218876c2010-03-02 13:11:00 -0600113 $BM =& load_class('Benchmark', 'core');
114 $BM->mark('total_execution_time_start');
115 $BM->mark('loading_time:_base_classes_start');
Derek Allard2067d1a2008-11-13 22:59:24 +0000116
117/*
118 * ------------------------------------------------------
119 * Instantiate the hooks class
120 * ------------------------------------------------------
121 */
Derek Jones218876c2010-03-02 13:11:00 -0600122 $EXT =& load_class('Hooks', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000123
124/*
125 * ------------------------------------------------------
126 * Is there a "pre_system" hook?
127 * ------------------------------------------------------
128 */
Derek Jones218876c2010-03-02 13:11:00 -0600129 $EXT->_call_hook('pre_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000130
131/*
132 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600133 * Instantiate the config class
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200135 */
Derek Jones218876c2010-03-02 13:11:00 -0600136 $CFG =& load_class('Config', 'core');
137
138 // Do we have any manually set config items in the index.php file?
139 if (isset($assign_to_config))
Barry Mienydd671972010-10-04 16:33:58 +0200140 {
Derek Jones218876c2010-03-02 13:11:00 -0600141 $CFG->_assign_to_config($assign_to_config);
142 }
143
144/*
145 * ------------------------------------------------------
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500146 * Instantiate the UTF-8 class
Derek Jones218876c2010-03-02 13:11:00 -0600147 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200148 *
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500149 * Note: Order here is rather important as the UTF-8
Derek Jones218876c2010-03-02 13:11:00 -0600150 * class needs to be used very early on, but it cannot
Barry Mienydd671972010-10-04 16:33:58 +0200151 * properly determine if UTf-8 can be supported until
Derek Jones218876c2010-03-02 13:11:00 -0600152 * after the Config class is instantiated.
Barry Mienydd671972010-10-04 16:33:58 +0200153 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 */
155
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500156 $UNI =& load_class('Utf8', 'core');
Barry Mienydd671972010-10-04 16:33:58 +0200157
Derek Jones218876c2010-03-02 13:11:00 -0600158/*
159 * ------------------------------------------------------
160 * Instantiate the URI class
161 * ------------------------------------------------------
162 */
163 $URI =& load_class('URI', 'core');
164
165/*
166 * ------------------------------------------------------
167 * Instantiate the routing class and set the routing
168 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200169 */
Derek Jones218876c2010-03-02 13:11:00 -0600170 $RTR =& load_class('Router', 'core');
171 $RTR->_set_routing();
Barry Mienydd671972010-10-04 16:33:58 +0200172
Derek Jones218876c2010-03-02 13:11:00 -0600173 // Set any routing overrides that may exist in the main index file
174 if (isset($routing))
175 {
176 $RTR->_set_overrides($routing);
177 }
178
179/*
180 * ------------------------------------------------------
181 * Instantiate the output class
182 * ------------------------------------------------------
183 */
184 $OUT =& load_class('Output', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000185
186/*
187 * ------------------------------------------------------
188 * Is there a valid cache file? If so, we're done...
189 * ------------------------------------------------------
190 */
Derek Jones218876c2010-03-02 13:11:00 -0600191 if ($EXT->_call_hook('cache_override') === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 {
Derek Jones218876c2010-03-02 13:11:00 -0600193 if ($OUT->_display_cache($CFG, $URI) == TRUE)
194 {
195 exit;
196 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000197 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000198
199/*
Pascal Kriete14a0ac62011-04-05 14:55:56 -0400200 * -----------------------------------------------------
201 * Load the security class for xss and csrf support
202 * -----------------------------------------------------
203 */
204 $SEC =& load_class('Security', 'core');
205
206/*
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600208 * Load the Input class and sanitize globals
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 * ------------------------------------------------------
210 */
Barry Mienydd671972010-10-04 16:33:58 +0200211 $IN =& load_class('Input', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000212
Derek Jones218876c2010-03-02 13:11:00 -0600213/*
214 * ------------------------------------------------------
215 * Load the Language class
216 * ------------------------------------------------------
217 */
218 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000219
220/*
221 * ------------------------------------------------------
222 * Load the app controller and local controller
223 * ------------------------------------------------------
224 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 */
Derek Jones218876c2010-03-02 13:11:00 -0600226 // Load the base controller class
Greg Aker3a746652011-04-19 10:59:47 -0500227 require BASEPATH.'core/Controller.php';
Barry Mienydd671972010-10-04 16:33:58 +0200228
Greg Aker4abfa682010-11-10 14:44:26 -0600229 function &get_instance()
230 {
231 return CI_Controller::get_instance();
232 }
233
234
Greg Aker3a746652011-04-19 10:59:47 -0500235 if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
Greg Akerfa281352010-03-22 14:41:27 -0500236 {
Greg Aker3a746652011-04-19 10:59:47 -0500237 require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
Greg Akerfa281352010-03-22 14:41:27 -0500238 }
Barry Mienydd671972010-10-04 16:33:58 +0200239
Derek Jones218876c2010-03-02 13:11:00 -0600240 // Load the local application controller
Barry Mienydd671972010-10-04 16:33:58 +0200241 // Note: The Router class automatically validates the controller path using the router->_validate_request().
Derek Jones218876c2010-03-02 13:11:00 -0600242 // 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 -0500243 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
Derek Jones218876c2010-03-02 13:11:00 -0600244 {
Pascal Krieteebb6f4b2010-11-10 17:09:21 -0500245 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 -0600246 }
Barry Mienydd671972010-10-04 16:33:58 +0200247
Greg Aker3a746652011-04-19 10:59:47 -0500248 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php');
Barry Mienydd671972010-10-04 16:33:58 +0200249
Derek Jones218876c2010-03-02 13:11:00 -0600250 // Set a mark point for benchmarking
251 $BM->mark('loading_time:_base_classes_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000252
253/*
254 * ------------------------------------------------------
255 * Security check
256 * ------------------------------------------------------
257 *
258 * None of the functions in the app controller or the
259 * loader class can be called via the URI, nor can
260 * controller functions that begin with an underscore
261 */
Derek Jones218876c2010-03-02 13:11:00 -0600262 $class = $RTR->fetch_class();
263 $method = $RTR->fetch_method();
Barry Mienydd671972010-10-04 16:33:58 +0200264
Derek Jones218876c2010-03-02 13:11:00 -0600265 if ( ! class_exists($class)
Derek Jones218876c2010-03-02 13:11:00 -0600266 OR strncmp($method, '_', 1) == 0
Greg Aker63277b82010-11-09 13:46:13 -0600267 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
Derek Jones218876c2010-03-02 13:11:00 -0600268 )
269 {
270 show_404("{$class}/{$method}");
271 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000272
273/*
274 * ------------------------------------------------------
275 * Is there a "pre_controller" hook?
276 * ------------------------------------------------------
277 */
Derek Jones218876c2010-03-02 13:11:00 -0600278 $EXT->_call_hook('pre_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000279
280/*
281 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600282 * Instantiate the requested controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 * ------------------------------------------------------
284 */
Derek Jones218876c2010-03-02 13:11:00 -0600285 // Mark a start point so we can benchmark the controller
286 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
Barry Mienydd671972010-10-04 16:33:58 +0200287
Derek Jones218876c2010-03-02 13:11:00 -0600288 $CI = new $class();
289
290/*
291 * ------------------------------------------------------
292 * Is there a "post_controller_constructor" hook?
293 * ------------------------------------------------------
294 */
295 $EXT->_call_hook('post_controller_constructor');
296
297/*
298 * ------------------------------------------------------
299 * Call the requested method
300 * ------------------------------------------------------
301 */
302 // Is there a "remap" function? If so, we call it instead
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 if (method_exists($CI, '_remap'))
304 {
Pascal Kriete3431ae32010-11-09 15:19:50 -0500305 $CI->_remap($method, array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000306 }
307 else
308 {
309 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
310 // methods, so we'll use this workaround for consistent behavior
311 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
312 {
Eric Barnesc5bf6162011-01-30 21:17:11 -0500313 // Check and see if we are using a 404 override and use it.
314 if ( ! empty($RTR->routes['404_override']))
315 {
316 $x = explode('/', $RTR->routes['404_override']);
317 $class = $x[0];
318 $method = (isset($x[1]) ? $x[1] : 'index');
Eric Barnes5519e3d2011-02-01 13:07:37 -0500319 if ( ! class_exists($class))
320 {
Greg Aker3a746652011-04-19 10:59:47 -0500321 if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
Eric Barnes5519e3d2011-02-01 13:07:37 -0500322 {
323 show_404("{$class}/{$method}");
324 }
325
Greg Aker3a746652011-04-19 10:59:47 -0500326 include_once(APPPATH.'controllers/'.$class.'.php');
Eric Barnes5519e3d2011-02-01 13:07:37 -0500327 unset($CI);
328 $CI = new $class();
329 }
Eric Barnesc5bf6162011-01-30 21:17:11 -0500330 }
331 else
332 {
333 show_404("{$class}/{$method}");
334 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 }
336
337 // Call the requested method.
Barry Mienydd671972010-10-04 16:33:58 +0200338 // Any URI segments present (besides the class/function) will be passed to the method for convenience
339 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000340 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000341
Barry Mienydd671972010-10-04 16:33:58 +0200342
Derek Jones218876c2010-03-02 13:11:00 -0600343 // Mark a benchmark end point
344 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000345
346/*
347 * ------------------------------------------------------
348 * Is there a "post_controller" hook?
349 * ------------------------------------------------------
350 */
Derek Jones218876c2010-03-02 13:11:00 -0600351 $EXT->_call_hook('post_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000352
353/*
354 * ------------------------------------------------------
355 * Send the final rendered output to the browser
356 * ------------------------------------------------------
357 */
Derek Jones218876c2010-03-02 13:11:00 -0600358 if ($EXT->_call_hook('display_override') === FALSE)
359 {
360 $OUT->_display();
361 }
Barry Mienydd671972010-10-04 16:33:58 +0200362
Derek Allard2067d1a2008-11-13 22:59:24 +0000363/*
364 * ------------------------------------------------------
365 * Is there a "post_system" hook?
366 * ------------------------------------------------------
367 */
Derek Jones218876c2010-03-02 13:11:00 -0600368 $EXT->_call_hook('post_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000369
370/*
371 * ------------------------------------------------------
372 * Close the DB connection if one exists
373 * ------------------------------------------------------
374 */
Derek Jones218876c2010-03-02 13:11:00 -0600375 if (class_exists('CI_DB') AND isset($CI->db))
376 {
377 $CI->db->close();
378 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000379
380
381/* End of file CodeIgniter.php */
Phil Sturgeon35f64912011-03-15 21:01:39 +0000382/* Location: ./system/core/CodeIgniter.php */