-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
101 lines (83 loc) · 2.64 KB
/
index.php
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
// flag to ensure, that includes aren't called directly
define('EXECUTE', true);
// load config
require("config.inc.php");
// initialize debug mode
if(DEBUG_MODE) {
ini_set('display_errors', 1);
error_reporting(E_ALL);
}
// 404 function
function response404() {
header('HTTP/1.0 404 Not Found');
echo "<h1>404 Not Found</h1>";
echo "The page that you have requested could not be found.";
exit();
}
// split URL if "?" contained
if(strpos($_SERVER['REQUEST_URI'], "?")) {
list($path, $parameter) = explode('?', $_SERVER['REQUEST_URI']);
} else {
$path = $_SERVER['REQUEST_URI'];
}
// if URL contains unvailed characters send 404
if(preg_match('/[^a-zA-Z0-9\/\-\_]/', $path)) {
response404();
}
// trim URL and remove path to this file (index.php)
$path = explode('/', rtrim($path,"/") );
$scriptName = explode('/', $_SERVER['SCRIPT_NAME']);
for($i= 0;$i < sizeof($scriptName);$i++) {
if(isset($path[$i]) && $path[$i] == $scriptName[$i]) {
unset($path[$i]);
}
}
$path = array_values($path);
// set home if no path
if( empty($path[0]) ) {
$path[0] = "home";
}
// set system path to the page include
$page = ABSPATH . "pages/" . implode("/", $path) . ".inc.php";
// if page doesn't exist, send 404
if( !file_exists($page) ) {
response404();
}
// check if there is a index.inc.php along the path, otherwise use $page
$path_partial = "";
for($i = 0; $i<count($path)-1; $i++) {
$path_partial .= $path[$i] . "/";
if( file_exists(ABSPATH . "pages/" . $path_partial . "index.inc.php") ) {
$include = ABSPATH . "pages/" . $path_partial . "index.inc.php";
}
}
if(empty($include)) {
$include = $page;
}
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Site Frame</title>
<link rel="icon" href="favicon.ico"/>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<link href="<?php echo BASE_URL; ?>css/central.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
base_url = "<?php echo BASE_URL; ?>";
</script>
</head>
<body>
<div class="container">
<div class="header">
<h1><a href="<?php echo BASE_URL; ?>"><img src="<?php echo BASE_URL; ?>img/logo.png" alt="Site Frame"></a></h1>
</div>
<?php include $include; ?>
</div> <!-- container -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<?php echo BASE_URL; ?>js/central.js"></script>
</body>
</html>