blob: 5146c807dad12f1e6e79079a7f251cd06751718f [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 */
adminaf436d72006-09-15 20:02:14 +000069$EXT->_call_hook('pre_system');
adminb0dd10f2006-08-25 17:25:49 +000070
71/*
72 * ------------------------------------------------------
73 * Instantiate the base classes
74 * ------------------------------------------------------
75 */
76
77$CFG =& _load_class('CI_Config');
78$RTR =& _load_class('CI_Router');
79$OUT =& _load_class('CI_Output');
80
81/*
82 * ------------------------------------------------------
83 * Is there a valid cache file? If so, we're done...
84 * ------------------------------------------------------
85 */
86
adminaf436d72006-09-15 20:02:14 +000087if ($EXT->_call_hook('cache_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +000088{
admin06508c42006-09-18 08:18:08 +000089 if ($OUT->_display_cache($CFG, $RTR) == TRUE)
adminb0dd10f2006-08-25 17:25:49 +000090 {
91 exit;
92 }
93}
94
95/*
96 * ------------------------------------------------------
adminb0dd10f2006-08-25 17:25:49 +000097 * Load the remaining base classes
98 * ------------------------------------------------------
99 */
100
101$IN =& _load_class('CI_Input');
102$URI =& _load_class('CI_URI');
103$LANG =& _load_class('CI_Language');
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
adminb071bb52006-08-26 19:28:37 +0000118_load_class('CI_Loader', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000119
120if (floor(phpversion()) < 5)
121{
122 require(BASEPATH.'codeigniter/Base4'.EXT);
123}
124else
125{
126 require(BASEPATH.'codeigniter/Base5'.EXT);
127}
128
adminb071bb52006-08-26 19:28:37 +0000129_load_class('CI_Controller', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000130
admin45c872b2006-08-26 04:51:38 +0000131require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
adminb0dd10f2006-08-25 17:25:49 +0000132
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
145if ( ! class_exists($class)
146 OR $method == 'controller'
147 OR substr($method, 0, 1) == '_'
148 OR in_array($method, get_class_methods('Controller'))
149 )
150{
151 show_404();
152}
153
154/*
155 * ------------------------------------------------------
156 * Is there a "pre_controller" hook?
157 * ------------------------------------------------------
158 */
adminaf436d72006-09-15 20:02:14 +0000159$EXT->_call_hook('pre_controller');
adminb0dd10f2006-08-25 17:25:49 +0000160
161/*
162 * ------------------------------------------------------
163 * Instantiate the controller and call requested method
164 * ------------------------------------------------------
165 */
166$CI = new $class();
167
168if ($RTR->scaffolding_request === TRUE)
169{
adminaf436d72006-09-15 20:02:14 +0000170 if ($EXT->_call_hook('scaffolding_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000171 {
172 $CI->_ci_scaffolding();
173 }
174}
175else
176{
admineb567c72006-09-06 02:48:47 +0000177 /*
178 * ------------------------------------------------------
179 * Is there a "post_controller_constructor" hook?
180 * ------------------------------------------------------
181 */
adminaf436d72006-09-15 20:02:14 +0000182 $EXT->_call_hook('post_controller_constructor');
admineb567c72006-09-06 02:48:47 +0000183
admineb6db842006-09-02 02:39:45 +0000184 if ($method == $class)
185 {
186 $method = 'index';
187 }
adminb0dd10f2006-08-25 17:25:49 +0000188
admin1cf89aa2006-09-03 18:24:39 +0000189 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 }
199
200 $CI->$method();
201 }
adminb0dd10f2006-08-25 17:25:49 +0000202}
203
204/*
205 * ------------------------------------------------------
206 * Is there a "post_controller" hook?
207 * ------------------------------------------------------
208 */
adminaf436d72006-09-15 20:02:14 +0000209$EXT->_call_hook('post_controller');
adminb0dd10f2006-08-25 17:25:49 +0000210
211/*
212 * ------------------------------------------------------
213 * Send the final rendered output to the browser
214 * ------------------------------------------------------
215 */
216
adminaf436d72006-09-15 20:02:14 +0000217if ($EXT->_call_hook('display_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000218{
219 $OUT->_display();
220}
221
222/*
223 * ------------------------------------------------------
224 * Is there a "post_system" hook?
225 * ------------------------------------------------------
226 */
adminaf436d72006-09-15 20:02:14 +0000227$EXT->_call_hook('post_system');
adminb0dd10f2006-08-25 17:25:49 +0000228
229/*
230 * ------------------------------------------------------
231 * Close the DB connection of one exists
232 * ------------------------------------------------------
233 */
234if ($CI->_ci_is_loaded('db'))
235{
236 $CI->db->close();
237}
238
239
240?>