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