admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
| 10 | * @license http://www.codeignitor.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 Rick Ellis |
| 27 | * @link http://www.codeigniter.com/user_guide/ |
| 28 | */ |
| 29 | |
admin | 41a1685 | 2006-09-26 18:17:19 +0000 | [diff] [blame] | 30 | define('APPVER', '1.5.0'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * ------------------------------------------------------ |
| 34 | * Load the global functions |
| 35 | * ------------------------------------------------------ |
| 36 | */ |
| 37 | require(BASEPATH.'codeigniter/Common'.EXT); |
| 38 | |
| 39 | /* |
| 40 | * ------------------------------------------------------ |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 41 | * Define a custom error handler so we can log PHP errors |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 42 | * ------------------------------------------------------ |
| 43 | */ |
| 44 | set_error_handler('_exception_handler'); |
| 45 | set_magic_quotes_runtime(0); // Kill magic quotes |
| 46 | |
| 47 | /* |
| 48 | * ------------------------------------------------------ |
| 49 | * Start the timer... tick tock tick tock... |
| 50 | * ------------------------------------------------------ |
| 51 | */ |
| 52 | |
admin | 7099a58 | 2006-10-10 17:47:59 +0000 | [diff] [blame^] | 53 | $BM =& load_class('Benchmark'); |
admin | e26611f | 2006-10-02 21:59:12 +0000 | [diff] [blame] | 54 | $BM->mark('total_execution_time_start'); |
admin | f6edc53 | 2006-10-03 05:28:09 +0000 | [diff] [blame] | 55 | $BM->mark('loading_time_base_clases_start'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * ------------------------------------------------------ |
| 59 | * Instantiate the hooks classe |
| 60 | * ------------------------------------------------------ |
| 61 | */ |
| 62 | |
admin | 7099a58 | 2006-10-10 17:47:59 +0000 | [diff] [blame^] | 63 | $EXT =& load_class('Hooks'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * ------------------------------------------------------ |
| 67 | * Is there a "pre_system" hook? |
| 68 | * ------------------------------------------------------ |
| 69 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 70 | $EXT->_call_hook('pre_system'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * ------------------------------------------------------ |
| 74 | * Instantiate the base classes |
| 75 | * ------------------------------------------------------ |
| 76 | */ |
| 77 | |
admin | 7099a58 | 2006-10-10 17:47:59 +0000 | [diff] [blame^] | 78 | $CFG =& load_class('Config'); |
| 79 | $RTR =& load_class('Router'); |
| 80 | $OUT =& load_class('Output'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * ------------------------------------------------------ |
| 84 | * Is there a valid cache file? If so, we're done... |
| 85 | * ------------------------------------------------------ |
| 86 | */ |
| 87 | |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 88 | if ($EXT->_call_hook('cache_override') === FALSE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 89 | { |
admin | 06508c4 | 2006-09-18 08:18:08 +0000 | [diff] [blame] | 90 | if ($OUT->_display_cache($CFG, $RTR) == TRUE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 91 | { |
| 92 | exit; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * ------------------------------------------------------ |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 98 | * Load the remaining base classes |
| 99 | * ------------------------------------------------------ |
| 100 | */ |
| 101 | |
admin | 7099a58 | 2006-10-10 17:47:59 +0000 | [diff] [blame^] | 102 | $IN =& load_class('Input'); |
| 103 | $URI =& load_class('URI'); |
| 104 | $LANG =& load_class('Language'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * ------------------------------------------------------ |
| 108 | * Load the app controller and local controller |
| 109 | * ------------------------------------------------------ |
| 110 | * |
| 111 | * Note: Due to the poor object handling in PHP 4 we'll |
| 112 | * contditionally load different versions of the base |
| 113 | * class. Retaining PHP 4 compatibility requires a bit of a hack. |
| 114 | * |
| 115 | * Note: The Loader class needs to be included first |
| 116 | * |
| 117 | */ |
| 118 | |
admin | 7099a58 | 2006-10-10 17:47:59 +0000 | [diff] [blame^] | 119 | load_class('Loader', FALSE); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 120 | |
| 121 | if (floor(phpversion()) < 5) |
| 122 | { |
| 123 | require(BASEPATH.'codeigniter/Base4'.EXT); |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | require(BASEPATH.'codeigniter/Base5'.EXT); |
| 128 | } |
| 129 | |
admin | 7099a58 | 2006-10-10 17:47:59 +0000 | [diff] [blame^] | 130 | load_class('Controller', FALSE); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 131 | |
admin | 45c872b | 2006-08-26 04:51:38 +0000 | [diff] [blame] | 132 | require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 133 | |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 134 | // Set a mark point for benchmarking |
admin | f6edc53 | 2006-10-03 05:28:09 +0000 | [diff] [blame] | 135 | $BM->mark('loading_time_base_clases_end'); |
| 136 | |
| 137 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 138 | /* |
| 139 | * ------------------------------------------------------ |
| 140 | * Security check |
| 141 | * ------------------------------------------------------ |
| 142 | * |
| 143 | * None of the functions in the app controller or the |
| 144 | * loader class can be called via the URI, nor can |
| 145 | * controller functions that begin with an underscore |
| 146 | */ |
| 147 | $class = $RTR->fetch_class(); |
| 148 | $method = $RTR->fetch_method(); |
| 149 | |
admin | f6edc53 | 2006-10-03 05:28:09 +0000 | [diff] [blame] | 150 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 151 | if ( ! class_exists($class) |
| 152 | OR $method == 'controller' |
| 153 | OR substr($method, 0, 1) == '_' |
admin | ee54c11 | 2006-09-28 17:13:38 +0000 | [diff] [blame] | 154 | OR in_array($method, get_class_methods('Controller'), TRUE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 155 | ) |
| 156 | { |
| 157 | show_404(); |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * ------------------------------------------------------ |
| 162 | * Is there a "pre_controller" hook? |
| 163 | * ------------------------------------------------------ |
| 164 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 165 | $EXT->_call_hook('pre_controller'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * ------------------------------------------------------ |
| 169 | * Instantiate the controller and call requested method |
| 170 | * ------------------------------------------------------ |
| 171 | */ |
admin | f6edc53 | 2006-10-03 05:28:09 +0000 | [diff] [blame] | 172 | |
| 173 | // Mark a start point so we can benchmark the controller |
| 174 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); |
| 175 | |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 176 | // Instantiate the Controller |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 177 | $CI = new $class(); |
| 178 | |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 179 | // Is this a scaffolding request? |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 180 | if ($RTR->scaffolding_request === TRUE) |
| 181 | { |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 182 | if ($EXT->_call_hook('scaffolding_override') === FALSE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 183 | { |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 184 | $CI->_ci_scaffolding(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | else |
| 188 | { |
admin | eb567c7 | 2006-09-06 02:48:47 +0000 | [diff] [blame] | 189 | /* |
| 190 | * ------------------------------------------------------ |
| 191 | * Is there a "post_controller_constructor" hook? |
| 192 | * ------------------------------------------------------ |
| 193 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 194 | $EXT->_call_hook('post_controller_constructor'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 195 | |
admin | b3ab70b | 2006-10-07 03:07:29 +0000 | [diff] [blame] | 196 | // Is there a "remap" function? |
admin | 1cf89aa | 2006-09-03 18:24:39 +0000 | [diff] [blame] | 197 | if (method_exists($CI, '_remap')) |
| 198 | { |
| 199 | $CI->_remap($method); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | if ( ! method_exists($CI, $method)) |
| 204 | { |
| 205 | show_404(); |
| 206 | } |
admin | 8407cca | 2006-09-23 01:22:56 +0000 | [diff] [blame] | 207 | |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 208 | // Call the requested method. |
| 209 | // Any URI segments present (besides the class/function) will be passed to the method for convenience |
admin | 7d85288 | 2006-09-24 01:33:56 +0000 | [diff] [blame] | 210 | call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3))); |
admin | 1cf89aa | 2006-09-03 18:24:39 +0000 | [diff] [blame] | 211 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 212 | } |
| 213 | |
admin | f6edc53 | 2006-10-03 05:28:09 +0000 | [diff] [blame] | 214 | // Mark a benchmark end point |
| 215 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); |
| 216 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 217 | /* |
| 218 | * ------------------------------------------------------ |
| 219 | * Is there a "post_controller" hook? |
| 220 | * ------------------------------------------------------ |
| 221 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 222 | $EXT->_call_hook('post_controller'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 223 | |
| 224 | /* |
| 225 | * ------------------------------------------------------ |
| 226 | * Send the final rendered output to the browser |
| 227 | * ------------------------------------------------------ |
| 228 | */ |
| 229 | |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 230 | if ($EXT->_call_hook('display_override') === FALSE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 231 | { |
| 232 | $OUT->_display(); |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * ------------------------------------------------------ |
| 237 | * Is there a "post_system" hook? |
| 238 | * ------------------------------------------------------ |
| 239 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 240 | $EXT->_call_hook('post_system'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 241 | |
| 242 | /* |
| 243 | * ------------------------------------------------------ |
| 244 | * Close the DB connection of one exists |
| 245 | * ------------------------------------------------------ |
| 246 | */ |
admin | 8f0a8f6 | 2006-10-07 01:17:25 +0000 | [diff] [blame] | 247 | if (class_exists('CI_DB')) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 248 | { |
| 249 | $CI->db->close(); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | ?> |