forked from NamelessMC/Nameless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
147 lines (120 loc) · 3.5 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/*
* Made by Samerton
* http://worldscapemc.co.uk
*
* License: MIT
* Copyright (c) 2016 Samerton
*/
// Start page load timer
$start = microtime(true);
// Temp
date_default_timezone_set('Europe/London');
// Definitions
define('PATH', '/');
define('ROOT_PATH', dirname(__FILE__));
$page = 'Home';
if(!ini_get('upload_tmp_dir')){
$tmp_dir = sys_get_temp_dir();
} else {
$tmp_dir = ini_get('upload_tmp_dir');
}
ini_set('open_basedir', ROOT_PATH . PATH_SEPARATOR . $tmp_dir);
// 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'){
if(!unlink('pages/install.php')) die('Please delete <strong>pages/install.php</strong> before continuing.');
} 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'){
if(isset($directories[2])) $profile = htmlspecialchars($directories[2]);
require('pages/profile.php');
// Kill the script
die();
}
// API?
if($directories[1] == 'api'){
if(is_file('pages' . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . $directories[2] . DIRECTORY_SEPARATOR . 'index.php')){
require('pages' . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . $directories[2] . DIRECTORY_SEPARATOR . 'index.php');
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;
$page_id = $custom_pages[0]->id;
if($custom_pages[0]->redirect == 1) $redirect_page = htmlspecialchars($custom_pages[0]->link);
// 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;
$page_id = $custom_pages[0]->id;
if($custom_pages[0]->redirect == 1) $redirect_page = htmlspecialchars($custom_pages[0]->link);
// For navbar
$page = $custom_pages[0]->title;
// Include the page
require 'pages/extra.php';
// Kill the page
die();
}
// 404
require('404.php');
}
}
}
?>