2012-06-11 17:08:59 +00:00
|
|
|
<?php
|
|
|
|
|
2012-09-07 17:19:33 +00:00
|
|
|
define("PHP_ROOT","");
|
|
|
|
define("APP_ROOT","app");
|
|
|
|
|
|
|
|
require_once(APP_ROOT.'/config.php');
|
2012-06-11 17:08:59 +00:00
|
|
|
|
|
|
|
// Load up the base classes
|
2012-09-07 17:19:33 +00:00
|
|
|
require_once(APP_ROOT.'/core/Controller.php');
|
|
|
|
require_once(APP_ROOT.'/core/Model.php');
|
2012-06-11 17:30:26 +00:00
|
|
|
// We need the uri library for things to work
|
2012-09-07 17:19:33 +00:00
|
|
|
require_once(APP_ROOT.'/core/uri_library.php');
|
2012-06-11 17:08:59 +00:00
|
|
|
// Load up the globals
|
|
|
|
foreach($global_libraries as $alib) {
|
2012-09-07 17:19:33 +00:00
|
|
|
require_once(APP_ROOT.'/libraries/'.$alib.'_library.php');
|
2012-06-11 17:08:59 +00:00
|
|
|
}
|
|
|
|
foreach($global_models as $amod) {
|
2012-09-07 17:19:33 +00:00
|
|
|
require_once(APP_ROOT.'/models/'.$amod.'_model.php');
|
2012-06-11 17:08:59 +00:00
|
|
|
}
|
2012-06-12 23:30:24 +00:00
|
|
|
// Buffer all output for speed!
|
|
|
|
ob_start();
|
2012-06-11 17:08:59 +00:00
|
|
|
|
|
|
|
$uri = new Uri_library($_SERVER['REQUEST_URI']);
|
|
|
|
$uri_array = $uri->getFullArray();
|
2012-09-07 20:33:50 +00:00
|
|
|
|
|
|
|
$class_name = (!isset($uri_array[0]) || empty($uri_array[0]))?$default_controller:array_shift($uri_array);
|
|
|
|
|
2012-06-11 17:30:26 +00:00
|
|
|
while($starting_token-- > 0) { array_shift($uri_array); }
|
2012-06-11 17:08:59 +00:00
|
|
|
// Check if $uri->getItem(0) is a controller
|
2012-09-07 20:33:50 +00:00
|
|
|
if(file_exists(APP_ROOT.'/controllers/'.$class_name.'_controller.php')) {
|
2012-06-11 17:08:59 +00:00
|
|
|
// File exists, set the cc_name and pop the uri_array
|
|
|
|
$cc_name = $class_name."_controller";
|
|
|
|
} else {
|
2012-09-07 20:33:50 +00:00
|
|
|
// Not a valid controller, so 404d!
|
|
|
|
header("HTTP/1.0 404 Not Found");
|
|
|
|
echo "Page Not Found";
|
|
|
|
exit;
|
|
|
|
// $cc_name = $default_controller."_controller";
|
2012-06-11 17:08:59 +00:00
|
|
|
}
|
|
|
|
// Pull in the requested Controller
|
2012-09-07 17:19:33 +00:00
|
|
|
require_once(APP_ROOT.'/controllers/'.$cc_name.'.php');
|
2012-06-11 17:08:59 +00:00
|
|
|
|
|
|
|
$c_class = new $cc_name;
|
|
|
|
// Were we provided a method?
|
2012-09-07 20:33:50 +00:00
|
|
|
$c_func = (!isset($uri_array[0]) || empty($uri_array[0]))?"index":array_shift($uri_array);
|
2012-06-11 17:08:59 +00:00
|
|
|
if($c_func!==false && method_exists($c_class, $c_func)) {
|
|
|
|
call_user_func_array(array($c_class, $c_func), $uri_array);
|
|
|
|
} else {
|
|
|
|
// Nope, hit the controller's index
|
|
|
|
if(method_exists($c_class, 'index')) {
|
|
|
|
call_user_func_array(array($c_class, "index"), $uri_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 23:30:24 +00:00
|
|
|
// Flush the buffer
|
|
|
|
ob_end_flush();
|
2012-06-11 17:08:59 +00:00
|
|
|
|
|
|
|
?>
|