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:
1 parent
f8a40bb668
commit
511d1fc220
5 files changed
+56
-7
No files matched your search
+31
-6
@@ -4,7 +4,7 @@ class HTMLLoader {
|
|||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
// Check if Paths variables exists
|
// 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__);
|
die("TEMPLATE_PATH or TEMPLATE_CONF are not defined at " . __FILE__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,11 +27,26 @@ class HTMLLoader {
|
|||||||
$file = file_get_contents(TEMPLATE_CONF);
|
$file = file_get_contents(TEMPLATE_CONF);
|
||||||
$json = json_decode($file, true);
|
$json = json_decode($file, true);
|
||||||
|
|
||||||
$error_page = $json["error"];
|
$page = $json["error"];
|
||||||
$error_html = file_get_contents(TEMPLATE_PATH . $error_page["dir_name"] . "/" . $error_page["html_file"]);
|
$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
|
// Write error
|
||||||
$replace = str_replace("%error%", $error, $error_html);
|
$replace = str_replace("%error%", $error, $html);
|
||||||
|
|
||||||
die($replace);
|
die($replace);
|
||||||
}
|
}
|
||||||
@@ -43,9 +58,19 @@ class HTMLLoader {
|
|||||||
$json = json_decode($file, true);
|
$json = json_decode($file, true);
|
||||||
|
|
||||||
$page = $json[$template];
|
$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
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ class gb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Define Paths
|
// Define Paths
|
||||||
|
define("APP_DOMAIN", $_SERVER["SERVER_NAME"]);
|
||||||
define("APP_PATH", __DIR__ . "/..");
|
define("APP_PATH", __DIR__ . "/..");
|
||||||
define("FRONTEND_PATH", __DIR__ . "/");
|
define("FRONTEND_PATH", __DIR__ . "/");
|
||||||
define("TEMPLATE_PATH", FRONTEND_PATH . "templates/");
|
define("TEMPLATE_PATH", FRONTEND_PATH . "templates/");
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.icon {
|
||||||
|
font-size: 100pt;
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
foreach($_SERVER as $key => $value) {
|
||||||
|
echo $key . " === " . $value . "<br>";
|
||||||
|
}
|
||||||
Reference in new issue
Block a user