/** * Launches the MVC framework */ public static function go() { TBGLogging::log('Dispatching'); try { if (($route = self::getRouting()->getRouteFromUrl(self::getRequest()->getParameter('url', null, false))) || self::isInstallmode()) { if (self::isUpgrademode()) { $route = array('module' => 'installation', 'action' => 'upgrade'); } elseif (self::isInstallmode()) { $route = array('module' => 'installation', 'action' => 'installIntro'); } if (self::$_redirect_login) { TBGLogging::log('An error occurred setting up the user object, redirecting to login', 'main', TBGLogging::LEVEL_NOTICE); self::getResponse()->headerRedirect(self::getRouting()->generate('login_redirect'), 403); } if (is_dir(THEBUGGENIE_MODULES_PATH . $route['module'])) { if (!file_exists(THEBUGGENIE_MODULES_PATH . $route['module'] . DS . 'classes' . DS . 'actions.class.php')) { throw new TBGActionNotFoundException('The ' . $route['module'] . ' module is missing the classes/actions.class.php file, containing all the module actions'); } if (!class_exists($route['module'] . 'Actions') && !class_exists($route['module'] . 'ActionComponents')) { self::addClasspath(THEBUGGENIE_MODULES_PATH . $route['module'] . DS . 'classes' . DS); } if (self::performAction($route['module'], $route['action'])) { if (B2DB::isInitialized()) { B2DB::closeDBLink(); } return true; } } else { throw new Exception('Cannot load the ' . $route['module'] . ' module'); return; } } else { require THEBUGGENIE_MODULES_PATH . 'main' . DS . 'classes' . DS . 'actions.class.php'; self::performAction('main', 'notFound'); } } catch (TBGTemplateNotFoundException $e) { B2DB::closeDBLink(); TBGContext::setLoadedAt(); header("HTTP/1.0 404 Not Found", true, 404); tbg_exception($e->getMessage(), $e); } catch (TBGActionNotFoundException $e) { B2DB::closeDBLink(); TBGContext::setLoadedAt(); header("HTTP/1.0 404 Not Found", true, 404); tbg_exception('Module action "' . $route['action'] . '" does not exist for module "' . $route['module'] . '"', $e); } catch (TBGCSRFFailureException $e) { B2DB::closeDBLink(); TBGContext::setLoadedAt(); self::$_response->setHttpStatus(301); $message = $e->getMessage(); if (self::getRequest()->getRequestedFormat() == 'json') { self::$_response->setContentType('application/json'); $message = json_encode(array('message' => $message)); } self::$_response->renderHeaders(); echo $message; } catch (Exception $e) { B2DB::closeDBLink(); TBGContext::setLoadedAt(); header("HTTP/1.0 404 Not Found", true, 404); tbg_exception('An error occured', $e); } }