blob: aef7618e9316d477390738d6476ec6f99e1282c9 [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
30define('APPVER', '1.4');
31
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 * ------------------------------------------------------
104 * Does the requested controller exist?
105 * ------------------------------------------------------
106 */
107if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_class().EXT))
108{
109 show_404();
110}
111
112/*
113 * ------------------------------------------------------
114 * Load the remaining base classes
115 * ------------------------------------------------------
116 */
117
118$IN =& _load_class('CI_Input');
119$URI =& _load_class('CI_URI');
120$LANG =& _load_class('CI_Language');
121
122/*
123 * ------------------------------------------------------
124 * Load the app controller and local controller
125 * ------------------------------------------------------
126 *
127 * Note: Due to the poor object handling in PHP 4 we'll
128 * contditionally load different versions of the base
129 * class. Retaining PHP 4 compatibility requires a bit of a hack.
130 *
131 * Note: The Loader class needs to be included first
132 *
133 */
134
135
136_load_class('CI_Loader');
137
138if (floor(phpversion()) < 5)
139{
140 require(BASEPATH.'codeigniter/Base4'.EXT);
141}
142else
143{
144 require(BASEPATH.'codeigniter/Base5'.EXT);
145}
146
147_load_class('CI_Controller');
148
149require(APPPATH.'controllers/'.$RTR->fetch_class().EXT);
150
151/*
152 * ------------------------------------------------------
153 * Security check
154 * ------------------------------------------------------
155 *
156 * None of the functions in the app controller or the
157 * loader class can be called via the URI, nor can
158 * controller functions that begin with an underscore
159 */
160$class = $RTR->fetch_class();
161$method = $RTR->fetch_method();
162
163if ( ! class_exists($class)
164 OR $method == 'controller'
165 OR substr($method, 0, 1) == '_'
166 OR in_array($method, get_class_methods('Controller'))
167 )
168{
169 show_404();
170}
171
172/*
173 * ------------------------------------------------------
174 * Is there a "pre_controller" hook?
175 * ------------------------------------------------------
176 */
177if ($EXT->_hook_exists('pre_controller'))
178{
179 $EXT->_call_hook('pre_controller');
180}
181
182/*
183 * ------------------------------------------------------
184 * Instantiate the controller and call requested method
185 * ------------------------------------------------------
186 */
187$CI = new $class();
188
189if ($RTR->scaffolding_request === TRUE)
190{
191 if ($EXT->_hook_exists('scaffolding_override'))
192 {
193 $EXT->_call_hook('scaffolding_override');
194 }
195 else
196 {
197 $CI->_ci_scaffolding();
198 }
199}
200else
201{
202 if ( ! method_exists($CI, $method))
203 {
204 show_404();
205 }
206
207 $CI->$method();
208}
209
210/*
211 * ------------------------------------------------------
212 * Is there a "post_controller" hook?
213 * ------------------------------------------------------
214 */
215if ($EXT->_hook_exists('post_controller'))
216{
217 $EXT->_call_hook('post_controller');
218}
219
220/*
221 * ------------------------------------------------------
222 * Send the final rendered output to the browser
223 * ------------------------------------------------------
224 */
225
226if ($EXT->_hook_exists('display_override'))
227{
228 $EXT->_call_hook('display_override');
229}
230else
231{
232 $OUT->_display();
233}
234
235/*
236 * ------------------------------------------------------
237 * Is there a "post_system" hook?
238 * ------------------------------------------------------
239 */
240if ($EXT->_hook_exists('post_system'))
241{
242 $EXT->_call_hook('post_system');
243}
244
245/*
246 * ------------------------------------------------------
247 * Close the DB connection of one exists
248 * ------------------------------------------------------
249 */
250if ($CI->_ci_is_loaded('db'))
251{
252 $CI->db->close();
253}
254
255
256?>