-
Notifications
You must be signed in to change notification settings - Fork 56
/
index.php
108 lines (101 loc) · 4.11 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
$includePath = implode(PATH_SEPARATOR, array_map(function ($dir) {
return __DIR__ . DIRECTORY_SEPARATOR . $dir;
}, array(
'.',
'_tpl',
'_tpl' . DIRECTORY_SEPARATOR . 'tpl-inc',
'_inc'
)));
ini_set('include_path', $includePath);
if (ini_get('session.save_handler') === 'files') {
// Make sure the session handler still works when setting open_basedir.
$sessionSaveDir = session_save_path() ?: sys_get_temp_dir();
ini_set('open_basedir', $includePath . PATH_SEPARATOR . $sessionSaveDir);
} else {
ini_set('open_basedir', $includePath);
}
require_once('start.php');
if ($_SERVER['HTTP_HOST'] != DOMAIN) {
header('Location: http://' . DOMAIN . $_SERVER['REQUEST_URI'], null, 301);
}
$home = $jsClass = $benchmark = $showAtom = $mainJS = $author = $update = $nameError = $mailError = $msgError = $slugError = $spamError = $codeError = $codeTitleError = $titleError = $error = $author = $authorEmail = $authorURL = $ga = $embed = $noIndex = false;
if (!empty($_GET['slug'])) {
$slug = $_GET['slug'];
$rev = isset($_GET['rev']) ? (int) $_GET['rev'] : 1;
$action = isset($_GET['action']) && in_array($_GET['action'], $reservedActions) ? $_GET['action'] : false;
$id = isset($_GET['id']) ? (int) $_GET['id'] : false;
$atom = isset($_GET['atom']);
$author = isset($_GET['author']) ? $_GET['author'] : false;
$search = in_array($slug, array('search', 'search.atom')) ? isset($_GET['q']) ? $_GET['q'] : '' : false;
$status = $slug == 'status' && $action && is_numeric($action);
if (in_array($slug, $reservedSlugs)) {
if (!$status && !$search && !in_array($_SERVER['REQUEST_URI'], array('/' . $slug, '/' . $slug . '.atom', '/browse/' . $author, '/browse/' . $author . '.atom', '/edit-comment/' . $id, '/delete-comment/' . $id))) {
header('Location: http://' . DOMAIN . '/' . $slug, null, 301);
}
if (!include($slug . ($status ? $action : '') . ($atom ? '.atom' : '') . '.tpl')) {
include('status404.tpl');
}
return;
} else {
$url = '/' . ($author ? 'browse/' . $author . ($atom ? '.atom' : '') : $slug . ($atom ? '.atom' : ($rev > 1 ? '/' . $rev : '') . ($action ? '/' . $action : '')));
if ($url != $_SERVER['REQUEST_URI'] && !$id && !$search) {
header('Location: http://' . DOMAIN . $url, null, 301);
}
}
$result = $db->query('SELECT *, (SELECT MAX(revision) FROM pages WHERE slug = "' . $db->real_escape_string($slug) . '") AS maxRev FROM pages WHERE slug = "' . $db->real_escape_string($slug) . '" AND revision = ' . $rev);
if ($result && $result->num_rows > 0) {
$item = $result->fetch_object();
$title = $item->title;
$result = $db->query('SELECT * FROM tests WHERE pageID = ' . $item->id . ' ORDER BY testID ASC');
$tests = array();
if ($result && $result->num_rows > 0) {
while ($test = $result->fetch_object()) {
$tests[] = $test;
}
if ($slug && $action && $action != 'dev') {
include($action . '.tpl');
return;
} else {
$result = $db->query('SELECT published, updated, author, authorEmail, revision, visible, title FROM pages WHERE slug = "' . $db->real_escape_string($slug) . '" ORDER BY published ASC');
$revisions = array();
if ($result && $result->num_rows > 0) {
while ($revision = $result->fetch_object()) {
$revisions[] = $revision;
}
}
$comments = array();
$sql = 'SELECT * FROM comments WHERE pageID = ' . $item->id . ' ORDER BY published ASC';
if ($result = $db->query($sql)) {
if ($result && $result->num_rows > 0) {
while ($r = $result->fetch_object()) {
$comments[] = $r;
}
}
}
if ($atom) {
require('testPage.atom.tpl');
} else if ($action == 'dev') {
// avoid getting indexed
header('HTTP/1.1 503 Service Unavailable');
require('dev.tpl');
} else {
if (!isset($_SESSION['hits'][$item->id])) {
$db->query('UPDATE pages SET hits = hits + 1 WHERE id = ' . $item->id);
$_SESSION['hits'][$item->id] = true;
}
require('testPage.tpl');
}
}
} else {
@mail(ADMIN_EMAIL, '[jsPerf] Test case without tests, lolwat', $slug);
require('status404.tpl');
}
} else {
// Error: slug not found
require('status404.tpl');
}
} else {
require('index.tpl');
}
?>