Add some more account actions,
Add return types, Add some stuff
This commit is contained in:
62
lib/page.php
62
lib/page.php
@@ -5,6 +5,31 @@ function renderDynamicPage($page_file): false|string
|
||||
return render();
|
||||
}
|
||||
|
||||
function parsePageTag($input): array
|
||||
{
|
||||
// Define the pattern for the tag
|
||||
$pattern = '/<page\s+([^>]+)><\/page>/i';
|
||||
|
||||
// Check if the pattern matches the input
|
||||
if (preg_match($pattern, $input, $matches)) {
|
||||
// Extract parameters
|
||||
$parameters = [];
|
||||
if (preg_match_all('/(\w+)="([^"]+)"/', $matches[1], $paramMatches, PREG_SET_ORDER)) {
|
||||
foreach ($paramMatches as $paramMatch) {
|
||||
$parameters[$paramMatch[1]] = $paramMatch[2];
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the tag from the input
|
||||
$output = preg_replace($pattern, '', $input, 1);
|
||||
|
||||
return ['parameters' => $parameters, 'output' => $output];
|
||||
}
|
||||
|
||||
// If no match is found, return the original input
|
||||
return ['parameters' => [], 'output' => $input];
|
||||
}
|
||||
|
||||
function getPage($page_name = null): array|false|string
|
||||
{
|
||||
global $routerConfig;
|
||||
@@ -38,6 +63,41 @@ function getPage($page_name = null): array|false|string
|
||||
else{
|
||||
$page = file_get_contents($routerConfig["template_dir"] . "404.html");
|
||||
}
|
||||
|
||||
$pageMetadata = parsePageTag($page);
|
||||
|
||||
$page = $pageMetadata["output"];
|
||||
|
||||
if(!empty($pageMetadata["parameters"]["minimal_permission_level"])){
|
||||
$page_required_permission = intval($pageMetadata["parameters"]["minimal_permission_level"]);
|
||||
}
|
||||
else{
|
||||
$page_required_permission = $routerConfig["default_page_permission_level"];
|
||||
}
|
||||
|
||||
if(!empty($pageMetadata["parameters"]["secret"])){
|
||||
$is_secret_page = intval($pageMetadata["parameters"]["secret"]);
|
||||
}
|
||||
else{
|
||||
$is_secret_page = $routerConfig["default_page_secret"];
|
||||
}
|
||||
|
||||
if($page_required_permission < $_SESSION["privilegelevel"]){
|
||||
if($is_secret_page == 1) {
|
||||
$page = file_get_contents($routerConfig["template_dir"] . "404.html"); //fake 404 error
|
||||
}
|
||||
else{
|
||||
$page = file_get_contents($routerConfig["template_dir"] . "403.html"); //deny access if doesnt have permissions
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($pageMetadata["parameters"]["page_title"])){
|
||||
$page_title = $pageMetadata["parameters"]["page_title"];
|
||||
}
|
||||
else{
|
||||
$page_title = $page_name;
|
||||
}
|
||||
|
||||
$navpages = generateNavigation();
|
||||
|
||||
$nav = str_replace("__NAV_PAGES__", $navpages, $nav);
|
||||
@@ -45,5 +105,5 @@ function getPage($page_name = null): array|false|string
|
||||
$out = $skeleton;
|
||||
$out = str_replace("__TEMPLATE__NAV__", $nav, $out);
|
||||
$out = str_replace("__TEMPLATE__PAGE__", $page, $out);
|
||||
return str_replace("__TEMPLATE_PAGE_NAME__", $page_name, $out);
|
||||
return str_replace("__TEMPLATE_PAGE_TITLE__", $page_title, $out);
|
||||
}
|
Reference in New Issue
Block a user