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
;
28 require_once './includes/init.php';
30 require_once HOPLITE_ROOT
. '/http/output_filter.php';
31 require_once HOPLITE_ROOT
. '/http/response_code.php';
32 require_once HOPLITE_ROOT
. '/http/root_controller.php';
33 require_once HOPLITE_ROOT
. '/http/url_map.php';
36 * @implements \hoplite\http\RootControllerDelegate
40 /** @var \hoplite\http\RootController */
41 private $controller = NULL
;
43 public function __construct(http\RootController
$controller)
45 $this->controller
= $controller;
48 public function WillRouteRequest(http\Request
$request, http\Response
$response)
50 // TODO(port): Write a new cookie function.
53 $cookie = COOKIE_PREFIX
. 'adminsession';
55 if (can_perform('canadminpanel')) {
56 $stmt = bugdar
::$db->Prepare("SELECT * FROM ". TABLE_PREFIX
. "adminsession WHERE sessionid = ?");
57 $stmt->Execute(array(bugdar
::$input->InputClean('c', $cookie, http\Input
::TYPE_STR
)));
58 $session = $stmt->FetchObject();
60 if ($session && $session->userid
== bugdar
::$user['userid'] && $session->dateline
>= TIMENOW
- 3600) {
62 $funct->cookie($cookie, $session->sessionid
, false
);
67 $funct->cookie($cookie, NULL
);
71 public function LoginPage()
73 $this->controller
->StopWithCode(http\ResponseCode
::FORBIDDEN
);
77 $controller = new http\
RootController($GLOBALS);
78 $controller->set_delegate(new FrontController($controller));
80 $url_map = new http\
UrlMap($controller);
81 $url_map->set_file_loader(function($name, $value) {
82 require_once BUGDAR_ROOT
. '/admin/' . $value;
83 return 'bugdar\\admin\\' . $name . 'Action';
85 $controller->set_url_map($url_map);
87 $url_map->set_map(array(
92 $output_filter = new http\
OutputFilter($controller);
93 $controller->set_output_filter($output_filter);