index fertig bis auf rank

This commit is contained in:
Timon Ostertun
2020-09-22 23:32:48 +02:00
parent cb840a8451
commit 4a3a8b636b
19 changed files with 2215 additions and 73 deletions

37
server/scripts.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
class Scripts {
private $path;
private $scripts;
function __construct($path) {
if (substr($path, -1) != '/') $path .= '/';
$this->path = $path;
$this->scripts = [];
}
function load($name, $params = []) {
if (!isset($this->scripts[$name])) {
$filename = $this->path . $name . '.js';
if (file_exists($filename) and is_file($filename)) {
$this->scripts[$name] = file_get_contents($filename);
} else {
return "<p>Script '$name' not found!</p>";
}
}
$script = $this->scripts[$name];
while (($pos = strpos($script, '$$')) !== false) {
$pos += 2;
$pos2 = strpos($script, ';', $pos);
if ($pos2 === false) return "<p>Syntax error in script '$name'!</p>";
$ph = substr($script, $pos, $pos2 - $pos);
if (!isset($params[$ph])) $params[$ph] = '';
$script = str_replace('$$' . $ph . ';', $params[$ph], $script);
}
return '<script>' . $script . '</script>';
}
}
?>