controller = $controller; $url_map = new http\UrlMap($controller); $url_map->set_file_loader(function($name, $value) { require_once BUGDAR_ROOT . '/admin/' . $value; return 'bugdar\\admin\\' . $name . 'Action'; }); $controller->set_url_map($url_map); $url_map->set_map(array( '' => 'home', 'fields/{action}' => 'fields', 'settings' => 'settings', )); $output_filter = new http\OutputFilter($controller); $controller->set_output_filter($output_filter); $tpl_loader = views\TemplateLoader::GetInstance(); $tpl_loader->set_template_path(BUGDAR_ROOT . '/admin/templates/%s.tpl'); $tpl_loader->set_cache_backend(new views\PDOCacheBackend( Bugdar::$db, // PDO object. TABLE_PREFIX . 'template', // Database table. 'filename', // Name column. 'template', // Data column. 'timestamp' // Modified time column. )); } public function LoginPage() { $this->controller->InvokeAction(new LoginAction($this->controller)); } // RootControllerDelegate: public function OnInitialRequest(http\Request $request, http\Response $response) { $response->data['language'] = fetch_user_language(); } public function WillRouteRequest(http\Request $request, http\Response $response) { // TODO(port): Write a new cookie function. global $funct; $cookie = COOKIE_PREFIX . 'adminsession'; if (can_perform('canadminpanel')) { $stmt = bugdar::$db->Prepare("SELECT * FROM ". TABLE_PREFIX . "adminsession WHERE sessionid = ?"); $stmt->Execute([ filter_input(INPUT_COOKIE, $cookie, FILTER_SANITIZE_STRING) ]); $session = $stmt->FetchObject(); if ($session && $session->userid == bugdar::$user['userid'] && $session->dateline >= TIMENOW - 3600) { // Renew the cookie. $funct->cookie($cookie, $session->sessionid, false); return; } } $funct->cookie($cookie, NULL); $this->LoginPage(); } public function WillInvokeAction(http\Action $action, http\Request $request, http\Response $response) { $templates = array('admin_header', 'admin_footer'); if ($action instanceof TemplatePreCaching) $templates = array_merge($templates, $action->TemplateSet()); views\TemplateLoader::GetInstance()->PreCache($templates); } public function DidInvokeAction(http\Action $action, http\Request $request, http\Response $response) {} public function WillStop(http\Request $request, http\Response $response) {} } // Actions can implement this interface to have their required templates loaded // with the common templates. interface TemplatePreCaching { // Return an array of template names to cache. public function TemplateSet(); } error_reporting(E_ALL); $controller = new http\RootController($GLOBALS); $delegate = new FrontController($controller); $controller->set_delegate($delegate); $controller->Run();