This repository was archived by the owner on Feb 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
93 lines (71 loc) · 2.16 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
<?php
# Config
require_once __DIR__.'/config.php';
Config::init();
# Helpers
foreach (glob(__DIR__.'/helpers/*.php') as $f) {
require_once $f;
}
# Routes
// limonade configuration
function configure() {
Config::routes_init();
}
function before($route) {
// Override X-Powered-By header
send_header('X-Powered-By: Electricity');
foreach ($route['params'] as $k => $v) {
params($k, escape_mysql_wildcards($v));
}
try_autoconnect();
if (stristr($route['callback'], 'admin')) {
if (!is_connected() || !user()->isAdmin()) {
halt(HTTP_FORBIDDEN, 'L\'accès à cette page est réservé aux administrateurs.');
}
}
else if (stristr($route['callback'], 'moderation')) {
if (!is_connected() || !user()->isModerator()) {
halt(HTTP_FORBIDDEN, 'L\'accès à cette page est réservé aux modérateurs.');
}
}
else if (stristr($route['callback'], 'member')) {
if (!is_connected() || !user()->isMember()) {
halt(HTTP_FORBIDDEN, 'L\'accès à cette page est réservé aux membres.');
}
}
}
function before_sending_header($header) {
if (strpos($header, 'text/html') !== false) {
send_header('Cache-Control: no-store');
}
}
define('LIM_REQUEST_URI', request_uri());
if ( strpos($_SERVER['HTTP_HOST'], 's.') === 0 ) {
dispatch('/**', 'short_link_route');
} else {
require_once __DIR__.'/routes.php';
}
# Errors handling (functions called by Limonade)
# Called when a route is not found.
function route_missing($request_method, $request_uri) {
error_log("Not found: ($request_method) $request_uri");
halt(NOT_FOUND);
}
# Server error output
#
# @param string $errno
# @param string $errstr
# @param string $errfile
# @param string $errline
# @return string "server error" output string
#
function server_error($errno, $errstr=null, $errfile=null, $errline=null) {
return display_http_error($errno, $errstr, $errfile, $errline);
}
# Not found error output
# @see server_error
function not_found($errno, $errstr=null, $errfile=null, $errline=null) {
return display_http_error($errno, $errstr, $errfile, $errline);
}
run();
?>