Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
| 8 | * @author ExpressionEngine Dev Team
|
| 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * System Front Controller
|
| 20 | *
|
| 21 | * Loads the base classes and executes the request.
|
| 22 | *
|
| 23 | * @package CodeIgniter
|
| 24 | * @subpackage codeigniter
|
| 25 | * @category Front-controller
|
| 26 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 27 | * @link http://codeigniter.com/user_guide/
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 28 | */
|
| 29 |
|
| 30 | // CI Version
|
Derek Allard | 197d10b | 2008-02-12 04:20:38 +0000 | [diff] [blame] | 31 | define('CI_VERSION', '1.6.1');
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 32 |
|
| 33 | /*
|
| 34 | * ------------------------------------------------------
|
| 35 | * Load the global functions
|
| 36 | * ------------------------------------------------------
|
| 37 | */
|
| 38 | require(BASEPATH.'codeigniter/Common'.EXT);
|
| 39 |
|
| 40 | /*
|
| 41 | * ------------------------------------------------------
|
| 42 | * Load the compatibility override functions
|
| 43 | * ------------------------------------------------------
|
| 44 | */
|
| 45 | require(BASEPATH.'codeigniter/Compat'.EXT);
|
Derek Jones | 3ad8efe | 2008-04-04 18:56:04 +0000 | [diff] [blame] | 46 |
|
| 47 | /*
|
| 48 | * ------------------------------------------------------
|
Derek Jones | e146ed7 | 2008-04-08 20:29:53 +0000 | [diff] [blame] | 49 | * Load the framework constants
|
Derek Jones | 3ad8efe | 2008-04-04 18:56:04 +0000 | [diff] [blame] | 50 | * ------------------------------------------------------
|
| 51 | */
|
| 52 | require(APPPATH.'config/constants'.EXT);
|
| 53 |
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 54 | /*
|
| 55 | * ------------------------------------------------------
|
| 56 | * Define a custom error handler so we can log PHP errors
|
| 57 | * ------------------------------------------------------
|
| 58 | */
|
| 59 | set_error_handler('_exception_handler');
|
| 60 | set_magic_quotes_runtime(0); // Kill magic quotes
|
| 61 |
|
| 62 | /*
|
| 63 | * ------------------------------------------------------
|
| 64 | * Start the timer... tick tock tick tock...
|
| 65 | * ------------------------------------------------------
|
| 66 | */
|
| 67 |
|
| 68 | $BM =& load_class('Benchmark');
|
| 69 | $BM->mark('total_execution_time_start');
|
| 70 | $BM->mark('loading_time_base_classes_start');
|
| 71 |
|
| 72 | /*
|
| 73 | * ------------------------------------------------------
|
| 74 | * Instantiate the hooks class
|
| 75 | * ------------------------------------------------------
|
| 76 | */
|
| 77 |
|
| 78 | $EXT =& load_class('Hooks');
|
| 79 |
|
| 80 | /*
|
| 81 | * ------------------------------------------------------
|
| 82 | * Is there a "pre_system" hook?
|
| 83 | * ------------------------------------------------------
|
| 84 | */
|
| 85 | $EXT->_call_hook('pre_system');
|
| 86 |
|
| 87 | /*
|
| 88 | * ------------------------------------------------------
|
| 89 | * Instantiate the base classes
|
| 90 | * ------------------------------------------------------
|
| 91 | */
|
| 92 |
|
| 93 | $CFG =& load_class('Config');
|
| 94 | $URI =& load_class('URI');
|
| 95 | $RTR =& load_class('Router');
|
| 96 | $OUT =& load_class('Output');
|
| 97 |
|
| 98 | /*
|
| 99 | * ------------------------------------------------------
|
| 100 | * Is there a valid cache file? If so, we're done...
|
| 101 | * ------------------------------------------------------
|
| 102 | */
|
| 103 |
|
| 104 | if ($EXT->_call_hook('cache_override') === FALSE)
|
| 105 | {
|
| 106 | if ($OUT->_display_cache($CFG, $RTR) == TRUE)
|
| 107 | {
|
| 108 | exit;
|
| 109 | }
|
| 110 | }
|
| 111 |
|
| 112 | /*
|
| 113 | * ------------------------------------------------------
|
| 114 | * Load the remaining base classes
|
| 115 | * ------------------------------------------------------
|
| 116 | */
|
| 117 |
|
| 118 | $IN =& load_class('Input');
|
| 119 | $LANG =& load_class('Language');
|
| 120 |
|
| 121 | /*
|
| 122 | * ------------------------------------------------------
|
| 123 | * Load the app controller and local controller
|
| 124 | * ------------------------------------------------------
|
| 125 | *
|
| 126 | * Note: Due to the poor object handling in PHP 4 we'll
|
| 127 | * conditionally load different versions of the base
|
| 128 | * class. Retaining PHP 4 compatibility requires a bit of a hack.
|
| 129 | *
|
| 130 | * Note: The Loader class needs to be included first
|
| 131 | *
|
| 132 | */
|
| 133 | if (floor(phpversion()) < 5)
|
| 134 | {
|
| 135 | load_class('Loader', FALSE);
|
| 136 | require(BASEPATH.'codeigniter/Base4'.EXT);
|
| 137 | }
|
| 138 | else
|
| 139 | {
|
| 140 | require(BASEPATH.'codeigniter/Base5'.EXT);
|
| 141 | }
|
| 142 |
|
| 143 | // Load the base controller class
|
| 144 | load_class('Controller', FALSE);
|
| 145 |
|
| 146 | // Load the local application controller
|
| 147 | // Note: The Router class automatically validates the controller path. If this include fails it
|
| 148 | // means that the default controller in the Routes.php file is not resolving to something valid.
|
Derek Allard | 7539f67 | 2008-05-05 16:38:35 +0000 | [diff] [blame^] | 149 | if (! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 150 | {
|
| 151 | show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
|
| 152 | }
|
| 153 |
|
| 154 | include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
|
| 155 |
|
| 156 | // Set a mark point for benchmarking
|
| 157 | $BM->mark('loading_time_base_classes_end');
|
| 158 |
|
| 159 |
|
| 160 | /*
|
| 161 | * ------------------------------------------------------
|
| 162 | * Security check
|
| 163 | * ------------------------------------------------------
|
| 164 | *
|
| 165 | * None of the functions in the app controller or the
|
| 166 | * loader class can be called via the URI, nor can
|
| 167 | * controller functions that begin with an underscore
|
| 168 | */
|
| 169 | $class = $RTR->fetch_class();
|
| 170 | $method = $RTR->fetch_method();
|
| 171 |
|
| 172 |
|
Derek Allard | 7539f67 | 2008-05-05 16:38:35 +0000 | [diff] [blame^] | 173 | if (! class_exists($class)
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 174 | OR $method == 'controller'
|
| 175 | OR substr($method, 0, 1) == '_'
|
| 176 | OR in_array($method, get_class_methods('Controller'), TRUE)
|
| 177 | )
|
| 178 | {
|
Derek Jones | 8a16077 | 2008-02-27 05:19:50 +0000 | [diff] [blame] | 179 | show_404("{$class}/{$method}");
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 180 | }
|
| 181 |
|
| 182 | /*
|
| 183 | * ------------------------------------------------------
|
| 184 | * Is there a "pre_controller" hook?
|
| 185 | * ------------------------------------------------------
|
| 186 | */
|
| 187 | $EXT->_call_hook('pre_controller');
|
| 188 |
|
| 189 | /*
|
| 190 | * ------------------------------------------------------
|
| 191 | * Instantiate the controller and call requested method
|
| 192 | * ------------------------------------------------------
|
| 193 | */
|
| 194 |
|
| 195 | // Mark a start point so we can benchmark the controller
|
| 196 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
|
| 197 |
|
| 198 | $CI = new $class();
|
| 199 |
|
| 200 | // Is this a scaffolding request?
|
| 201 | if ($RTR->scaffolding_request === TRUE)
|
| 202 | {
|
| 203 | if ($EXT->_call_hook('scaffolding_override') === FALSE)
|
| 204 | {
|
| 205 | $CI->_ci_scaffolding();
|
| 206 | }
|
| 207 | }
|
| 208 | else
|
| 209 | {
|
| 210 | /*
|
| 211 | * ------------------------------------------------------
|
| 212 | * Is there a "post_controller_constructor" hook?
|
| 213 | * ------------------------------------------------------
|
| 214 | */
|
| 215 | $EXT->_call_hook('post_controller_constructor');
|
| 216 |
|
| 217 | // Is there a "remap" function?
|
| 218 | if (method_exists($CI, '_remap'))
|
| 219 | {
|
| 220 | $CI->_remap($method);
|
| 221 | }
|
| 222 | else
|
| 223 | {
|
Derek Jones | 8a16077 | 2008-02-27 05:19:50 +0000 | [diff] [blame] | 224 | // is_callable() returns TRUE on some versions of PHP 5 for private and protected
|
| 225 | // methods, so we'll use this workaround for consistent behavior
|
Derek Jones | 3951e8e | 2008-02-28 18:20:18 +0000 | [diff] [blame] | 226 | if (! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 227 | {
|
Derek Jones | 8a16077 | 2008-02-27 05:19:50 +0000 | [diff] [blame] | 228 | show_404("{$class}/{$method}");
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 229 | }
|
| 230 |
|
| 231 | // Call the requested method.
|
| 232 | // Any URI segments present (besides the class/function) will be passed to the method for convenience
|
Derek Jones | f30445b | 2008-01-30 05:23:32 +0000 | [diff] [blame] | 233 | call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 234 | }
|
| 235 | }
|
| 236 |
|
| 237 | // Mark a benchmark end point
|
| 238 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
|
| 239 |
|
| 240 | /*
|
| 241 | * ------------------------------------------------------
|
| 242 | * Is there a "post_controller" hook?
|
| 243 | * ------------------------------------------------------
|
| 244 | */
|
| 245 | $EXT->_call_hook('post_controller');
|
| 246 |
|
| 247 | /*
|
| 248 | * ------------------------------------------------------
|
| 249 | * Send the final rendered output to the browser
|
| 250 | * ------------------------------------------------------
|
| 251 | */
|
| 252 |
|
| 253 | if ($EXT->_call_hook('display_override') === FALSE)
|
| 254 | {
|
| 255 | $OUT->_display();
|
| 256 | }
|
| 257 |
|
| 258 | /*
|
| 259 | * ------------------------------------------------------
|
| 260 | * Is there a "post_system" hook?
|
| 261 | * ------------------------------------------------------
|
| 262 | */
|
| 263 | $EXT->_call_hook('post_system');
|
| 264 |
|
| 265 | /*
|
| 266 | * ------------------------------------------------------
|
| 267 | * Close the DB connection if one exists
|
| 268 | * ------------------------------------------------------
|
| 269 | */
|
| 270 | if (class_exists('CI_DB') AND isset($CI->db))
|
| 271 | {
|
| 272 | $CI->db->close();
|
| 273 | }
|
| 274 |
|
| 275 |
|
| 276 | ?> |