File: D:/HostingSpaces/SBogers10/lab.komma-mediadesign.nl/wwwroot/lab/lib/bootstrap.class.php
<?php
/**
* bootstrap.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 3/19/13
*/
class Bootstrap extends Controller{
public function __construct()
{
/*
* Start the session
*/
Session::init();
/*
* Error / Success handling
*/
$Alert = new Alert();
if($alert = $Alert->get())
{
echo $alert;
}
/*
* Convert URL_PAGE & URL_SUB to a controller and a method within a controller
*/
$cntr = '';
$method = '';
if(defined('URL_LANG'))
{
$LanguageHandler = new LanguageHandler();
$LanguageHandler->set(URL_LANG);
}
if(defined('URL_PAGE'))
{
$cntr = URL_PAGE;
}
if(defined('URL_SUB'))
{
$method = URL_SUB;
}
/*
* Check whether a user is logged in
*/
$Login = new Login();
$Login->loadModel('login');
if($Login->Model->isLoggedIn())
{
/*
* If URL_PAGE is not defined, call the homepage controller.
*/
if(empty($cntr))
{
require_once DOCUMENT_ROOT.'controllers/c_home.class.php';
$Controller = new Home();
$Controller->index();
return false;
}
$name = str_replace('-','_',$cntr);
/*
* Check if the controller file exists.
* If so, require the file and create a new Controller object
*/
$file = DOCUMENT_ROOT . 'controllers/c_' . strtolower($name) . '.class.php';
if(is_file($file))
{
require_once $file;
}
else
{
header("HTTP/1.0 404 Not Found");
header('location:'.SITE_ROOT.'404/');
exit;
}
/*
* Catch 404
*/
if($name == '404') $name = 'Page_Not_Found';
/*
* PAGE -> Create a controller object and load the model
* Note that the Login controller is already added in the top of this page.
*/
if($name != 'login')
{
$Controller = new $name;
$Controller->loadModel($name);
}
else
{
$Controller = $Login;
}
/*
* SUB -> If SUB exists as a method, call that method.
* If no sub,
*/
if( ! empty($method))
{
if(method_exists($Controller, $method))
{
$Controller->{$method}();
return true;
}
}
else
{
if(method_exists($Controller, 'index'))
{
$Controller->index();
return true;
}
}
$Controller->Functions->notFound();
}
else
{
if( ! empty($method))
{
if(method_exists($Login, $method))
{
$Login->{$method}();
return true;
}
}
else if(method_exists($Login, 'index'))
{
$Login->index();
return true;
}
$Login->Functions->notFound();
}
return false;
}
}