This commit is contained in:
Bruno Rybársky 2024-02-01 09:10:55 +01:00
parent 3b3a504c9f
commit f1dc7d866f
3 changed files with 32 additions and 7 deletions

@ -1,8 +1,10 @@
<?php
function renderDynamicPage($page_file): false|string
function renderDynamicPage($page_file): array
{
require_once $page_file;
return render();
$page_parameters = get_parameters();
$page_content = render();
return ["output" => $page_content, "parameters" => $page_parameters];
}
function parsePageTag($input): array
@ -49,16 +51,26 @@ function getPage($page_name = null): array|false|string
$nav = file_get_contents($routerConfig["template_dir"] . "nav.html");
if (file_exists($dynamic_page_file_global)){
$page = renderDynamicPage($dynamic_page_file_global);
$pageMetadata = renderDynamicPage($dynamic_page_file_global);
$page = $pageMetadata["output"];
}
elseif (file_exists($page_file_global)){
$page = file_get_contents($page_file_global);
$pagetmp = file_get_contents($page_file_global);
$pageMetadata = parsePageTag($pagetmp);
$page = $pageMetadata["output"];
}
elseif (file_exists($dynamic_page_file)){
$page = renderDynamicPage($dynamic_page_file);
$pageMetadata = renderDynamicPage($dynamic_page_file);
$page = $pageMetadata["output"];
}
elseif (file_exists($page_file)){
$page = file_get_contents($page_file);
$pagetmp = file_get_contents($page_file);
$pageMetadata = parsePageTag($pagetmp);
$page = $pageMetadata["output"];
}
else{
$page = file_get_contents($routerConfig["template_dir"] . "404.html");
@ -85,9 +97,11 @@ function getPage($page_name = null): array|false|string
if($page_required_permission < $_SESSION["privilegelevel"]){
if($is_secret_page == 1) {
$page = file_get_contents($routerConfig["template_dir"] . "404.html"); //fake 404 error
http_response_code(404);
}
else{
$page = file_get_contents($routerConfig["template_dir"] . "403.html"); //deny access if doesnt have permissions
http_response_code(403);
}
}

@ -2,7 +2,12 @@
require_once "lib/router.php";
function render(): false|string
function get_parameters():array
{
return ["minimal_permission_level" => 0, "secret" => 0, "page_title" => "Domov"];
}
function render(): string
{
global $routerConfig;

6
templates/500.html Normal file

@ -0,0 +1,6 @@
<div class="wrapper-500">
<h2>Niekto to pobabral</h2>
<h1 class="error-code">500</h1>
<h3><i class="fa-solid fa-circle-exclamation error"></i> Nejaký neschopný vývojár nevedel robiť túto stránku: <span class="error">__TEMPLATE_PAGE_NAME__</span>. <i class="fa-solid fa-circle-exclamation error"></i></h3>
<a href="/domov" class="back"><i class="fa-solid fa-arrow-left"></i> SPÄŤ DOMOV</a>
</div>