//require_once (ROOT . '/library/adodb/adodb.inc.php');
//require_once (ROOT . '/library/dbclass/connection.class.php');
require_once (ROOT . '/library/dbclass/db_model.class.php');
/** Check if environment is development and display errors **/
function setReporting() {
if (DEVELOPMENT_ENVIRONMENT == true) {
ini_set ('error_reporting', E_ALL & ~E_NOTICE);
ini_set ('display_errors', 1);
} else {
error_reporting(E_ALL);
ini_set('display_errors',0);
ini_set('log_errors', 'On');
ini_set('error_log', ROOT.'/tmp/logs/error.log');
}
}
/** Check for Magic Quotes and remove them **/
function stripSlashesDeep($value) {
$value = is_array($value) ? array_map('stripSlashesDeep', $value) : stripslashes($value);
return $value;
}
function removeMagicQuotes() {
if ( get_magic_quotes_gpc() ) {
$_GET = stripSlashesDeep($_GET );
$_POST = stripSlashesDeep($_POST );
$_COOKIE = stripSlashesDeep($_COOKIE);
}
}
/** Check register globals and remove them **/
function unregisterGlobals() {
if (ini_get('register_globals')) {
$array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
foreach ($array as $value) {
if (is_array($GLOBALS[$value])) {
foreach ($GLOBALS[$value] as $key => $var) {
if ($var === $GLOBALS[$key]) {
unset($GLOBALS[$key]);
}
}
}
}
}
}
function urlMap() {
global $url;
if ($url) {
$url=(strstr($url,"/"))?$url:$url."/";
$parts = explode("/",$url);
$num = count($parts);
$route = array_slice($parts,0,2);
$vars = array_slice($parts,2);
$map['name'] = $route[0];
$map['action'] = ($route[1])?$route[1]:'index';
$map['qString'] = $vars;
}
return $map;
}
/** Main Call Function **/
function callHook() {
$map = urlMap();
$controllerName = $map['name'];
$action = $map['action'];
$qString = $map['qString'];
//if (!is_dir( __DOCPATH.$controllerName)) {
$controller = ucwords($controllerName)."Controller";
$model = ucwords($controllerName);
$dispatch = new $controller($model,$controllerName,$action,$qString);
if (method_exists($controller, $action)) {
@call_user_func_array(array($dispatch,$action),$qString);
} else {
/* Error Generation Code Here */
}
//}
}
/** Autoload any classes that are required **/
function __autoload($className) {
$libraryFile = ROOT . '/library/' . strtolower($className) . '.class.php';
$controlFile = ROOT . '/application/controllers/' . strtolower($className) . '.php';
$modelFile = ROOT . '/application/models/' . strtolower($className) . '.php';
if (file_exists($libraryFile)) {
require_once($libraryFile);
//echo $libraryFile."
:";
} else if (file_exists($controlFile)) {
require_once($controlFile);
//echo $controlFile."
+";
} else if (file_exists($modelFile)) {
require_once($modelFile);
//echo $modelFile."
-";
} else {
/* Error Generation Code Here */
}
}
setReporting();
removeMagicQuotes();
unregisterGlobals();
callHook();
?>