-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
81 lines (63 loc) · 2.17 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
<?php
ini_set('display_errors','On');
error_reporting(-1);
define('VERSION', '0.2.0');
require 'controllers/presskit.php';
require 'helpers/errorhelper.php';
// convienience function to set constants if not defined, used in config files
function set($const, $value) { defined($const) || define($const, $value); }
// loads config file
if (!file_exists('config.php' )) {
ErrorHelper::logError('Missing config.php, make a copy of config-defaults.php to get started.');
} else {
require 'config.php';
}
// load defaults
require 'config-defaults.php';
// detects if mod_rewrite is available (or if force flag is set)
ViewHelper::$mod_rewrite = (FORCE_MOD_REWRITE == 'true' || getenv('HTTP_MOD_REWRITE') == 'On');
$requestUrl = $_SERVER['REQUEST_URI'];
// support for presskit legacy urls, also used when mod_rewrite is unavailable
if (isset($_GET['p']) && $_GET['p'] != ''){
$requestUrl = $_GET['p'];
} else {
// strip GET variables from URL
if(($pos = strpos($requestUrl, '?')) !== false) {
$requestUrl = substr($requestUrl, 0, $pos);
}
// strip out the base path
$requestUrl = str_replace(BASE_PATH, '', $requestUrl);
// strip any leading slashes
$requestUrl = ltrim($requestUrl, '/');
// if mod_rewrite is available and the request doesn't end with a slash, redirect to one that does
if (ViewHelper::$mod_rewrite && strlen($requestUrl) > 1 && substr($requestUrl, -1) != '/'){
header('HTTP/1.1 301 Moved Permanently');
header('Location: /' . BASE_PATH . $requestUrl . '/');
exit();
}
// strip any leading/trailing slashes
$requestUrl = trim($requestUrl, '/');
}
// if mod_rewrite is available and we're on a legacy url, redirect to the new, nicer one
if (ViewHelper::$mod_rewrite && isset($_GET['p'])){
header('HTTP/1.1 301 Moved Permanently');
header('Location: /' . BASE_PATH . $requestUrl);
exit();
}
ob_start();
if(!ErrorHelper::hasErrors()){
$presskit = new PresskitController();
}
if(!ErrorHelper::hasErrors()){
if ($requestUrl == ''){
$presskit->index();
} else if ($requestUrl == 'credits'){
$presskit->credits();
} else {
$presskit->game($requestUrl);
}
}
$content = ob_get_contents();
ob_end_clean();
require 'views/' . ViewHelper::$template . '.php';
?>