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