-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
50 lines (40 loc) · 1.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
<?php
require_once __DIR__ . "/inc/siteFunctions.php";
$config = require __DIR__ . "/config/vars.sample.php";
// always force / as home
if ( $_SERVER['REQUEST_URI'] == "/index.php" || $_SERVER['REQUEST_URI'] == "/index.html" ) {
header("Location: /");
exit();
}
// figure out which page to show
$q = $_GET['q']??"";
$page = ( $q ? $q : "index" ) . ".html";
$file = realpath(__DIR__."/cache/".$page);
if ( ! file_exists($file) ) {
if ( ! headers_sent() ) {
header('HTTP/1.0 404 Not Found');
}
include __DIR__ . "/config/404.tpl";
exit();
}
$html = file_get_contents($file);
// "fix" the html of the page
$headinject = <<<"EOT"
<script src="inc/common.js"></script>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
EOT;
$html = str_replace('</body>', $headinject.'</body>', $html);
// inject the common header
$header = trim(file_get_contents( __DIR__ . "/config/header.tpl"));
$header = str_replace("{{pathfromroot}}", ($config['path_from_root']??""), $header);
$header = str_replace("{{logoimage}}", ($config['logo_image_src']??""), $header);
$header = str_replace("{{brandname}}", ($config['brand_name']??""), $header);
$header = str_replace("{{enablesearch}}", ($config['enable_search']??"")?"true":"false", $header);
// inject the common footer
$footer = trim(file_get_contents( __DIR__ . "/config/footer.tpl"));
$footer = str_replace("{{footerhtml}}", ($config['footer_html']??""), $footer);
// build and render
$html = str_replace('<body>', '<body>'.$header, $html);
$html = str_replace('</body>', $footer.'</body>', $html);
echo $html;