blob: 5c3d19b768f8eda39ba4d51c42bb9aeaf1b0c321 [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{
admineb6db842006-09-02 02:39:45 +0000191 if ($method == $class)
192 {
193 $method = 'index';
194 }
adminb0dd10f2006-08-25 17:25:49 +0000195
admin1cf89aa2006-09-03 18:24:39 +0000196 if (method_exists($CI, '_remap'))
197 {
198 $CI->_remap($method);
199 }
200 else
201 {
202 if ( ! method_exists($CI, $method))
203 {
204 show_404();
205 }
206
207 $CI->$method();
208 }
adminb0dd10f2006-08-25 17:25:49 +0000209}
210
211/*
212 * ------------------------------------------------------
213 * Is there a "post_controller" hook?
214 * ------------------------------------------------------
215 */
216if ($EXT->_hook_exists('post_controller'))
217{
218 $EXT->_call_hook('post_controller');
219}
220
221/*
222 * ------------------------------------------------------
223 * Send the final rendered output to the browser
224 * ------------------------------------------------------
225 */
226
227if ($EXT->_hook_exists('display_override'))
228{
229 $EXT->_call_hook('display_override');
230}
231else
232{
233 $OUT->_display();
234}
235
236/*
237 * ------------------------------------------------------
238 * Is there a "post_system" hook?
239 * ------------------------------------------------------
240 */
241if ($EXT->_hook_exists('post_system'))
242{
243 $EXT->_call_hook('post_system');
244}
245
246/*
247 * ------------------------------------------------------
248 * Close the DB connection of one exists
249 * ------------------------------------------------------
250 */
251if ($CI->_ci_is_loaded('db'))
252{
253 $CI->db->close();
254}
255
256
257?>