Individualisations

This commit is contained in:
Timon Ostertun
2020-09-21 21:06:16 +02:00
parent 7e8d863e26
commit 62cb4408cf
21 changed files with 1810 additions and 1632 deletions

37
server/templates.php Normal file
View File

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