Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('../config/bootstrap.php');
- if (DEBUG) {
- error_reporting(E_ALL);
- ini_set('display_errors', 'On');
- } else {
- error_reporting(E_ALL);
- ini_set('display_errors', 'Off');
- }
- // autoload from composer
- require_once('../vendor/autoload.php');
- // init log
- AI\Lib\Log::init();
- if (WIP_ACTIVE && !in_array(trim(AI\Lib\Net::getIP()), $DEBUG_IPS)) {
- if (!Net::isAPICall()) {
- echo file_get_contents('offline.html');
- exit();
- } else {
- die(json_encode(array('error' => 'forbidden', 'error_code' => '403')));
- }
- }
- // URL Mapper
- $mapper = AI\Core\MultiLanguageMapper::getInstance();
- if (PREFIX) {
- $mapper->setPrefix(PREFIX);
- }
- require_once(DOCUMENT_ROOT . 'config/routes.php');
- $route = $mapper->match($_SERVER['REQUEST_URI'], array('controller' => 'pages', 'action' => 'home', 'args' => array()));
- $controllerClass = ucfirst(strtolower($route['controller'])) . 'Controller';
- $controllerAction = strtolower(str_replace('-', '_', $route['action']));
- // Check if the desired view is in the admin area
- define('ADMINVIEW', (isset($route['admin']) && $route['admin']) ? true : false);
- // Set session ID if is set from Flash call
- if ($controllerClass == 'UploadController' && isset($_GET['sessionCookie']) && Net::isFlash()) {
- session_id($_GET['sessionCookie']);
- }
- // Start session
- AI\Lib\PDOSession::init();
- // Get controller path from route
- $controller_path = (ADMINVIEW) ? DOCUMENT_ROOT . 'controller/admin/' . $route['controller'] . '.php' : DOCUMENT_ROOT . 'controller/' . $route['controller'] . '.php';
- // Try initializing controller
- if (!file_exists($controller_path)) {
- AI\Lib\Error::redirect(404);
- }
- require_once($controller_path);
- $controller = new $controllerClass;
- // Try running method
- if (!method_exists($controller, $controllerAction)) {
- AI\Lib\Error::redirect(404);
- }
- // Call before method in controller
- $controller->methodRequest = $controllerAction;
- $controller->requestRoute = $route;
- $controller->before();
- // Call method in controller
- call_user_func_array(array($controller, $controllerAction), $route['args']);
- // Call after method in controller
- $controller->after();
- // Check if the call is an AJAX call
- if ($controller->isAjaxCall) {
- if (!DEBUG && !(AI\Lib\Net::isFlash() || AI\Lib\Net::isAjax() || AI\Lib\Net::isAPICall())) {
- die(json_encode(array('error' => 'forbidden', 'error_code' => '403')));
- } else {
- // set view vars as
- foreach ($controller->viewVars as $k => $v) {
- $$k = $v;
- }
- }
- } else {
- // set view vars as
- foreach ($controller->viewVars as $k => $v) {
- $$k = $v;
- }
- // Auth instance for view
- $Auth = \AI\Core\AuthController::getInstance();
- // Determine view
- $showView = ($controller->view == '') ? $controllerAction : $controller->view;
- $view_path = (ADMINVIEW) ? DOCUMENT_ROOT . 'view/' . strtolower($route['controller']) . '/admin/' . $showView . '.php' : DOCUMENT_ROOT . 'view/' . strtolower($route['controller']) . '/' . $showView . '.php';
- if (!file_exists($view_path)) {
- AI\Lib\Log::error("View not found: " . $view_path);
- AI\Lib\Error::redirect(404);
- }
- // Set Javascript vars
- $javascriptConfig = [
- 'ROOT_URL' => ROOT_URL,
- 'debug' => DEBUG,
- 'locale' => $controller->locale
- ];
- if (isset($_SESSION['notify']) && sizeof($_SESSION['notify']) > 0) {
- $javascriptConfig['notify'] = $_SESSION['notify'];
- unset($_SESSION['notify']);
- }
- // set data in controller
- $layoutVars = $controller->getlayoutVars();
- $javascripts = $controller->getJavascripts(); // check for any flash messages
- if (method_exists($controller, '__')) {
- function __()
- {
- global $controller; // not very pretty
- return call_user_func_array(array($controller, '__'), func_get_args());
- }
- }
- ob_start();
- include($view_path);
- $body_content = ob_get_contents();
- ob_end_clean();
- }
- // show layout
- include(DOCUMENT_ROOT . 'view/layout/' . $controller->layout . '.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement