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.
|
| 10 | * @license http://www.codeigniter.com/user_guide/license.html
|
| 11 | * @link http://www.codeigniter.com
|
| 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
|
| 27 | * @link http://www.codeigniter.com/user_guide/
|
| 28 | */
|
| 29 |
|
| 30 | // CI Version
|
| 31 | define('CI_VERSION', '1.5.5');
|
| 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);
|
| 46 |
|
| 47 | /*
|
| 48 | * ------------------------------------------------------
|
| 49 | * Define a custom error handler so we can log PHP errors
|
| 50 | * ------------------------------------------------------
|
| 51 | */
|
| 52 | set_error_handler('_exception_handler');
|
| 53 | set_magic_quotes_runtime(0); // Kill magic quotes
|
| 54 |
|
| 55 | /*
|
| 56 | * ------------------------------------------------------
|
| 57 | * Start the timer... tick tock tick tock...
|
| 58 | * ------------------------------------------------------
|
| 59 | */
|
| 60 |
|
| 61 | $BM =& load_class('Benchmark');
|
| 62 | $BM->mark('total_execution_time_start');
|
| 63 | $BM->mark('loading_time_base_classes_start');
|
| 64 |
|
| 65 | /*
|
| 66 | * ------------------------------------------------------
|
| 67 | * Instantiate the hooks class
|
| 68 | * ------------------------------------------------------
|
| 69 | */
|
| 70 |
|
| 71 | $EXT =& load_class('Hooks');
|
| 72 |
|
| 73 | /*
|
| 74 | * ------------------------------------------------------
|
| 75 | * Is there a "pre_system" hook?
|
| 76 | * ------------------------------------------------------
|
| 77 | */
|
| 78 | $EXT->_call_hook('pre_system');
|
| 79 |
|
| 80 | /*
|
| 81 | * ------------------------------------------------------
|
| 82 | * Instantiate the base classes
|
| 83 | * ------------------------------------------------------
|
| 84 | */
|
| 85 |
|
| 86 | $CFG =& load_class('Config');
|
| 87 | $URI =& load_class('URI');
|
| 88 | $RTR =& load_class('Router');
|
| 89 | $OUT =& load_class('Output');
|
| 90 |
|
| 91 | /*
|
| 92 | * ------------------------------------------------------
|
| 93 | * Is there a valid cache file? If so, we're done...
|
| 94 | * ------------------------------------------------------
|
| 95 | */
|
| 96 |
|
| 97 | if ($EXT->_call_hook('cache_override') === FALSE)
|
| 98 | {
|
| 99 | if ($OUT->_display_cache($CFG, $RTR) == TRUE)
|
| 100 | {
|
| 101 | exit;
|
| 102 | }
|
| 103 | }
|
| 104 |
|
| 105 | /*
|
| 106 | * ------------------------------------------------------
|
| 107 | * Load the remaining base classes
|
| 108 | * ------------------------------------------------------
|
| 109 | */
|
| 110 |
|
| 111 | $IN =& load_class('Input');
|
| 112 | $LANG =& load_class('Language');
|
| 113 |
|
| 114 | /*
|
| 115 | * ------------------------------------------------------
|
| 116 | * Load the app controller and local controller
|
| 117 | * ------------------------------------------------------
|
| 118 | *
|
| 119 | * Note: Due to the poor object handling in PHP 4 we'll
|
| 120 | * conditionally load different versions of the base
|
| 121 | * class. Retaining PHP 4 compatibility requires a bit of a hack.
|
| 122 | *
|
| 123 | * Note: The Loader class needs to be included first
|
| 124 | *
|
| 125 | */
|
| 126 | if (floor(phpversion()) < 5)
|
| 127 | {
|
| 128 | load_class('Loader', FALSE);
|
| 129 | require(BASEPATH.'codeigniter/Base4'.EXT);
|
| 130 | }
|
| 131 | else
|
| 132 | {
|
| 133 | require(BASEPATH.'codeigniter/Base5'.EXT);
|
| 134 | }
|
| 135 |
|
| 136 | // Load the base controller class
|
| 137 | load_class('Controller', FALSE);
|
| 138 |
|
| 139 | // Load the local application controller
|
| 140 | // Note: The Router class automatically validates the controller path. If this include fails it
|
| 141 | // means that the default controller in the Routes.php file is not resolving to something valid.
|
| 142 | if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
|
| 143 | {
|
| 144 | show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
|
| 145 | }
|
| 146 |
|
| 147 | include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
|
| 148 |
|
| 149 | // Set a mark point for benchmarking
|
| 150 | $BM->mark('loading_time_base_classes_end');
|
| 151 |
|
| 152 |
|
| 153 | /*
|
| 154 | * ------------------------------------------------------
|
| 155 | * Security check
|
| 156 | * ------------------------------------------------------
|
| 157 | *
|
| 158 | * None of the functions in the app controller or the
|
| 159 | * loader class can be called via the URI, nor can
|
| 160 | * controller functions that begin with an underscore
|
| 161 | */
|
| 162 | $class = $RTR->fetch_class();
|
| 163 | $method = $RTR->fetch_method();
|
| 164 |
|
| 165 |
|
| 166 | if ( ! class_exists($class)
|
| 167 | OR $method == 'controller'
|
| 168 | OR substr($method, 0, 1) == '_'
|
| 169 | OR in_array($method, get_class_methods('Controller'), TRUE)
|
| 170 | )
|
| 171 | {
|
| 172 | show_404();
|
| 173 | }
|
| 174 |
|
| 175 | /*
|
| 176 | * ------------------------------------------------------
|
| 177 | * Is there a "pre_controller" hook?
|
| 178 | * ------------------------------------------------------
|
| 179 | */
|
| 180 | $EXT->_call_hook('pre_controller');
|
| 181 |
|
| 182 | /*
|
| 183 | * ------------------------------------------------------
|
| 184 | * Instantiate the controller and call requested method
|
| 185 | * ------------------------------------------------------
|
| 186 | */
|
| 187 |
|
| 188 | // Mark a start point so we can benchmark the controller
|
| 189 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
|
| 190 |
|
| 191 | $CI = new $class();
|
| 192 |
|
| 193 | // Is this a scaffolding request?
|
| 194 | if ($RTR->scaffolding_request === TRUE)
|
| 195 | {
|
| 196 | if ($EXT->_call_hook('scaffolding_override') === FALSE)
|
| 197 | {
|
| 198 | $CI->_ci_scaffolding();
|
| 199 | }
|
| 200 | }
|
| 201 | else
|
| 202 | {
|
| 203 | /*
|
| 204 | * ------------------------------------------------------
|
| 205 | * Is there a "post_controller_constructor" hook?
|
| 206 | * ------------------------------------------------------
|
| 207 | */
|
| 208 | $EXT->_call_hook('post_controller_constructor');
|
| 209 |
|
| 210 | // Is there a "remap" function?
|
| 211 | if (method_exists($CI, '_remap'))
|
| 212 | {
|
| 213 | $CI->_remap($method);
|
| 214 | }
|
| 215 | else
|
| 216 | {
|
| 217 | if ( ! method_exists($CI, $method))
|
| 218 | {
|
| 219 | show_404();
|
| 220 | }
|
| 221 |
|
| 222 | // Call the requested method.
|
| 223 | // Any URI segments present (besides the class/function) will be passed to the method for convenience
|
| 224 | call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
|
| 225 | }
|
| 226 | }
|
| 227 |
|
| 228 | // Mark a benchmark end point
|
| 229 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
|
| 230 |
|
| 231 | /*
|
| 232 | * ------------------------------------------------------
|
| 233 | * Is there a "post_controller" hook?
|
| 234 | * ------------------------------------------------------
|
| 235 | */
|
| 236 | $EXT->_call_hook('post_controller');
|
| 237 |
|
| 238 | /*
|
| 239 | * ------------------------------------------------------
|
| 240 | * Send the final rendered output to the browser
|
| 241 | * ------------------------------------------------------
|
| 242 | */
|
| 243 |
|
| 244 | if ($EXT->_call_hook('display_override') === FALSE)
|
| 245 | {
|
| 246 | $OUT->_display();
|
| 247 | }
|
| 248 |
|
| 249 | /*
|
| 250 | * ------------------------------------------------------
|
| 251 | * Is there a "post_system" hook?
|
| 252 | * ------------------------------------------------------
|
| 253 | */
|
| 254 | $EXT->_call_hook('post_system');
|
| 255 |
|
| 256 | /*
|
| 257 | * ------------------------------------------------------
|
| 258 | * Close the DB connection if one exists
|
| 259 | * ------------------------------------------------------
|
| 260 | */
|
| 261 | if (class_exists('CI_DB') AND isset($CI->db))
|
| 262 | {
|
| 263 | $CI->db->close();
|
| 264 | }
|
| 265 |
|
| 266 |
|
| 267 | ?> |