2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2002-2013 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 namespace bugdar
\admin
;
29 require_once './includes/init.php';
31 require_once HOPLITE_ROOT
. '/http/output_filter.php';
32 require_once HOPLITE_ROOT
. '/http/response_code.php';
33 require_once HOPLITE_ROOT
. '/http/root_controller.php';
34 require_once HOPLITE_ROOT
. '/http/url_map.php';
35 require_once HOPLITE_ROOT
. '/views/pdo_cache_backend.php';
36 require_once HOPLITE_ROOT
. '/views/template_loader.php';
38 require_once BUGDAR_ROOT
. '/admin/login.php';
40 class FrontController
implements http\RootControllerDelegate
42 /** @var \hoplite\http\RootController */
43 private $controller = NULL
;
45 public function __construct(http\RootController
$controller)
47 $this->controller
= $controller;
49 $url_map = new http\
UrlMap($controller);
50 $url_map->set_file_loader(function($name, $value) {
51 require_once BUGDAR_ROOT
. '/admin/' . $value;
52 return 'bugdar\\admin\\' . $name . 'Action';
54 $controller->set_url_map($url_map);
56 $url_map->set_map(array(
58 'fields/{action}' => 'fields',
59 'settings' => 'settings',
62 $output_filter = new http\
OutputFilter($controller);
63 $controller->set_output_filter($output_filter);
65 $tpl_loader = views\TemplateLoader
::GetInstance();
66 $tpl_loader->set_template_path(BUGDAR_ROOT
. '/admin/templates/%s.tpl');
67 $tpl_loader->set_cache_backend(new views\
PDOCacheBackend(
68 Bugdar
::$db, // PDO object.
69 TABLE_PREFIX
. 'template', // Database table.
70 'filename', // Name column.
71 'template', // Data column.
72 'timestamp' // Modified time column.
76 public function LoginPage()
78 $this->controller
->InvokeAction(new LoginAction($this->controller
));
81 // RootControllerDelegate:
83 public function OnInitialRequest(http\Request
$request, http\Response
$response)
85 $response->data
['language'] = fetch_user_language();
88 public function WillRouteRequest(http\Request
$request, http\Response
$response)
90 // TODO(port): Write a new cookie function.
93 $cookie = COOKIE_PREFIX
. 'adminsession';
95 if (can_perform('canadminpanel')) {
96 $stmt = bugdar
::$db->Prepare("SELECT * FROM ". TABLE_PREFIX
. "adminsession WHERE sessionid = ?");
97 $stmt->Execute([ filter_input(INPUT_COOKIE
, $cookie, FILTER_SANITIZE_STRING
) ]);
98 $session = $stmt->FetchObject();
100 if ($session && $session->userid
== bugdar
::$user['userid'] && $session->dateline
>= TIMENOW
- 3600) {
102 $funct->cookie($cookie, $session->sessionid
, false
);
107 $funct->cookie($cookie, NULL
);
111 public function WillInvokeAction(http\Action
$action, http\Request
$request, http\Response
$response)
113 $templates = array('admin_header', 'admin_footer');
114 if ($action instanceof TemplatePreCaching
)
115 $templates = array_merge($templates, $action->TemplateSet());
116 views\TemplateLoader
::GetInstance()->PreCache($templates);
119 public function DidInvokeAction(http\Action
$action, http\Request
$request, http\Response
$response) {}
121 public function WillStop(http\Request
$request, http\Response
$response) {}
124 // Actions can implement this interface to have their required templates loaded
125 // with the common templates.
126 interface TemplatePreCaching
128 // Return an array of template names to cache.
129 public function TemplateSet();
132 error_reporting(E_ALL
);
134 $controller = new http\
RootController($GLOBALS);
135 $delegate = new FrontController($controller);
136 $controller->set_delegate($delegate);