80 lines
2.8 KiB
PHP
Executable File
80 lines
2.8 KiB
PHP
Executable File
<?php
|
|
class HTMLLoader {
|
|
private $template;
|
|
|
|
function __construct() {
|
|
// Check if Paths variables exists
|
|
if (!defined("TEMPLATE_PATH") || !defined("TEMPLATE_CONF") || !defined("APP_DOMAIN")) {
|
|
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);
|
|
|
|
$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> not found.");
|
|
}
|
|
|
|
// Add CSS Files to HTML
|
|
$css .= '<link rel="stylesheet" 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, $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_file"]);
|
|
|
|
// Get CSS
|
|
$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">' . $this->template . '</span> in <span class="code">' . __FILE__ . "</span> not found.");
|
|
}
|
|
|
|
// 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);
|
|
|
|
die($html);
|
|
}
|
|
} |