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 | * ------------------------------------------------------ |
| 41 | * Define a custom error handler so we can log errors |
| 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 | 33de9a1 | 2006-09-28 06:50:16 +0000 | [diff] [blame] | 53 | $BM =& _load_class('Benchmark'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 54 | $BM->mark('code_igniter_start'); |
| 55 | |
| 56 | /* |
| 57 | * ------------------------------------------------------ |
| 58 | * Instantiate the hooks classe |
| 59 | * ------------------------------------------------------ |
| 60 | */ |
| 61 | |
admin | 33de9a1 | 2006-09-28 06:50:16 +0000 | [diff] [blame] | 62 | $EXT =& _load_class('Hooks'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * ------------------------------------------------------ |
| 66 | * Is there a "pre_system" hook? |
| 67 | * ------------------------------------------------------ |
| 68 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 69 | $EXT->_call_hook('pre_system'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * ------------------------------------------------------ |
| 73 | * Instantiate the base classes |
| 74 | * ------------------------------------------------------ |
| 75 | */ |
| 76 | |
admin | 33de9a1 | 2006-09-28 06:50:16 +0000 | [diff] [blame] | 77 | $CFG =& _load_class('Config'); |
| 78 | $RTR =& _load_class('Router'); |
| 79 | $OUT =& _load_class('Output'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * ------------------------------------------------------ |
| 83 | * Is there a valid cache file? If so, we're done... |
| 84 | * ------------------------------------------------------ |
| 85 | */ |
| 86 | |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 87 | if ($EXT->_call_hook('cache_override') === FALSE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 88 | { |
admin | 06508c4 | 2006-09-18 08:18:08 +0000 | [diff] [blame] | 89 | if ($OUT->_display_cache($CFG, $RTR) == TRUE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 90 | { |
| 91 | exit; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * ------------------------------------------------------ |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 97 | * Load the remaining base classes |
| 98 | * ------------------------------------------------------ |
| 99 | */ |
| 100 | |
admin | 33de9a1 | 2006-09-28 06:50:16 +0000 | [diff] [blame] | 101 | $IN =& _load_class('Input'); |
| 102 | $URI =& _load_class('URI'); |
| 103 | $LANG =& _load_class('Language'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 104 | |
| 105 | /* |
| 106 | * ------------------------------------------------------ |
| 107 | * Load the app controller and local controller |
| 108 | * ------------------------------------------------------ |
| 109 | * |
| 110 | * Note: Due to the poor object handling in PHP 4 we'll |
| 111 | * contditionally load different versions of the base |
| 112 | * class. Retaining PHP 4 compatibility requires a bit of a hack. |
| 113 | * |
| 114 | * Note: The Loader class needs to be included first |
| 115 | * |
| 116 | */ |
| 117 | |
admin | 33de9a1 | 2006-09-28 06:50:16 +0000 | [diff] [blame] | 118 | _load_class('Loader', FALSE); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 119 | |
| 120 | if (floor(phpversion()) < 5) |
| 121 | { |
| 122 | require(BASEPATH.'codeigniter/Base4'.EXT); |
| 123 | } |
| 124 | else |
| 125 | { |
| 126 | require(BASEPATH.'codeigniter/Base5'.EXT); |
| 127 | } |
| 128 | |
admin | 33de9a1 | 2006-09-28 06:50:16 +0000 | [diff] [blame] | 129 | _load_class('Controller', FALSE); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 130 | |
admin | 45c872b | 2006-08-26 04:51:38 +0000 | [diff] [blame] | 131 | require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 132 | |
| 133 | /* |
| 134 | * ------------------------------------------------------ |
| 135 | * Security check |
| 136 | * ------------------------------------------------------ |
| 137 | * |
| 138 | * None of the functions in the app controller or the |
| 139 | * loader class can be called via the URI, nor can |
| 140 | * controller functions that begin with an underscore |
| 141 | */ |
| 142 | $class = $RTR->fetch_class(); |
| 143 | $method = $RTR->fetch_method(); |
| 144 | |
| 145 | if ( ! class_exists($class) |
| 146 | OR $method == 'controller' |
| 147 | OR substr($method, 0, 1) == '_' |
admin | ee54c11 | 2006-09-28 17:13:38 +0000 | [diff] [blame] | 148 | OR in_array($method, get_class_methods('Controller'), TRUE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 149 | ) |
| 150 | { |
| 151 | show_404(); |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * ------------------------------------------------------ |
| 156 | * Is there a "pre_controller" hook? |
| 157 | * ------------------------------------------------------ |
| 158 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 159 | $EXT->_call_hook('pre_controller'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * ------------------------------------------------------ |
| 163 | * Instantiate the controller and call requested method |
| 164 | * ------------------------------------------------------ |
| 165 | */ |
| 166 | $CI = new $class(); |
| 167 | |
| 168 | if ($RTR->scaffolding_request === TRUE) |
| 169 | { |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 170 | if ($EXT->_call_hook('scaffolding_override') === FALSE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 171 | { |
| 172 | $CI->_ci_scaffolding(); |
| 173 | } |
| 174 | } |
| 175 | else |
| 176 | { |
admin | eb567c7 | 2006-09-06 02:48:47 +0000 | [diff] [blame] | 177 | /* |
| 178 | * ------------------------------------------------------ |
| 179 | * Is there a "post_controller_constructor" hook? |
| 180 | * ------------------------------------------------------ |
| 181 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 182 | $EXT->_call_hook('post_controller_constructor'); |
admin | eb567c7 | 2006-09-06 02:48:47 +0000 | [diff] [blame] | 183 | |
admin | eb6db84 | 2006-09-02 02:39:45 +0000 | [diff] [blame] | 184 | if ($method == $class) |
| 185 | { |
| 186 | $method = 'index'; |
| 187 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 188 | |
admin | 1cf89aa | 2006-09-03 18:24:39 +0000 | [diff] [blame] | 189 | if (method_exists($CI, '_remap')) |
| 190 | { |
| 191 | $CI->_remap($method); |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | if ( ! method_exists($CI, $method)) |
| 196 | { |
| 197 | show_404(); |
| 198 | } |
admin | 8407cca | 2006-09-23 01:22:56 +0000 | [diff] [blame] | 199 | |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 200 | // Call the requested method. |
| 201 | // 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] | 202 | 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] | 203 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /* |
| 207 | * ------------------------------------------------------ |
| 208 | * Is there a "post_controller" hook? |
| 209 | * ------------------------------------------------------ |
| 210 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 211 | $EXT->_call_hook('post_controller'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 212 | |
| 213 | /* |
| 214 | * ------------------------------------------------------ |
| 215 | * Send the final rendered output to the browser |
| 216 | * ------------------------------------------------------ |
| 217 | */ |
| 218 | |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 219 | if ($EXT->_call_hook('display_override') === FALSE) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 220 | { |
| 221 | $OUT->_display(); |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * ------------------------------------------------------ |
| 226 | * Is there a "post_system" hook? |
| 227 | * ------------------------------------------------------ |
| 228 | */ |
admin | af436d7 | 2006-09-15 20:02:14 +0000 | [diff] [blame] | 229 | $EXT->_call_hook('post_system'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 230 | |
| 231 | /* |
| 232 | * ------------------------------------------------------ |
| 233 | * Close the DB connection of one exists |
| 234 | * ------------------------------------------------------ |
| 235 | */ |
| 236 | if ($CI->_ci_is_loaded('db')) |
| 237 | { |
| 238 | $CI->db->close(); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | ?> |