-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
87 lines (73 loc) · 1.84 KB
/
Copy pathrouter.php
File metadata and controls
87 lines (73 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/* copyright - Catalin Alin 2015 (catalin@live.jp) */
class router {
const NOAUTH = 0;
const NEEDAUTH = 1;
private $routerList = array();
private $scriptPath = "_System/_Modules/news.php"; //Default
private $authRequired = self::NOAUTH; //Default
private $pageTitle = "News"; //Default
public function __construct()
{
//init available routes.
// [Request Page] [Page Title] [Script Path] [[NOAUTH / NEEDAUTH]]
$this->addRoute("404", "Page Not Found!", "_System/_Modules/404.php", self::NOAUTH);
$this->addRoute("guide", "Game Guide", "_System/_Modules/guide.php", self::NOAUTH);
$this->addRoute("downloads", "Download Game", "_System/_Modules/downloads.php", self::NOAUTH);
$this->addRoute("login", "Login to your account", "_System/_Modules/login.php", self::NOAUTH);
}
private function addRoute($match, $pageTitle, $routeScript, $AUTH)
{
array_push($this->routerList, array($match, $pageTitle, $routeScript, $AUTH));
}
public function Init($REQUEST){
foreach ($this->routerList as &$value) {
if(strcmp($REQUEST,$value[0]) == 0)
{
$this->pageTitle = $value[1]; //#1
$this->scriptPath = $value[2]; //#2
$this->authRequired = $value[3]; //#3
return;
}
}
}
/*
* Dispatch script
*/
public function dispatch()
{
if($this->authRequired == self::NEEDAUTH)
{
header("Location: /login");
exit;
}elseif($this->authRequired == self::NOAUTH)
{
if(file_exists($this->scriptPath) == true)
{
include($this->scriptPath);
}else{
//404 handler.
header("Location: /404");
}
}
}
/**
* Forces router to load script.
*/
public function force($scriptPath)
{
if(file_exists($scriptPath) == true)
{
include($scriptPath);
}
}
public function getPageTitle()
{
return $this->pageTitle;
}
private function getRouterList()
{
return $this->routerList;
}
}
?>