blob: e09bf3debe64db67086fc0df378c9eaa0e08db6c [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?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
adminb071bb52006-08-26 19:28:37 +000030define('APPVER', '1.4.0');
adminb0dd10f2006-08-25 17:25:49 +000031
32/*
33 * ------------------------------------------------------
34 * Load the global functions
35 * ------------------------------------------------------
36 */
37require(BASEPATH.'codeigniter/Common'.EXT);
38
39/*
40 * ------------------------------------------------------
41 * Define a custom error handler so we can log errors
42 * ------------------------------------------------------
43 */
44set_error_handler('_exception_handler');
45set_magic_quotes_runtime(0); // Kill magic quotes
46
47/*
48 * ------------------------------------------------------
49 * Start the timer... tick tock tick tock...
50 * ------------------------------------------------------
51 */
52
53$BM =& _load_class('CI_Benchmark');
54$BM->mark('code_igniter_start');
55
56/*
57 * ------------------------------------------------------
58 * Instantiate the hooks classe
59 * ------------------------------------------------------
60 */
61
62$EXT =& _load_class('CI_Hooks');
63
64/*
65 * ------------------------------------------------------
66 * Is there a "pre_system" hook?
67 * ------------------------------------------------------
68 */
69if ($EXT->_hook_exists('pre_system'))
70{
71 $EXT->_call_hook('pre_system');
72}
73
74/*
75 * ------------------------------------------------------
76 * Instantiate the base classes
77 * ------------------------------------------------------
78 */
79
80$CFG =& _load_class('CI_Config');
81$RTR =& _load_class('CI_Router');
82$OUT =& _load_class('CI_Output');
83
84/*
85 * ------------------------------------------------------
86 * Is there a valid cache file? If so, we're done...
87 * ------------------------------------------------------
88 */
89
90if ($EXT->_hook_exists('cache_override'))
91{
92 $EXT->_call_hook('cache_override');
93}
94else
95{
96 if ($OUT->_display_cache() == TRUE)
97 {
98 exit;
99 }
100}
101
102/*
103 * ------------------------------------------------------
adminb0dd10f2006-08-25 17:25:49 +0000104 * Load the remaining base classes
105 * ------------------------------------------------------
106 */
107
108$IN =& _load_class('CI_Input');
109$URI =& _load_class('CI_URI');
110$LANG =& _load_class('CI_Language');
111
112/*
113 * ------------------------------------------------------
114 * Load the app controller and local controller
115 * ------------------------------------------------------
116 *
117 * Note: Due to the poor object handling in PHP 4 we'll
118 * contditionally load different versions of the base
119 * class. Retaining PHP 4 compatibility requires a bit of a hack.
120 *
121 * Note: The Loader class needs to be included first
122 *
123 */
124
adminb071bb52006-08-26 19:28:37 +0000125_load_class('CI_Loader', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000126
127if (floor(phpversion()) < 5)
128{
129 require(BASEPATH.'codeigniter/Base4'.EXT);
130}
131else
132{
133 require(BASEPATH.'codeigniter/Base5'.EXT);
134}
135
adminb071bb52006-08-26 19:28:37 +0000136_load_class('CI_Controller', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000137
admin45c872b2006-08-26 04:51:38 +0000138require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
adminb0dd10f2006-08-25 17:25:49 +0000139
140/*
141 * ------------------------------------------------------
142 * Security check
143 * ------------------------------------------------------
144 *
145 * None of the functions in the app controller or the
146 * loader class can be called via the URI, nor can
147 * controller functions that begin with an underscore
148 */
149$class = $RTR->fetch_class();
150$method = $RTR->fetch_method();
151
152if ( ! class_exists($class)
153 OR $method == 'controller'
154 OR substr($method, 0, 1) == '_'
155 OR in_array($method, get_class_methods('Controller'))
156 )
157{
158 show_404();
159}
160
161/*
162 * ------------------------------------------------------
163 * Is there a "pre_controller" hook?
164 * ------------------------------------------------------
165 */
166if ($EXT->_hook_exists('pre_controller'))
167{
168 $EXT->_call_hook('pre_controller');
169}
170
171/*
172 * ------------------------------------------------------
173 * Instantiate the controller and call requested method
174 * ------------------------------------------------------
175 */
176$CI = new $class();
177
178if ($RTR->scaffolding_request === TRUE)
179{
180 if ($EXT->_hook_exists('scaffolding_override'))
181 {
182 $EXT->_call_hook('scaffolding_override');
183 }
184 else
185 {
186 $CI->_ci_scaffolding();
187 }
188}
189else
190{
admineb567c72006-09-06 02:48:47 +0000191 /*
192 * ------------------------------------------------------
193 * Is there a "post_controller_constructor" hook?
194 * ------------------------------------------------------
195 */
196 if ($EXT->_hook_exists('post_controller_constructor'))
197 {
198 $EXT->_call_hook('post_controller_constructor');
199 }
200
admineb6db842006-09-02 02:39:45 +0000201 if ($method == $class)
202 {
203 $method = 'index';
204 }
adminb0dd10f2006-08-25 17:25:49 +0000205
admin1cf89aa2006-09-03 18:24:39 +0000206 if (method_exists($CI, '_remap'))
207 {
208 $CI->_remap($method);
209 }
210 else
211 {
212 if ( ! method_exists($CI, $method))
213 {
214 show_404();
215 }
216
217 $CI->$method();
218 }
adminb0dd10f2006-08-25 17:25:49 +0000219}
220
221/*
222 * ------------------------------------------------------
223 * Is there a "post_controller" hook?
224 * ------------------------------------------------------
225 */
226if ($EXT->_hook_exists('post_controller'))
227{
228 $EXT->_call_hook('post_controller');
229}
230
231/*
232 * ------------------------------------------------------
233 * Send the final rendered output to the browser
234 * ------------------------------------------------------
235 */
236
237if ($EXT->_hook_exists('display_override'))
238{
239 $EXT->_call_hook('display_override');
240}
241else
242{
243 $OUT->_display();
244}
245
246/*
247 * ------------------------------------------------------
248 * Is there a "post_system" hook?
249 * ------------------------------------------------------
250 */
251if ($EXT->_hook_exists('post_system'))
252{
253 $EXT->_call_hook('post_system');
254}
255
256/*
257 * ------------------------------------------------------
258 * Close the DB connection of one exists
259 * ------------------------------------------------------
260 */
261if ($CI->_ci_is_loaded('db'))
262{
263 $CI->db->close();
264}
265
266
267?>