blob: 4ac03820a956c576f993b68c497509992165e9be [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
admin41a16852006-09-26 18:17:19 +000030define('APPVER', '1.5.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
admin33de9a12006-09-28 06:50:16 +000053$BM =& _load_class('Benchmark');
adminb0dd10f2006-08-25 17:25:49 +000054$BM->mark('code_igniter_start');
55
56/*
57 * ------------------------------------------------------
58 * Instantiate the hooks classe
59 * ------------------------------------------------------
60 */
61
admin33de9a12006-09-28 06:50:16 +000062$EXT =& _load_class('Hooks');
adminb0dd10f2006-08-25 17:25:49 +000063
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
admin33de9a12006-09-28 06:50:16 +000077$CFG =& _load_class('Config');
78$RTR =& _load_class('Router');
79$OUT =& _load_class('Output');
adminb0dd10f2006-08-25 17:25:49 +000080
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
admin33de9a12006-09-28 06:50:16 +0000101$IN =& _load_class('Input');
102$URI =& _load_class('URI');
103$LANG =& _load_class('Language');
adminb0dd10f2006-08-25 17:25:49 +0000104
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
admin33de9a12006-09-28 06:50:16 +0000118_load_class('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
admin33de9a12006-09-28 06:50:16 +0000129_load_class('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 }
admin8407cca2006-09-23 01:22:56 +0000199
admin83b05a82006-09-25 21:06:46 +0000200 // Call the requested method.
201 // Any URI segments present (besides the class/function) will be passed to the method for convenience
admin7d852882006-09-24 01:33:56 +0000202 call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
admin1cf89aa2006-09-03 18:24:39 +0000203 }
adminb0dd10f2006-08-25 17:25:49 +0000204}
205
206/*
207 * ------------------------------------------------------
208 * Is there a "post_controller" hook?
209 * ------------------------------------------------------
210 */
adminaf436d72006-09-15 20:02:14 +0000211$EXT->_call_hook('post_controller');
adminb0dd10f2006-08-25 17:25:49 +0000212
213/*
214 * ------------------------------------------------------
215 * Send the final rendered output to the browser
216 * ------------------------------------------------------
217 */
218
adminaf436d72006-09-15 20:02:14 +0000219if ($EXT->_call_hook('display_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000220{
221 $OUT->_display();
222}
223
224/*
225 * ------------------------------------------------------
226 * Is there a "post_system" hook?
227 * ------------------------------------------------------
228 */
adminaf436d72006-09-15 20:02:14 +0000229$EXT->_call_hook('post_system');
adminb0dd10f2006-08-25 17:25:49 +0000230
231/*
232 * ------------------------------------------------------
233 * Close the DB connection of one exists
234 * ------------------------------------------------------
235 */
236if ($CI->_ci_is_loaded('db'))
237{
238 $CI->db->close();
239}
240
241
242?>