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() {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user