Files
better_guestbook/public/html_loader.php
T
2026-10-02 16:05:50 +00:00

51 lines
1.5 KiB
PHP
Executable File

<?php
class HTMLLoader {
private $template;
function __construct() {
// Check if Paths variables exists
if (!defined("TEMPLATE_PATH") || !defined("TEMPLATE_CONF")) {
die("TEMPLATE_PATH or TEMPLATE_CONF are not defined at " . __FILE__);
}
}
function setTemplate($template) {
// Check if template exists
$file = file_get_contents(TEMPLATE_CONF);
$json = json_decode($file, true);
if (!array_key_exists($template, $json) && array_key_exists("error", $json)) {
$this->showError('Template "' . $template . '" was not found.');
exit;
}elseif (!array_key_exists("error", $json)){
die("Error Template was not found.");
}
$this->template = $template;
}
function showError($error) {
$file = file_get_contents(TEMPLATE_CONF);
$json = json_decode($file, true);
$error_page = $json["error"];
$error_html = file_get_contents(TEMPLATE_PATH . $error_page["dir_name"] . "/" . $error_page["html_file"]);
// Write error
$replace = str_replace("%error%", $error, $error_html);
die($replace);
}
function show() {
$template = $this->template;
$file = file_get_contents(TEMPLATE_CONF);
$json = json_decode($file, true);
$page = $json[$template];
$html = file_get_contents(TEMPLATE_PATH . $page["dir_name"] . "/" . $page["html"]);
// Get CSS
foreach ($page[""])
}
}