00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 00002 /** 00003 * CodeIgniter 00004 * 00005 * An open source application development framework for PHP 4.3.2 or newer 00006 * 00007 * @package CodeIgniter 00008 * @author ExpressionEngine Dev Team 00009 * @copyright Copyright (c) 2008, EllisLab, Inc. 00010 * @license http://codeigniter.com/user_guide/license.html 00011 * @link http://codeigniter.com 00012 * @since Version 1.0 00013 * @filesource 00014 */ 00015 00016 // ------------------------------------------------------------------------ 00017 00018 /** 00019 * System Front Controller 00020 * 00021 * Loads the base classes and executes the request. 00022 * 00023 * @package CodeIgniter 00024 * @subpackage codeigniter 00025 * @category Front-controller 00026 * @author ExpressionEngine Dev Team 00027 * @link http://codeigniter.com/user_guide/ 00028 */ 00029 00030 // CI Version 00031 define('CI_VERSION', '1.7.0'); 00032 00033 /* 00034 * ------------------------------------------------------ 00035 * Load the global functions 00036 * ------------------------------------------------------ 00037 */ 00038 require(BASEPATH.'codeigniter/Common'.EXT); 00039 00040 /* 00041 * ------------------------------------------------------ 00042 * Load the compatibility override functions 00043 * ------------------------------------------------------ 00044 */ 00045 require(BASEPATH.'codeigniter/Compat'.EXT); 00046 00047 /* 00048 * ------------------------------------------------------ 00049 * Load the framework constants 00050 * ------------------------------------------------------ 00051 */ 00052 require(APPPATH.'config/constants'.EXT); 00053 00054 /* 00055 * ------------------------------------------------------ 00056 * Define a custom error handler so we can log PHP errors 00057 * ------------------------------------------------------ 00058 */ 00059 set_error_handler('_exception_handler'); 00060 set_magic_quotes_runtime(0); // Kill magic quotes 00061 00062 /* 00063 * ------------------------------------------------------ 00064 * Start the timer... tick tock tick tock... 00065 * ------------------------------------------------------ 00066 */ 00067 00068 $BM =& load_class('Benchmark'); 00069 $BM->mark('total_execution_time_start'); 00070 $BM->mark('loading_time_base_classes_start'); 00071 00072 /* 00073 * ------------------------------------------------------ 00074 * Instantiate the hooks class 00075 * ------------------------------------------------------ 00076 */ 00077 00078 $EXT =& load_class('Hooks'); 00079 00080 /* 00081 * ------------------------------------------------------ 00082 * Is there a "pre_system" hook? 00083 * ------------------------------------------------------ 00084 */ 00085 $EXT->_call_hook('pre_system'); 00086 00087 /* 00088 * ------------------------------------------------------ 00089 * Instantiate the base classes 00090 * ------------------------------------------------------ 00091 */ 00092 00093 $CFG =& load_class('Config'); 00094 $URI =& load_class('URI'); 00095 $RTR =& load_class('Router'); 00096 $OUT =& load_class('Output'); 00097 00098 /* 00099 * ------------------------------------------------------ 00100 * Is there a valid cache file? If so, we're done... 00101 * ------------------------------------------------------ 00102 */ 00103 00104 if ($EXT->_call_hook('cache_override') === FALSE) 00105 { 00106 if ($OUT->_display_cache($CFG, $URI) == TRUE) 00107 { 00108 exit; 00109 } 00110 } 00111 00112 /* 00113 * ------------------------------------------------------ 00114 * Load the remaining base classes 00115 * ------------------------------------------------------ 00116 */ 00117 00118 $IN =& load_class('Input'); 00119 $LANG =& load_class('Language'); 00120 00121 /* 00122 * ------------------------------------------------------ 00123 * Load the app controller and local controller 00124 * ------------------------------------------------------ 00125 * 00126 * Note: Due to the poor object handling in PHP 4 we'll 00127 * conditionally load different versions of the base 00128 * class. Retaining PHP 4 compatibility requires a bit of a hack. 00129 * 00130 * Note: The Loader class needs to be included first 00131 * 00132 */ 00133 if (floor(phpversion()) < 5) 00134 { 00135 load_class('Loader', FALSE); 00136 require(BASEPATH.'codeigniter/Base4'.EXT); 00137 } 00138 else 00139 { 00140 require(BASEPATH.'codeigniter/Base5'.EXT); 00141 } 00142 00143 // Load the base controller class 00144 load_class('Controller', FALSE); 00145 00146 // Load the local application controller 00147 // Note: The Router class automatically validates the controller path. If this include fails it 00148 // means that the default controller in the Routes.php file is not resolving to something valid. 00149 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) 00150 { 00151 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); 00152 } 00153 00154 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); 00155 00156 // Set a mark point for benchmarking 00157 $BM->mark('loading_time_base_classes_end'); 00158 00159 00160 /* 00161 * ------------------------------------------------------ 00162 * Security check 00163 * ------------------------------------------------------ 00164 * 00165 * None of the functions in the app controller or the 00166 * loader class can be called via the URI, nor can 00167 * controller functions that begin with an underscore 00168 */ 00169 $class = $RTR->fetch_class(); 00170 $method = $RTR->fetch_method(); 00171 00172 if ( ! class_exists($class) 00173 OR $method == 'controller' 00174 OR strncmp($method, '_', 1) == 0 00175 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) 00176 ) 00177 { 00178 show_404("{$class}/{$method}"); 00179 } 00180 00181 /* 00182 * ------------------------------------------------------ 00183 * Is there a "pre_controller" hook? 00184 * ------------------------------------------------------ 00185 */ 00186 $EXT->_call_hook('pre_controller'); 00187 00188 /* 00189 * ------------------------------------------------------ 00190 * Instantiate the controller and call requested method 00191 * ------------------------------------------------------ 00192 */ 00193 00194 // Mark a start point so we can benchmark the controller 00195 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); 00196 00197 $CI = new $class(); 00198 00199 // Is this a scaffolding request? 00200 if ($RTR->scaffolding_request === TRUE) 00201 { 00202 if ($EXT->_call_hook('scaffolding_override') === FALSE) 00203 { 00204 $CI->_ci_scaffolding(); 00205 } 00206 } 00207 else 00208 { 00209 /* 00210 * ------------------------------------------------------ 00211 * Is there a "post_controller_constructor" hook? 00212 * ------------------------------------------------------ 00213 */ 00214 $EXT->_call_hook('post_controller_constructor'); 00215 00216 // Is there a "remap" function? 00217 if (method_exists($CI, '_remap')) 00218 { 00219 $CI->_remap($method); 00220 } 00221 else 00222 { 00223 // is_callable() returns TRUE on some versions of PHP 5 for private and protected 00224 // methods, so we'll use this workaround for consistent behavior 00225 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI)))) 00226 { 00227 show_404("{$class}/{$method}"); 00228 } 00229 00230 // Call the requested method. 00231 // Any URI segments present (besides the class/function) will be passed to the method for convenience 00232 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2)); 00233 } 00234 } 00235 00236 // Mark a benchmark end point 00237 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); 00238 00239 /* 00240 * ------------------------------------------------------ 00241 * Is there a "post_controller" hook? 00242 * ------------------------------------------------------ 00243 */ 00244 $EXT->_call_hook('post_controller'); 00245 00246 /* 00247 * ------------------------------------------------------ 00248 * Send the final rendered output to the browser 00249 * ------------------------------------------------------ 00250 */ 00251 00252 if ($EXT->_call_hook('display_override') === FALSE) 00253 { 00254 $OUT->_display(); 00255 } 00256 00257 /* 00258 * ------------------------------------------------------ 00259 * Is there a "post_system" hook? 00260 * ------------------------------------------------------ 00261 */ 00262 $EXT->_call_hook('post_system'); 00263 00264 /* 00265 * ------------------------------------------------------ 00266 * Close the DB connection if one exists 00267 * ------------------------------------------------------ 00268 */ 00269 if (class_exists('CI_DB') AND isset($CI->db)) 00270 { 00271 $CI->db->close(); 00272 } 00273 00274 00275 /* End of file CodeIgniter.php */ 00276 /* Location: ./system/codeigniter/CodeIgniter.php */