forked from NamelessMC/Nameless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
123 lines (102 loc) · 2.63 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/*
* Made by Samerton
* http://worldscapemc.co.uk
*
* License: MIT
*/
// Start page load timer
$start = microtime(true);
// Temp
date_default_timezone_set('Europe/London');
// Definitions
define('PATH', '/');
define('ROOT_PATH', dirname(__FILE__));
$page = 'Home';
// Get the directory the user is trying to access
$directory = $_SERVER['REQUEST_URI'];
$directories = explode("/", $directory);
$lim = count($directories);
// Installer?
if(is_file('pages/install.php')){
if(isset($_GET['from']) && $_GET['from'] == 'install'){
unlink('pages/install.php');
} else {
$page = 'install';
require('core/init.php');
require('pages/install.php');
die();
}
}
// Start initialising the page
require('core/init.php');
// Load the main page content
// Check if the page actually exists..
// First, check the contents of the URL
if(empty($directories[0]) && empty($directories[1])){
// Must be the index page
$page_path = 'pages/index.php';
} else {
$n = 0;
foreach($directories as $directory){
if(strpos($directory, '?') !== false){
$params = $directory; // Get URL parameters
unset($directories[$n]);
}
$n++;
}
$page_path = 'pages' . implode('/', $directories);
if(substr($page_path, -1) == "/"){
$page_path = rtrim($page_path, '/');
}
}
// Include the page
if(is_file($page_path)){
require($page_path);
} else {
if(is_file($page_path . '.php')){
require($page_path . '.php');
} else {
if(is_dir($page_path)){
if(file_exists($page_path . '/index.php')){
require($page_path . '/index.php');
}
} else {
// Profile page?
if($directories[1] == 'profile'){
$profile = htmlspecialchars($directories[2]);
require('pages/profile.php');
// Kill the script
die();
}
// Custom page?
$page_path = explode('/', $page_path);
$custom_pages = $queries->getWhere('custom_pages', array('url', '=', '/' . $page_path[1]));
if(count($custom_pages)){
$page_title = $custom_pages[0]->title;
$page_content = $custom_pages[0]->content;
// For navbar
$page = $custom_pages[0]->title;
// Include the page
require 'pages/extra.php';
// Kill the page
die();
}
// Doesn't exist without trailing '/', try again with trailing '/'
$custom_pages = $queries->getWhere('custom_pages', array('url', '=', '/' . $page_path[1] . '/'));
if(count($custom_pages)){
$page_title = $custom_pages[0]->title;
$page_content = $custom_pages[0]->content;
// For navbar
$page = $custom_pages[0]->title;
// Include the page
require 'pages/extra.php';
// Kill the page
die();
}
// 404
require('404.php');
}
}
}
?>