-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
157 lines (121 loc) · 4.23 KB
/
index.php
File metadata and controls
157 lines (121 loc) · 4.23 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
*
*
* @author Knut Kohl <github@knutkohl.de>
* @copyright (c) 2016 Knut Kohl
* @licence MIT License - http://opensource.org/licenses/MIT
*/
use App\Config;
use App\Encoder;
use App\Hook;
use App\I18N;
use App\Snipes;
use App\User;
/**
*
*/
if (!isset($_SERVER['REQUEST_TIME_FLOAT'])) {
// Make sure, $_SERVER['REQUEST_TIME_FLOAT'] exists
$_SERVER['REQUEST_TIME_FLOAT'] = microtime(true);
}
session_start();
setcookie(session_name(), session_id(), time() + 86400, '/');
require 'vendor/autoload.php';
// May not exist
@include 'hooks.php';
Hook::apply('init');
// Load default config and custom config if exists
$config = Config::getInstance()->load('config.default.php')->load('config.local.php');
// Must be set via config.local.php
if ($config->debug) {
ini_set('display_errors', 1);
error_reporting(-1);
}
if ($config->esniper == '') {
die('Can not find esniper binary, please help and define in <pre>config.local.php</pre>');
}
if (isset($_GET['login'])) {
list($_SESSION['user'], $_SESSION['pass'], $_SESSION['lang']) =
explode("\t", Encoder::decrypt($_GET['login'], $config->secret));
$_SESSION['token'] = $_GET['login'];
// session_write_close();
// die(header('Location: /'));
}
if (isset($_SESSION['lang'])) {
$config->language = $_SESSION['lang'];
}
$config->version = trim(file_get_contents('.version'));
$config->esniper_version = exec('esniper -v 2>&1 | head -n 1');
setlocale(LC_ALL, $config->locales[$config->language]);
if (!is_dir($config->dataDir) && !mkdir($config->dataDir, 0700, true)) {
die(sprintf(
'Unable to create data directory:<pre>%s</pre>Please check permissions.',
$config->dataDir
));
}
Hook::apply('config.loaded', $config);
I18N::load(realpath('language/' . $config->language . '.php'));
if (isset($_SESSION['user'], $_SESSION['pass'])) {
$page = 'home';
User::init($_SESSION['user'], $_SESSION['pass']);
$user_name=User::$name;
// Load all auction groups
$snipes = new Snipes();
// Any bug reports?
$bugs = glob(User::$dir.'/esniper.*.bug.html');
$bugs = array_map(function ($file) {
return basename($file);
}, $bugs);
} else {
$page = 'login';
}
Hook::apply('before.action', $page);
// Check for API calls
include 'api.php';
// Check for form submits
include 'post.php';
$server_name = $_SERVER['SERVER_NAME'];
foreach (['index', $page] as $tpl) {
$cpl = 'design_cpl/' . $config->design . '.' . $tpl . '.html';
$tpl = 'design/' . $config->design . '/' . $tpl . '.phtml';
if ($config->debug || !is_file($cpl) || filemtime($cpl) < filemtime($tpl)) {
// Compile template
$html = file_get_contents($tpl);
Hook::apply('template.compile', $html);
// Variables - {{$var_name}}
if (preg_match_all('~\{\{(\$.+?)\}\}~', $html, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$html = str_replace($match[0], '<?php echo '.$match[1].' ?'.'>', $html);
}
}
// Coding - {{if (true):}}
if (preg_match_all('~\{\{(.+?)\}\}~s', $html, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$html = str_replace($match[0], '<?php '.$match[1].' ?'.'>', $html);
}
}
// Translations - {|translation_id|}
if (preg_match_all('~\{\|(\w+)\|\}~', $html, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$html = str_replace($match[0], '<?php echo App\I18N::_(\''.$match[1].'\') ?'.'>', $html);
}
}
Hook::apply('template.compiled', $html);
if ($config->compress) {
$html = preg_replace('~\s+~s', ' ', $html);
$html = preg_replace('~<!--.+?-->~', '', $html);
$html = preg_replace('~/\*.+?\*/~s', ' ', $html);
$html = preg_replace('~>\s+<~s', '><', $html);
$html = str_replace(['<?php', '?'.'>'], ['<?php ', ' ?'.'>'], $html);
Hook::apply('template.compressed', $html);
}
file_put_contents($cpl, $html);
}
}
Hook::apply('before.render');
// Show
include 'design_cpl/' . $config->design . '.index.html';
Hook::apply('after.render');
unset($_SESSION['new']);
session_write_close();