Enhance HTMLLoader to include CSS files in error templates and add error handling for missing CSS. Define APP_DOMAIN in main.php and update error template structure.

This commit is contained in:
marc-go committed 2026-10-02 19:25:56 +02:00
1 parent f8a40bb668
commit 511d1fc220
5 files changed
+56 -7

No files matched your search

+31 -6
View File
@@ -4,7 +4,7 @@ class HTMLLoader {
function __construct() {
// Check if Paths variables exists
if (!defined("TEMPLATE_PATH") || !defined("TEMPLATE_CONF")) {
if (!defined("TEMPLATE_PATH") || !defined("TEMPLATE_CONF") || !defined("APP_DOMAIN")) {
die("TEMPLATE_PATH or TEMPLATE_CONF are not defined at " . __FILE__);
}
}
@@ -27,11 +27,26 @@ class HTMLLoader {
$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"]);
$page = $json["error"];
$html = file_get_contents(TEMPLATE_PATH . $page["dir_name"] . "/" . $page["html_file"]);
$css = "";
// Get CSS
foreach ($page["css_files"] as $file) {
// Check if File exists
if (!is_file(TEMPLATE_PATH . $page["dir_name"] . "/" . $file)) {
$this->showError('CSS File <span class="code">' . $file . '</span> for Template <span class="code">error</span> in <span class="code">' . __FILE__ . "</span>");
}
// Add CSS Files to HTML
$css .= '<link rel="stylessheet" type="text/css" href="http://' . APP_DOMAIN . "/templates/" . $page["dir_name"] . "/" . $file . '">';
}
$html = str_replace("%css%", $css, $html);
// Write error
$replace = str_replace("%error%", $error, $error_html);
$replace = str_replace("%error%", $error, $html);
die($replace);
}
@@ -43,9 +58,19 @@ class HTMLLoader {
$json = json_decode($file, true);
$page = $json[$template];
$html = file_get_contents(TEMPLATE_PATH . $page["dir_name"] . "/" . $page["html"]);
$html = file_get_contents(TEMPLATE_PATH . $page["dir_name"] . "/" . $page["html_file"]);
// Get CSS
foreach ($page[""])
foreach ($page["css_files"] as $file) {
// Check if File exists
if (!is_file(TEMPLATE_PATH . $page["dir_name"] . "/" . $file)) {
$this->showError('CSS File <span class="code">' . $file . '</span> for Template <span class="code">' . $this->template . '</span> in <span class="code">' . __FILE__ . "</span>");
}
// Add CSS Files to HTML
$css .= '<link rel="stylessheet" text="text/css" href="' . APP_DOMAIN . "/templates/" . $page["dir_name"] . "/" . $file . '">';
}
$html = str_replace("%css%", $css, $html);
}
}
+1
View File
@@ -9,6 +9,7 @@ class gb {
}
// Define Paths
define("APP_DOMAIN", $_SERVER["SERVER_NAME"]);
define("APP_PATH", __DIR__ . "/..");
define("FRONTEND_PATH", __DIR__ . "/");
define("TEMPLATE_PATH", FRONTEND_PATH . "templates/");
+3
View File
@@ -0,0 +1,3 @@
.icon {
font-size: 100pt;
}
+16 -1
View File
@@ -1 +1,16 @@
<h1>%error%</h1>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error</title>
%css%
</head>
<body>
<div class="page-content">
<div class="icon">
⚠️
</div>
</div>
</body>
</html>
+5
View File
@@ -0,0 +1,5 @@
<?php
foreach($_SERVER as $key => $value) {
echo $key . " === " . $value . "<br>";
}