From f1dc7d866f2a642f2212e826370a1bba1f2cd54b Mon Sep 17 00:00:00 2001 From: bruno Date: Thu, 1 Feb 2024 09:10:55 +0100 Subject: [PATCH] test --- lib/page.php | 26 ++++++++++++++++++++------ pages/global/account.php | 7 ++++++- templates/500.html | 6 ++++++ 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 templates/500.html diff --git a/lib/page.php b/lib/page.php index ee3b4c6..de399e1 100644 --- a/lib/page.php +++ b/lib/page.php @@ -1,8 +1,10 @@ $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); } } diff --git a/pages/global/account.php b/pages/global/account.php index 4bca5ee..b010640 100644 --- a/pages/global/account.php +++ b/pages/global/account.php @@ -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; diff --git a/templates/500.html b/templates/500.html new file mode 100644 index 0000000..93e5228 --- /dev/null +++ b/templates/500.html @@ -0,0 +1,6 @@ +
+

Niekto to pobabral

+

500

+

Nejaký neschopný vývojár nevedel robiť túto stránku: __TEMPLATE_PAGE_NAME__.

+ SPÄŤ DOMOV +
\ No newline at end of file