fix dynamic pages

This commit is contained in:
Richard Mikloš 2024-02-01 13:44:00 +01:00
parent 7920fa5b1d
commit 6e63f56fe2

@ -1,5 +1,10 @@
<?php <?php
function getDynamicPermission($file): int {
include_once($file);
return get_parameters()["minimal_permission_level"];
}
function generateNavigation(): string function generateNavigation(): string
{ {
global $routerConfig; global $routerConfig;
@ -36,7 +41,8 @@ function generateNavigation(): string
$navpages = ""; $navpages = "";
foreach ($pages_dir as $page_file) { foreach ($pages_dir as $page_file) {
$page_dir = explode(".", $page_file)[0]; $page_dir_tmp = explode(".", $page_file);
$page_dir = $page_dir_tmp[0];
$page_class = "class=\"navpage_link\""; $page_class = "class=\"navpage_link\"";
if ($routerRequest["subdomain"] == $site_dir && $routerRequest["page_name"] == $page_dir) { if ($routerRequest["subdomain"] == $site_dir && $routerRequest["page_name"] == $page_dir) {
$page_class = "class=\"navpage_link active\""; $page_class = "class=\"navpage_link active\"";
@ -48,15 +54,24 @@ function generateNavigation(): string
$page_name = explode(".", $page_name)[0]; $page_name = explode(".", $page_name)[0];
$page_name = ucfirst($page_name); $page_name = ucfirst($page_name);
$page_file = $routerConfig["page_dir"] . $site_dir . "/" . $page_file ; $page_file = $routerConfig["page_dir"] . $site_dir . "/" . $page_file ;
if($page_dir_tmp[1] == "html"){
$page_tmp = file_get_contents($page_file); $page_tmp = file_get_contents($page_file);
$pageMetadata = parsePageTag($page_tmp); //make dynamic pages work here $pageMetadata = parsePageTag($page_tmp);
if(!empty($pageMetadata["parameters"]["minimal_permission_level"])){ if(!empty($pageMetadata["parameters"]["minimal_permission_level"])){
$page_required_permission = intval($pageMetadata["parameters"]["minimal_permission_level"]); $page_required_permission = intval($pageMetadata["parameters"]["minimal_permission_level"]);
} }
else{ else{
$page_required_permission = $routerConfig["default_page_permission_level"]; $page_required_permission = $routerConfig["default_page_permission_level"];
} }
}
elseif($page_dir_tmp[1] == "php"){
$page_required_permission = getDynamicPermission($page_file);
}
else{
$page_required_permission = $routerConfig["default_page_permission_level"];
}
if($page_required_permission <= $_SESSION["privilegelevel"]) { if($page_required_permission <= $_SESSION["privilegelevel"]) {
$navpages .= "<li class='navpage_item'><a href='$page_location' $page_class>$page_name</a></li>"; $navpages .= "<li class='navpage_item'><a href='$page_location' $page_class>$page_name</a></li>";