forked from sergey-platonov/cpp-russia-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
97 lines (81 loc) · 2.59 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
<?php
include ("./loader.php");
$GLOBALS['project_root'] = __DIR__;
$GLOBALS["speakers"] = getAllSpeakerData(__DIR__)["speakers"];
$router = new AltoRouter();
// map homepage
function map_home() {
set_locale();
require __DIR__ . '/main.php';
}
$router->map( 'GET', '/[i:year]/', map_home );
$router->map( 'GET', '/', map_home );
// map all talks page
function map_all_talks() {
set_locale();
$GLOBALS["prefix"] = '';
require __DIR__ . '/templates/talks.php';
}
function map_all_talks_year($year) {
set_locale();
$GLOBALS["prefix"] = '/' . basename(__DIR__);
require __DIR__ . '/templates/talks.php';
}
$router->map( 'GET', '/[i:year]/talks', map_all_talks_year );
$router->map( 'GET', '/talks', map_all_talks );
function map_talk_detalis_impl($speaker) {
set_locale();
$speakerData = getSpeakerDataByDirName($speaker);
if (!$speakerData) {
header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
print tr('not found');
} else {
require __DIR__ . '/templates/talk.php';
}
}
function map_talk_details_year($year, $speaker) {
set_locale();
$GLOBALS["prefix"] = '/' . basename(__DIR__);
map_talk_detalis_impl($speaker);
}
// map talk details page
function map_talk_details($speaker) {
set_locale();
$GLOBALS["prefix"] = '';
map_talk_detalis_impl($speaker);
}
$router->map( 'GET', '/[i:year]/talks/[*:speaker]', map_talk_details_year );
$router->map( 'GET', '/talks/[*:speaker]', map_talk_details );
// map workshop details page
function map_workshop_details_impl($speaker) {
set_locale();
$speakerData = getSpeakerDataByDirName($speaker);
if (!$speakerData) {
header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
print tr('not found');
} else {
require __DIR__ . '/templates/workshop.php';
}
}
function map_workshop_details_year($year, $speaker) {
set_locale();
$GLOBALS["prefix"] = '/' . basename(__DIR__);
map_workshop_details_impl($speaker);
}
function map_workshop_details($speaker) {
set_locale();
$GLOBALS["prefix"] = '';
map_workshop_details_impl($speaker);
}
$router->map( 'GET', '/[i:year]/workshops/[*:speaker]', map_workshop_details_year );
$router->map( 'GET', '/workshops/[*:speaker]', map_workshop_details );
// match current request url
$match = $router->match();
// call closure or throw 404 status
if( $match && is_callable( $match['target'] ) ) {
call_user_func_array( $match['target'], $match['params'] );
} else {
print $_SERVER['REQUEST_URI'];
// no route was matched
header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}