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