-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
67 lines (52 loc) · 1.44 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
<?php
require 'lib/AltoRouter.php';
require 'lib/config.php';
require 'lib/data.php';
require 'lib/util.php';
$baseURI = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $basePath;
$router = new AltoRouter();
$router->setBasePath($basePath);
$data = new Data();
////////////////////////////////////////////////////////////////////////////////
function display_page($slug, $fallacy=false) {
global $basePath;
global $baseURI;
global $data;
$data->setSlug($slug);
$slug = $fallacy ? 'fallacy' : $slug;
require __DIR__ . '/pages/header.php';
require __DIR__ . '/pages/' . $slug . '.php';
require __DIR__ . '/pages/footer.php';
}
function not_found() {
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
display_page('404');
}
// Home page
$router->map('GET', '/', function() {
display_page('home');
});
// Remove trailing slash
$router->map('GET', '/[*:slug]/', function($slug) {
global $baseURI;
header('Location: ' . $baseURI . '/' . $slug, true, 301);
});
// FAQ
$router->map('GET', '/sss', function() {
display_page('faq');
});
// Fallacies
$router->map('GET', '/[*:slug]', function($slug) {
global $data;
if ($data->isFallacy($slug)) {
display_page($slug, true);
} else {
not_found();
}
});
$match = $router->match();
if ($match && is_callable($match['target'])) {
call_user_func_array($match['target'], $match['params']);
} else {
not_found();
}