-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
70 lines (55 loc) · 1.66 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
<?php
require_once('parser/DefaultParser.php');
require_once('config.php');
//Every Request will be redirected to here!
/*
To configure SQL Settings check the relevant Databae Engine Provider
*/
//
// These 3 functions do all the heavy lifting of finding a file
//
$allpaths = GetRegisteredPaths();
$path = GetRealPath($allpaths);
$realPath = GetRealFileFromPath($path);
// Now we need to parse any relevant things and send the output back
// Doing so with a dedicated Class/Wrapper allows us to do more fancy things in the future like output buffering
// Compared to a simple 'require(file)'
$parser = new Parser($realPath);
$parser->OutputContent();
//
// We need to register every path a User could request
//
function GetRegisteredPaths() : array {
$paths = array();
$conn = Config::DatabaseEngine();
$paths = $conn->GetTableAsFlatArray('paths');
return $paths;
}
//
// Match the request to our registered paths
// No path = /sites/home template
//
function GetRealPath(array $paths) : string {
//strtok only gets everything until the first "?" Easier than explode
$requestUrl = strtok($_SERVER['REQUEST_URI'], "?");
foreach($paths as $row){
if (trim($requestUrl) === $row[0]){
return $row[1];
}
}
//Fallback will be always home page
return $paths[0][1];
}
//
// Search for a template with the correct path
//
function GetRealFileFromPath(string $path) : string {
$file = Parser::FindFile($path);
//If we can't find something, it means we have stray site in our DB
//This is a valid case for a 404
if($file == ""){
return "templates/sites/404.html";
}
return $file;
}
?>