Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author ExpressionEngine Dev Team |
Derek Jones | 7f3719f | 2010-01-05 13:35:37 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | /** |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 19 | * System Initialization File |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 30 | /* |
| 31 | * ------------------------------------------------------ |
| 32 | * Define the CodeIgniter Version |
| 33 | * ------------------------------------------------------ |
| 34 | */ |
| 35 | define('CI_VERSION', '2.0'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * ------------------------------------------------------ |
| 39 | * Load the global functions |
| 40 | * ------------------------------------------------------ |
| 41 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 42 | require(BASEPATH.'core/Common'.EXT); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * ------------------------------------------------------ |
| 46 | * Load the compatibility override functions |
| 47 | * ------------------------------------------------------ |
| 48 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 49 | require(BASEPATH.'core/Compat'.EXT); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * ------------------------------------------------------ |
| 53 | * Load the framework constants |
| 54 | * ------------------------------------------------------ |
| 55 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 56 | require(APPPATH.'config/constants'.EXT); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * ------------------------------------------------------ |
| 60 | * Define a custom error handler so we can log PHP errors |
| 61 | * ------------------------------------------------------ |
| 62 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 63 | set_error_handler('_exception_handler'); |
| 64 | |
| 65 | if ( ! is_php('5.3')) |
| 66 | { |
| 67 | @set_magic_quotes_runtime(0); // Kill magic quotes |
| 68 | } |
Derek Jones | 962d225 | 2009-08-05 04:26:11 +0000 | [diff] [blame] | 69 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 70 | // Set a liberal script execution time limit |
| 71 | if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0) |
| 72 | { |
| 73 | @set_time_limit(300); |
| 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 | { |
| 94 | get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix'])); |
| 95 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | * ------------------------------------------------------ |
| 99 | * Start the timer... tick tock tick tock... |
| 100 | * ------------------------------------------------------ |
| 101 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 102 | $BM =& load_class('Benchmark', 'core'); |
| 103 | $BM->mark('total_execution_time_start'); |
| 104 | $BM->mark('loading_time:_base_classes_start'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * ------------------------------------------------------ |
| 108 | * Instantiate the hooks class |
| 109 | * ------------------------------------------------------ |
| 110 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 111 | $EXT =& load_class('Hooks', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * ------------------------------------------------------ |
| 115 | * Is there a "pre_system" hook? |
| 116 | * ------------------------------------------------------ |
| 117 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 118 | $EXT->_call_hook('pre_system'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * ------------------------------------------------------ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 122 | * Instantiate the config class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 123 | * ------------------------------------------------------ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 124 | */ |
| 125 | $CFG =& load_class('Config', 'core'); |
| 126 | |
| 127 | // Do we have any manually set config items in the index.php file? |
| 128 | if (isset($assign_to_config)) |
| 129 | { |
| 130 | $CFG->_assign_to_config($assign_to_config); |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * ------------------------------------------------------ |
| 135 | * Instantiate the Unicode class |
| 136 | * ------------------------------------------------------ |
| 137 | * |
| 138 | * Note: Order here is rather important as the Unicode |
| 139 | * class needs to be used very early on, but it cannot |
| 140 | * properly determine if UTf-8 can be supported until |
| 141 | * after the Config class is instantiated. |
| 142 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | */ |
| 144 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 145 | $UNI =& load_class('Unicode', 'core'); |
| 146 | |
| 147 | /* |
| 148 | * ------------------------------------------------------ |
| 149 | * Instantiate the URI class |
| 150 | * ------------------------------------------------------ |
| 151 | */ |
| 152 | $URI =& load_class('URI', 'core'); |
| 153 | |
| 154 | /* |
| 155 | * ------------------------------------------------------ |
| 156 | * Instantiate the routing class and set the routing |
| 157 | * ------------------------------------------------------ |
| 158 | */ |
| 159 | $RTR =& load_class('Router', 'core'); |
| 160 | $RTR->_set_routing(); |
| 161 | |
| 162 | // Set any routing overrides that may exist in the main index file |
| 163 | if (isset($routing)) |
| 164 | { |
| 165 | $RTR->_set_overrides($routing); |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * ------------------------------------------------------ |
| 170 | * Instantiate the output class |
| 171 | * ------------------------------------------------------ |
| 172 | */ |
| 173 | $OUT =& load_class('Output', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * ------------------------------------------------------ |
| 177 | * Is there a valid cache file? If so, we're done... |
| 178 | * ------------------------------------------------------ |
| 179 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 180 | if ($EXT->_call_hook('cache_override') === FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 181 | { |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 182 | if ($OUT->_display_cache($CFG, $URI) == TRUE) |
| 183 | { |
| 184 | exit; |
| 185 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 186 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * ------------------------------------------------------ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 190 | * Load the Input class and sanitize globals |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | * ------------------------------------------------------ |
| 192 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 193 | $IN =& load_class('Input', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 195 | /* |
| 196 | * ------------------------------------------------------ |
| 197 | * Load the Language class |
| 198 | * ------------------------------------------------------ |
| 199 | */ |
| 200 | $LANG =& load_class('Lang', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | |
| 202 | /* |
| 203 | * ------------------------------------------------------ |
| 204 | * Load the app controller and local controller |
| 205 | * ------------------------------------------------------ |
| 206 | * |
| 207 | * Note: Due to the poor object handling in PHP 4 we'll |
| 208 | * conditionally load different versions of the base |
| 209 | * class. Retaining PHP 4 compatibility requires a bit of a hack. |
| 210 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 211 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 212 | if (is_php('5.0.0') == TRUE) |
| 213 | { |
| 214 | require(BASEPATH.'core/Base5'.EXT); |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | // The Loader class needs to be included first when running PHP 4.x |
| 219 | load_class('Loader', 'core'); |
| 220 | require(BASEPATH.'core/Base4'.EXT); |
| 221 | } |
| 222 | |
| 223 | // Load the base controller class |
| 224 | require BASEPATH.'core/Controller'.EXT; |
| 225 | |
| 226 | // Load the local application controller |
| 227 | // Note: The Router class automatically validates the controller path using the router->_validate_request(). |
| 228 | // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid. |
| 229 | if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) |
| 230 | { |
| 231 | show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); |
| 232 | } |
| 233 | |
| 234 | include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); |
| 235 | |
| 236 | // Set a mark point for benchmarking |
| 237 | $BM->mark('loading_time:_base_classes_end'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 238 | |
| 239 | /* |
| 240 | * ------------------------------------------------------ |
| 241 | * Security check |
| 242 | * ------------------------------------------------------ |
| 243 | * |
| 244 | * None of the functions in the app controller or the |
| 245 | * loader class can be called via the URI, nor can |
| 246 | * controller functions that begin with an underscore |
| 247 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 248 | $class = $RTR->fetch_class(); |
| 249 | $method = $RTR->fetch_method(); |
| 250 | |
| 251 | if ( ! class_exists($class) |
| 252 | OR $method == 'controller' |
| 253 | OR strncmp($method, '_', 1) == 0 |
| 254 | OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) |
| 255 | ) |
| 256 | { |
| 257 | show_404("{$class}/{$method}"); |
| 258 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 259 | |
| 260 | /* |
| 261 | * ------------------------------------------------------ |
| 262 | * Is there a "pre_controller" hook? |
| 263 | * ------------------------------------------------------ |
| 264 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 265 | $EXT->_call_hook('pre_controller'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 266 | |
| 267 | /* |
| 268 | * ------------------------------------------------------ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 269 | * Instantiate the requested controller |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | * ------------------------------------------------------ |
| 271 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 272 | // Mark a start point so we can benchmark the controller |
| 273 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 274 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 275 | $CI = new $class(); |
| 276 | |
| 277 | /* |
| 278 | * ------------------------------------------------------ |
| 279 | * Is there a "post_controller_constructor" hook? |
| 280 | * ------------------------------------------------------ |
| 281 | */ |
| 282 | $EXT->_call_hook('post_controller_constructor'); |
| 283 | |
| 284 | /* |
| 285 | * ------------------------------------------------------ |
| 286 | * Call the requested method |
| 287 | * ------------------------------------------------------ |
| 288 | */ |
| 289 | // Is there a "remap" function? If so, we call it instead |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | if (method_exists($CI, '_remap')) |
| 291 | { |
| 292 | $CI->_remap($method); |
| 293 | } |
| 294 | else |
| 295 | { |
| 296 | // is_callable() returns TRUE on some versions of PHP 5 for private and protected |
| 297 | // methods, so we'll use this workaround for consistent behavior |
| 298 | if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI)))) |
| 299 | { |
| 300 | show_404("{$class}/{$method}"); |
| 301 | } |
| 302 | |
| 303 | // Call the requested method. |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 304 | // Any URI segments present (besides the class/function) will be passed to the method for convenience |
| 305 | call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 306 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 308 | |
| 309 | // Mark a benchmark end point |
| 310 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 311 | |
| 312 | /* |
| 313 | * ------------------------------------------------------ |
| 314 | * Is there a "post_controller" hook? |
| 315 | * ------------------------------------------------------ |
| 316 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 317 | $EXT->_call_hook('post_controller'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 318 | |
| 319 | /* |
| 320 | * ------------------------------------------------------ |
| 321 | * Send the final rendered output to the browser |
| 322 | * ------------------------------------------------------ |
| 323 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 324 | if ($EXT->_call_hook('display_override') === FALSE) |
| 325 | { |
| 326 | $OUT->_display(); |
| 327 | } |
| 328 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | /* |
| 330 | * ------------------------------------------------------ |
| 331 | * Is there a "post_system" hook? |
| 332 | * ------------------------------------------------------ |
| 333 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 334 | $EXT->_call_hook('post_system'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 335 | |
| 336 | /* |
| 337 | * ------------------------------------------------------ |
| 338 | * Close the DB connection if one exists |
| 339 | * ------------------------------------------------------ |
| 340 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame^] | 341 | if (class_exists('CI_DB') AND isset($CI->db)) |
| 342 | { |
| 343 | $CI->db->close(); |
| 344 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | |
| 346 | |
| 347 | /* End of file CodeIgniter.php */ |
Derek Jones | c68dfbf | 2010-03-02 12:59:23 -0600 | [diff] [blame] | 348 | /* Location: ./system/core/CodeIgniter.php */ |