Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 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 |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2014, 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 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 29 | /** |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 30 | * System Initialization File |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 31 | * |
| 32 | * Loads the base classes and executes the request. |
| 33 | * |
| 34 | * @package CodeIgniter |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 35 | * @subpackage CodeIgniter |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @category Front-controller |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 37 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 38 | * @link http://codeigniter.com/user_guide/ |
| 39 | */ |
| 40 | |
Phil Sturgeon | d8ef630 | 2011-08-14 12:10:55 -0600 | [diff] [blame] | 41 | /** |
| 42 | * CodeIgniter Version |
| 43 | * |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 44 | * @var string |
Phil Sturgeon | d8ef630 | 2011-08-14 12:10:55 -0600 | [diff] [blame] | 45 | * |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 46 | */ |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 47 | define('CI_VERSION', '3.0-dev'); |
Andrey Andreev | b6fbcbe | 2013-11-17 18:06:18 +0200 | [diff] [blame] | 48 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | /* |
| 50 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 51 | * Load the framework constants |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | * ------------------------------------------------------ |
| 53 | */ |
Andrey Andreev | db529ca | 2013-01-28 11:00:02 +0200 | [diff] [blame] | 54 | if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php')) |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 55 | { |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 56 | require_once(APPPATH.'config/'.ENVIRONMENT.'/constants.php'); |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 57 | } |
Andrey Andreev | b6fbcbe | 2013-11-17 18:06:18 +0200 | [diff] [blame] | 58 | |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 59 | require_once(APPPATH.'config/constants.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 60 | |
| 61 | /* |
| 62 | * ------------------------------------------------------ |
josephok | 1095d11 | 2013-11-16 09:33:37 +0800 | [diff] [blame] | 63 | * Load the global functions |
| 64 | * ------------------------------------------------------ |
| 65 | */ |
| 66 | require_once(BASEPATH.'core/Common.php'); |
| 67 | |
Andrey Andreev | b78a8c7 | 2014-04-15 17:21:16 +0300 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * ------------------------------------------------------ |
| 71 | * Security procedures |
| 72 | * ------------------------------------------------------ |
| 73 | */ |
| 74 | |
| 75 | if ( ! is_php('5.4')) |
| 76 | { |
| 77 | ini_set('magic_quotes_runtime', 0); |
| 78 | |
| 79 | if ((bool) ini_get('register_globals')) |
| 80 | { |
| 81 | $_protected = array( |
| 82 | '_SERVER', |
| 83 | '_GET', |
| 84 | '_POST', |
| 85 | '_FILES', |
| 86 | '_REQUEST', |
| 87 | '_SESSION', |
| 88 | '_ENV', |
| 89 | '_COOKIE', |
| 90 | 'GLOBALS', |
| 91 | 'HTTP_RAW_POST_DATA', |
vlakoff | de70dbb | 2014-04-15 16:46:03 +0200 | [diff] [blame] | 92 | 'system_path', |
Andrey Andreev | b78a8c7 | 2014-04-15 17:21:16 +0300 | [diff] [blame] | 93 | 'application_folder', |
| 94 | 'view_folder', |
| 95 | '_protected', |
| 96 | '_registered' |
| 97 | ); |
| 98 | |
| 99 | $_registered = ini_get('variables_order'); |
| 100 | foreach (array('E' => '_ENV', 'G' => '_GET', 'P' => '_POST', 'C' => '_COOKIE', 'S' => '_SERVER') as $key => $superglobal) |
| 101 | { |
| 102 | if (strpos($_registered, $key) === FALSE) |
| 103 | { |
| 104 | continue; |
| 105 | } |
| 106 | |
| 107 | foreach (array_keys($$superglobal) as $var) |
| 108 | { |
| 109 | if (isset($GLOBALS[$var]) && ! in_array($var, $_protected, TRUE)) |
| 110 | { |
| 111 | $GLOBALS[$var] = NULL; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | |
josephok | 1095d11 | 2013-11-16 09:33:37 +0800 | [diff] [blame] | 119 | /* |
| 120 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 121 | * Define a custom error handler so we can log PHP errors |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 122 | * ------------------------------------------------------ |
| 123 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 124 | set_error_handler('_exception_handler'); |
Kaiwang Chen | 21fe9da | 2013-09-11 13:09:41 +0800 | [diff] [blame] | 125 | register_shutdown_function('_shutdown_handler'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 126 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 127 | /* |
| 128 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 129 | * Set the subclass_prefix |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 130 | * ------------------------------------------------------ |
| 131 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 132 | * Normally the "subclass_prefix" is set in the config file. |
| 133 | * The subclass prefix allows CI to know if a core class is |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 134 | * being extended via a library in the local application |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 135 | * "libraries" folder. Since CI allows config items to be |
vlakoff | 8d70c0a | 2013-08-17 07:31:29 +0200 | [diff] [blame] | 136 | * overriden via data set in the main index.php file, |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 137 | * before proceeding we need to know if a subclass_prefix |
Andrey Andreev | 9c5c24a | 2012-01-07 18:51:21 +0200 | [diff] [blame] | 138 | * override exists. If so, we will set this value now, |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 139 | * before any classes are loaded |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 140 | * Note: Since the config file data is cached it doesn't |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 141 | * hurt to load it here. |
| 142 | */ |
Andrey Andreev | 9ba661b | 2012-06-04 14:44:34 +0300 | [diff] [blame] | 143 | if ( ! empty($assign_to_config['subclass_prefix'])) |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 144 | { |
| 145 | get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix'])); |
| 146 | } |
Eric Barnes | c5bf616 | 2011-01-30 21:17:11 -0500 | [diff] [blame] | 147 | |
Pascal Kriete | f566af5 | 2010-11-09 13:03:26 -0500 | [diff] [blame] | 148 | /* |
| 149 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 150 | * Start the timer... tick tock tick tock... |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 151 | * ------------------------------------------------------ |
| 152 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 153 | $BM =& load_class('Benchmark', 'core'); |
| 154 | $BM->mark('total_execution_time_start'); |
| 155 | $BM->mark('loading_time:_base_classes_start'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 159 | * Instantiate the hooks class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 160 | * ------------------------------------------------------ |
| 161 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 162 | $EXT =& load_class('Hooks', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 166 | * Is there a "pre_system" hook? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 167 | * ------------------------------------------------------ |
| 168 | */ |
Andrey Andreev | a5dd297 | 2012-03-26 14:43:01 +0300 | [diff] [blame] | 169 | $EXT->call_hook('pre_system'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 173 | * Instantiate the config class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 174 | * ------------------------------------------------------ |
Andrey Andreev | eb555ed | 2014-02-12 19:25:01 +0200 | [diff] [blame] | 175 | * |
| 176 | * Note: It is important that Config is loaded first as |
| 177 | * most other classes depend on it either directly or by |
| 178 | * depending on another class that uses it. |
| 179 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 180 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 181 | $CFG =& load_class('Config', 'core'); |
| 182 | |
| 183 | // Do we have any manually set config items in the index.php file? |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame] | 184 | if (isset($assign_to_config) && is_array($assign_to_config)) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 185 | { |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame] | 186 | foreach ($assign_to_config as $key => $value) |
| 187 | { |
| 188 | $CFG->set_item($key, $value); |
| 189 | } |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* |
| 193 | * ------------------------------------------------------ |
Andrey Andreev | eb555ed | 2014-02-12 19:25:01 +0200 | [diff] [blame] | 194 | * Important charset-related stuff |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 195 | * ------------------------------------------------------ |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 196 | * |
Andrey Andreev | eb555ed | 2014-02-12 19:25:01 +0200 | [diff] [blame] | 197 | * Configure mbstring and/or iconv if they are enabled |
| 198 | * and set MB_ENABLED and ICONV_ENABLED constants, so |
| 199 | * that we don't repeatedly do extension_loaded() or |
| 200 | * function_exists() calls. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 201 | * |
Andrey Andreev | eb555ed | 2014-02-12 19:25:01 +0200 | [diff] [blame] | 202 | * Note: UTF-8 class depends on this. It used to be done |
| 203 | * in it's constructor, but it's _not_ class-specific. |
| 204 | * |
| 205 | */ |
| 206 | $charset = strtoupper(config_item('charset')); |
Andrey Andreev | 51593f4 | 2014-05-07 00:06:31 +0300 | [diff] [blame] | 207 | ini_set('default_charset', $charset); |
Andrey Andreev | eb555ed | 2014-02-12 19:25:01 +0200 | [diff] [blame] | 208 | |
| 209 | if (extension_loaded('mbstring')) |
| 210 | { |
| 211 | define('MB_ENABLED', TRUE); |
Andrey Andreev | 1ffa223 | 2014-05-09 12:30:59 +0300 | [diff] [blame^] | 212 | // mbstring.internal_encoding is deprecated starting with PHP 5.6 |
| 213 | // and it's usage triggers E_DEPRECATED messages. |
| 214 | @ini_set('mbstring.internal_encoding', $charset); |
Andrey Andreev | eb555ed | 2014-02-12 19:25:01 +0200 | [diff] [blame] | 215 | // This is required for mb_convert_encoding() to strip invalid characters. |
| 216 | // That's utilized by CI_Utf8, but it's also done for consistency with iconv. |
| 217 | mb_substitute_character('none'); |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | define('MB_ENABLED', FALSE); |
| 222 | } |
| 223 | |
| 224 | // There's an ICONV_IMPL constant, but the PHP manual says that using |
| 225 | // iconv's predefined constants is "strongly discouraged". |
| 226 | if (extension_loaded('iconv')) |
| 227 | { |
| 228 | define('ICONV_ENABLED', TRUE); |
Andrey Andreev | 51593f4 | 2014-05-07 00:06:31 +0300 | [diff] [blame] | 229 | // iconv.internal_encoding is deprecated starting with PHP 5.6 |
| 230 | // and it's usage triggers E_DEPRECATED messages. |
| 231 | @ini_set('iconv.internal_encoding', $charset); |
Andrey Andreev | eb555ed | 2014-02-12 19:25:01 +0200 | [diff] [blame] | 232 | } |
| 233 | else |
| 234 | { |
| 235 | define('ICONV_ENABLED', FALSE); |
| 236 | } |
| 237 | |
Andrey Andreev | 51593f4 | 2014-05-07 00:06:31 +0300 | [diff] [blame] | 238 | if (is_php('5.6')) |
| 239 | { |
| 240 | ini_set('php.internal_encoding', $charset); |
| 241 | } |
| 242 | |
Andrey Andreev | eb555ed | 2014-02-12 19:25:01 +0200 | [diff] [blame] | 243 | /* |
| 244 | * ------------------------------------------------------ |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 245 | * Load compatibility features |
| 246 | * ------------------------------------------------------ |
| 247 | */ |
| 248 | |
Andrey Andreev | 376b215 | 2014-02-13 12:35:52 +0200 | [diff] [blame] | 249 | require_once(BASEPATH.'core/compat/mbstring.php'); |
Andrey Andreev | 9a152a9 | 2014-02-18 16:29:53 +0200 | [diff] [blame] | 250 | require_once(BASEPATH.'core/compat/hash.php'); |
Andrey Andreev | 376b215 | 2014-02-13 12:35:52 +0200 | [diff] [blame] | 251 | require_once(BASEPATH.'core/compat/password.php'); |
Andrey Andreev | 0254589 | 2014-02-19 23:49:31 +0200 | [diff] [blame] | 252 | require_once(BASEPATH.'core/compat/array.php'); |
Andrey Andreev | 3fd1b38 | 2014-02-13 03:01:31 +0200 | [diff] [blame] | 253 | |
| 254 | /* |
| 255 | * ------------------------------------------------------ |
Andrey Andreev | eb555ed | 2014-02-12 19:25:01 +0200 | [diff] [blame] | 256 | * Instantiate the UTF-8 class |
| 257 | * ------------------------------------------------------ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 258 | */ |
Pascal Kriete | aaec1e4 | 2011-01-20 00:01:21 -0500 | [diff] [blame] | 259 | $UNI =& load_class('Utf8', 'core'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 260 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 261 | /* |
| 262 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 263 | * Instantiate the URI class |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 264 | * ------------------------------------------------------ |
| 265 | */ |
| 266 | $URI =& load_class('URI', 'core'); |
| 267 | |
| 268 | /* |
| 269 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 270 | * Instantiate the routing class and set the routing |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 271 | * ------------------------------------------------------ |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 272 | */ |
Andrey Andreev | c26b9eb | 2014-02-24 11:31:36 +0200 | [diff] [blame] | 273 | $RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 274 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 275 | /* |
| 276 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 277 | * Instantiate the output class |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 278 | * ------------------------------------------------------ |
| 279 | */ |
| 280 | $OUT =& load_class('Output', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 281 | |
| 282 | /* |
| 283 | * ------------------------------------------------------ |
Andrey Andreev | 9c5c24a | 2012-01-07 18:51:21 +0200 | [diff] [blame] | 284 | * Is there a valid cache file? If so, we're done... |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 285 | * ------------------------------------------------------ |
| 286 | */ |
Andrey Andreev | c26b9eb | 2014-02-24 11:31:36 +0200 | [diff] [blame] | 287 | if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | { |
Andrey Andreev | 9c5c24a | 2012-01-07 18:51:21 +0200 | [diff] [blame] | 289 | exit; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 291 | |
| 292 | /* |
Pascal Kriete | 14a0ac6 | 2011-04-05 14:55:56 -0400 | [diff] [blame] | 293 | * ----------------------------------------------------- |
| 294 | * Load the security class for xss and csrf support |
| 295 | * ----------------------------------------------------- |
| 296 | */ |
| 297 | $SEC =& load_class('Security', 'core'); |
| 298 | |
| 299 | /* |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 301 | * Load the Input class and sanitize globals |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 302 | * ------------------------------------------------------ |
| 303 | */ |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 304 | $IN =& load_class('Input', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 305 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 306 | /* |
| 307 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 308 | * Load the Language class |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 309 | * ------------------------------------------------------ |
| 310 | */ |
| 311 | $LANG =& load_class('Lang', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 312 | |
| 313 | /* |
| 314 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 315 | * Load the app controller and local controller |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 316 | * ------------------------------------------------------ |
| 317 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 318 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 319 | // Load the base controller class |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 320 | require_once BASEPATH.'core/Controller.php'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 321 | |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 322 | /** |
| 323 | * Reference to the CI_Controller method. |
| 324 | * |
| 325 | * Returns current CI instance object |
| 326 | * |
| 327 | * @return object |
| 328 | */ |
Greg Aker | 4abfa68 | 2010-11-10 14:44:26 -0600 | [diff] [blame] | 329 | function &get_instance() |
| 330 | { |
| 331 | return CI_Controller::get_instance(); |
| 332 | } |
| 333 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 334 | if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php')) |
Greg Aker | fa28135 | 2010-03-22 14:41:27 -0500 | [diff] [blame] | 335 | { |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 336 | require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'; |
Greg Aker | fa28135 | 2010-03-22 14:41:27 -0500 | [diff] [blame] | 337 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 338 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 339 | // Set a mark point for benchmarking |
| 340 | $BM->mark('loading_time:_base_classes_end'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | |
| 342 | /* |
| 343 | * ------------------------------------------------------ |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 344 | * Sanity checks |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | * ------------------------------------------------------ |
| 346 | * |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 347 | * The Router class has already validated the request, |
| 348 | * leaving us with 3 options here: |
| 349 | * |
| 350 | * 1) an empty class name, if we reached the default |
| 351 | * controller, but it didn't exist; |
| 352 | * 2) a query string which doesn't go through a |
| 353 | * file_exists() check |
| 354 | * 3) a regular request for a non-existing page |
| 355 | * |
| 356 | * We handle all of these as a 404 error. |
| 357 | * |
| 358 | * Furthermore, none of the methods in the app controller |
| 359 | * or the loader class can be called via the URI, nor can |
Andrey Andreev | 2029231 | 2013-07-22 14:29:10 +0300 | [diff] [blame] | 360 | * controller methods that begin with an underscore. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 361 | */ |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 362 | |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 363 | $e404 = FALSE; |
| 364 | $class = ucfirst($RTR->class); |
| 365 | $method = $RTR->method; |
| 366 | |
| 367 | if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php')) |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 368 | { |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 369 | $e404 = TRUE; |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 370 | } |
| 371 | else |
| 372 | { |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 373 | require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php'); |
| 374 | |
| 375 | if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method)) |
| 376 | { |
| 377 | $e404 = TRUE; |
| 378 | } |
| 379 | elseif (method_exists($class, '_remap')) |
| 380 | { |
| 381 | $params = array($method, array_slice($URI->rsegments, 2)); |
| 382 | $method = '_remap'; |
| 383 | } |
Andrey Andreev | 522c736 | 2012-11-05 16:40:32 +0200 | [diff] [blame] | 384 | // WARNING: It appears that there are issues with is_callable() even in PHP 5.2! |
| 385 | // Furthermore, there are bug reports and feature/change requests related to it |
| 386 | // that make it unreliable to use in this context. Please, DO NOT change this |
| 387 | // work-around until a better alternative is available. |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 388 | elseif ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($class)), TRUE)) |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 389 | { |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 390 | $e404 = TRUE; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | if ($e404) |
| 395 | { |
| 396 | if ( ! empty($RTR->routes['404_override'])) |
| 397 | { |
| 398 | if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2) |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 399 | { |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 400 | $error_method = 'index'; |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 403 | $error_class = ucfirst($error_class); |
Andrey Andreev | 2029231 | 2013-07-22 14:29:10 +0300 | [diff] [blame] | 404 | |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 405 | if ( ! class_exists($error_class, FALSE)) |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 406 | { |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 407 | if (file_exists(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php')) |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 408 | { |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 409 | require_once(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php'); |
| 410 | $e404 = ! class_exists($error_class, FALSE); |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 411 | } |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 412 | // Were we in a directory? If so, check for a global override |
| 413 | elseif ( ! empty($RTR->directory) && file_exists(APPPATH.'controllers/'.$error_class.'.php')) |
| 414 | { |
| 415 | require_once(APPPATH.'controllers/'.$error_class.'.php'); |
| 416 | if (($e404 = ! class_exists($error_class, FALSE)) === FALSE) |
| 417 | { |
| 418 | $RTR->directory = ''; |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | else |
| 423 | { |
| 424 | $e404 = FALSE; |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 428 | // Did we reset the $e404 flag? If so, set the rsegments, starting from index 1 |
| 429 | if ( ! $e404) |
| 430 | { |
| 431 | $class = $error_class; |
| 432 | $method = $error_method; |
| 433 | |
| 434 | $URI->rsegments = array( |
| 435 | 1 => $class, |
| 436 | 2 => $method |
| 437 | ); |
| 438 | } |
| 439 | else |
| 440 | { |
| 441 | show_404($RTR->directory.$class.'/'.$method); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | if ($method !== '_remap') |
| 446 | { |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 447 | $params = array_slice($URI->rsegments, 2); |
| 448 | } |
| 449 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 450 | /* |
| 451 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 452 | * Is there a "pre_controller" hook? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 453 | * ------------------------------------------------------ |
| 454 | */ |
Andrey Andreev | a5dd297 | 2012-03-26 14:43:01 +0300 | [diff] [blame] | 455 | $EXT->call_hook('pre_controller'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 456 | |
| 457 | /* |
| 458 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 459 | * Instantiate the requested controller |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 460 | * ------------------------------------------------------ |
| 461 | */ |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 462 | // Mark a start point so we can benchmark the controller |
| 463 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 464 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 465 | $CI = new $class(); |
| 466 | |
| 467 | /* |
| 468 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 469 | * Is there a "post_controller_constructor" hook? |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 470 | * ------------------------------------------------------ |
| 471 | */ |
Andrey Andreev | a5dd297 | 2012-03-26 14:43:01 +0300 | [diff] [blame] | 472 | $EXT->call_hook('post_controller_constructor'); |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 473 | |
| 474 | /* |
| 475 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 476 | * Call the requested method |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 477 | * ------------------------------------------------------ |
| 478 | */ |
Andrey Andreev | 38e32f6 | 2012-11-03 00:16:47 +0200 | [diff] [blame] | 479 | call_user_func_array(array(&$CI, $method), $params); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 480 | |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 481 | // Mark a benchmark end point |
| 482 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 483 | |
| 484 | /* |
| 485 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 486 | * Is there a "post_controller" hook? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 487 | * ------------------------------------------------------ |
| 488 | */ |
Andrey Andreev | a5dd297 | 2012-03-26 14:43:01 +0300 | [diff] [blame] | 489 | $EXT->call_hook('post_controller'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 490 | |
| 491 | /* |
| 492 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 493 | * Send the final rendered output to the browser |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 494 | * ------------------------------------------------------ |
| 495 | */ |
Andrey Andreev | a5dd297 | 2012-03-26 14:43:01 +0300 | [diff] [blame] | 496 | if ($EXT->call_hook('display_override') === FALSE) |
Derek Jones | 218876c | 2010-03-02 13:11:00 -0600 | [diff] [blame] | 497 | { |
| 498 | $OUT->_display(); |
| 499 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 500 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 501 | /* |
| 502 | * ------------------------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 503 | * Is there a "post_system" hook? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 504 | * ------------------------------------------------------ |
| 505 | */ |
Andrey Andreev | a5dd297 | 2012-03-26 14:43:01 +0300 | [diff] [blame] | 506 | $EXT->call_hook('post_system'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 507 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | /* End of file CodeIgniter.php */ |
Andrey Andreev | b6fbcbe | 2013-11-17 18:06:18 +0200 | [diff] [blame] | 509 | /* Location: ./system/core/CodeIgniter.php */ |