-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
114 lines (90 loc) · 2.36 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
<?php
// Public facing rendering engine.
require_once __DIR__ . "/config.php";
require_once __DIR__ . "/core.php";
require_once __DIR__ . "/router.php";
$not_found = false;
// Maps URL type -> store type
$page_types = array(
"toots" => "toot",
"replies" => "reply",
"photos" => "photo",
"code" => "code"
);
switch(true) {
case !is_https() and FORCE_HTTPS:
http_response_code(301);
header("Location: https://" . HOST . $_SERVER['REQUEST_URI']);
exit;
case $path == "/":
http_response_code(302);
header("Location: " . CANONICAL . "/" . date("Y"));
exit;
case route('@' . CMS . '.*$@'):
// Delegate to the pebble router.
include __DIR__ . "/cms/index.php";
exit;
case route('@/(\d{4})$@'):
$year = $params[1];
$posts = \store\list_posts($year);
break;
case route('@/(\d{4})/(toots|replies|photos|code)$@'):
$year = $params[1];
$type = $page_types[$params[2]];
$posts = \store\list_posts_by_type($year, $type);
break;
case route('@/(\d{4})/(\w+)$@'):
$year = $params[1];
$id = $params[2];
$post = \store\get_post($year, $id);
if(!$post) $not_found = true;
break;
default:
$year = date("Y");
$not_found = true;
break;
}
if($not_found) {
http_response_code(404);
} else {
\stats\record_view($path);
}
?><!DOCTYPE html>
<html lang="<?= SITE_LANG ?>">
<head>
<?php include "partials/head.php" ?>
<title><?= SITE_TITLE ?></title>
</head>
<body>
<header>
<?php include "partials/header.php" ?>
</header>
<main <?php if(isset($posts)) echo 'class="h-feed"' ?>>
<?php
switch(true) {
case isset($post) and $post !== false:
\renderer\render_post($post);
\renderer\render_comment_section($post);
break;
case isset($posts) and count($posts) > 0:
foreach($posts as $post) {
\renderer\render_post($post);
}
break;
case $not_found:
include "partials/404.php";
break;
default:
\renderer\render_info("Nothing here. (anymore?)");
break;
}
?>
</main>
<aside>
<?php include "partials/menu.php" ?>
</aside>
<footer>
<?php include "partials/footer.php" ?>
</footer>
</body>
</html>