This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
108 lines (86 loc) · 2.94 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
<?php
if ($_SERVER['HTTP_HOST'] !== 'findparkering.nu') {
define('DEV', true);
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
else
define('DEV', false);
require 'vendor/autoload.php';
if (DEV)
require 'config/dev.mysql.php';
else
require 'config/mysql.php';
require 'inc/functions.php';
$klein = new \Klein\Klein();
$klein->respond(function($request, $response, $service) {
$service->cities = get_cities();
$service->layout('views/main.php');
});
$klein->respond('GET', '/', function($request, $response, $service) {
$service->title = 'Forside';
$service->render('views/front.php');
});
$klein->respond('GET', '/admin/login', function($request, $response, $service) {
$service->title = 'Login';
$service->render('views/admin/login.php');
});
$klein->respond('GET', '/admin', function($request, $response, $service) {
$service->title = 'Admin';
$service->render('views/admin/admin.php');
});
/* Needs a complete rework to work with multiple citys at some point. See Trello for more info */
$klein->respond('GET', '/info', function($request, $response, $service) {
$service->title = 'Info';
$service->render('views/info.php');
});
$klein->respond('GET', '/tak', function($request, $response, $service) {
$service->title = 'Tak';
$service->backgrounds = get_backgrounds();
$service->render('views/tak.php');
});
$klein->respond('GET', '/guides', function($request, $response, $service) {
$service->title = 'Guides';
$service->backgrounds = get_backgrounds();
$service->render('views/guides.php');
});
$klein->respond('GET', '/fejl', function($request, $response, $service) {
$service->title = 'Fejl & Forbedringer';
$service->backgrounds = get_backgrounds();
$service->render('views/fejl.php');
});
$klein->respond('GET', '/baggrunde', function($request, $response, $service) {
$service->title = 'Baggrunde';
$service->backgrounds = get_backgrounds();
$service->render('views/backgrounds.php');
});
$klein->respond('GET', '/rest/[i:id]', function($request, $response, $service) use ($klein) {
$rest = get_rest_by_id($request->id);
if (!isset($rest))
$klein->abort(404);
$city = get_city_by_id($rest['city_id']);
$service->title = $rest['name'];
$service->breadcrumb = ['/parkering/'.$city['url'] => $city['name'], $rest['name']];
$service->rest = $rest;
$service->render('views/rest.php');
});
foreach (get_cities() as $city) {
$klein->respond('GET', '/parkering/['.$city['url'].':city]', function($request, $response, $service) {
$city = get_city_by_url($request->city);
$rests = get_rests_by_city_id($city['id']);
$service->title = 'Parkeringsguide - '.$city['name'];
$service->breadcrumb = [$city['name']];
$service->city = $city;
$service->rests = $rests;
$service->render('views/parking.php');
});
}
$klein->onHttpError(function ($code, $router) {
if ($code == 404) {
$service = $router->service();
$service->title = '404 - Siden blev ikke fundet';
$service->render('views/404.php');
}
});
$klein->dispatch();
?>