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