-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·53 lines (49 loc) · 1.49 KB
/
index.php
File metadata and controls
executable file
·53 lines (49 loc) · 1.49 KB
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
<?php
const EMAIL = "x@lennis.dev";
function renderfile(string $file, bool $ishome = false): string
{
$content = file_get_contents($file);
$master = file_get_contents(__DIR__ . "/pages/_master.html");
$master = str_replace("[content]", $content, $master);
if ($ishome) {
$master = str_replace("[ishome]", "home", $master);
} else {
$master = str_replace("[ishome]", "", $master);
}
return $master;
}
if ($_SERVER["REQUEST_URI"] == "/") {
echo renderfile(__DIR__ . "/pages/_index.html", true);
exit();
} elseif (str_starts_with($_SERVER["REQUEST_URI"], "/sendmail")) {
if (isset($_GET["subject"]) && isset($_GET["message"])) {
header(
"Location: mailto:" .
EMAIL .
"?subject=" .
$_GET["subject"] .
"&body=" .
$_GET["message"],
);
} elseif (isset($_GET["subject"])) {
header("Location: mailto:" . EMAIL . "?subject=" . $_GET["subject"]);
} else {
header("Location: mailto:" . EMAIL);
}
exit();
} else {
$realpath = realpath(
__DIR__ .
"/pages/" .
explode("/", $_SERVER["REQUEST_URI"])[1] .
".html",
);
if (str_starts_with($realpath, __DIR__ . "/pages/")) {
if (file_exists($realpath)) {
echo renderfile($realpath, false);
exit();
}
}
}
header("HTTP/1.1 404 Not Found");
echo renderfile(__DIR__ . "/pages/_404.html", false);