92 lines
3.3 KiB
PHP
92 lines
3.3 KiB
PHP
<?php
|
|
|
|
function getDynamicPermission($file): int {
|
|
include_once($file);
|
|
return get_parameters()["minimal_permission_level"];
|
|
}
|
|
|
|
function generateNavigation(): string
|
|
{
|
|
global $routerConfig;
|
|
global $routerRequest;
|
|
|
|
$site_dirs = array_diff(scandir($routerConfig["page_dir"]), array('.', '..'));
|
|
|
|
$nav_out = "";
|
|
|
|
foreach ($site_dirs as $site_dir) {
|
|
$pages_dir = array_diff(scandir($routerConfig["page_dir"] . $site_dir), array('.', '..'));
|
|
|
|
$site_name = str_replace("_", " ", $site_dir);
|
|
if ($site_name == "global") {
|
|
$site_name = "misc";
|
|
$site_subdomain = $routerConfig["default_site"];
|
|
}
|
|
else{
|
|
$site_subdomain = $site_dir;
|
|
}
|
|
|
|
if ($site_name == "smp") {
|
|
$site_name = "SMP";
|
|
} else{
|
|
$site_name = ucfirst($site_name);
|
|
}
|
|
|
|
$site_location = $routerConfig["protocol"] . $site_subdomain . "." . $routerRequest["domain"] . "." . $routerRequest["tld"] . "/" . $routerConfig["default_page"];
|
|
|
|
if ($routerRequest["subdomain"] == $site_dir) {
|
|
//this is the current page
|
|
$site_class = "class=\"navsite_link active\"";
|
|
}
|
|
else{
|
|
$site_class = "class=\"navsite_link\"";
|
|
}
|
|
|
|
$navpages = "";
|
|
|
|
foreach ($pages_dir as $page_file) {
|
|
$page_dir_tmp = explode(".", $page_file);
|
|
$page_dir = $page_dir_tmp[0];
|
|
$page_class = "class=\"navpage_link\"";
|
|
if ($routerRequest["subdomain"] == $site_dir && $routerRequest["page_name"] == $page_dir) {
|
|
$page_class = "class=\"navpage_link active\"";
|
|
}
|
|
|
|
$page_location = $routerConfig["protocol"] . $site_dir . "." . $routerRequest["domain"] . "." . $routerRequest["tld"] . "/" . $page_dir;
|
|
|
|
$page_name = str_replace("_", " ", $page_dir);
|
|
$page_name = explode(".", $page_name)[0];
|
|
$page_name = ucfirst($page_name);
|
|
$page_file_path = $routerConfig["page_dir"] . $site_dir . "/" . $page_file ;
|
|
if($page_dir_tmp[1] == "html"){
|
|
$page_tmp = file_get_contents($page_file_path);
|
|
|
|
$pageMetadata = parsePageTag($page_tmp);
|
|
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"];
|
|
}
|
|
}
|
|
elseif($page_dir_tmp[1] == "php"){
|
|
$page_required_permission = getDynamicPermission($page_file_path);
|
|
}
|
|
else{
|
|
$page_required_permission = $routerConfig["default_page_permission_level"];
|
|
}
|
|
|
|
if($page_required_permission <= $_SESSION["privilegelevel"]) {
|
|
$navpages .= "<li class='navpage_item'><a href='$page_location' $page_class>$page_name</a></li>";
|
|
}
|
|
}
|
|
if(!empty($navpages)){
|
|
$nav_out .= "<li class='navsite_item'><a href='$site_location' $site_class>$site_name</a><ul class='navpage_list'>$navpages</ul></li>";
|
|
}
|
|
}
|
|
|
|
return $nav_out;
|
|
}
|
|
|
|
|