2024-01-11 10:14:21 +01:00
|
|
|
<?php
|
|
|
|
|
2024-02-01 13:44:00 +01:00
|
|
|
function getDynamicPermission($file): int {
|
|
|
|
include_once($file);
|
|
|
|
return get_parameters()["minimal_permission_level"];
|
|
|
|
}
|
|
|
|
|
2024-01-31 22:05:23 +01:00
|
|
|
function generateNavigation(): string
|
2024-01-12 16:20:17 +01:00
|
|
|
{
|
2024-01-16 20:43:57 +01:00
|
|
|
global $routerConfig;
|
|
|
|
global $routerRequest;
|
|
|
|
|
2024-01-16 20:56:37 +01:00
|
|
|
$site_dirs = array_diff(scandir($routerConfig["page_dir"]), array('.', '..'));
|
2024-01-11 10:14:21 +01:00
|
|
|
|
2024-01-12 16:20:17 +01:00
|
|
|
$nav_out = "";
|
2024-01-11 10:14:21 +01:00
|
|
|
|
2024-01-12 16:20:17 +01:00
|
|
|
foreach ($site_dirs as $site_dir) {
|
2024-01-16 20:56:37 +01:00
|
|
|
$pages_dir = array_diff(scandir($routerConfig["page_dir"] . $site_dir), array('.', '..'));
|
2024-01-11 16:02:10 +01:00
|
|
|
|
2024-01-12 16:20:17 +01:00
|
|
|
$site_name = str_replace("_", " ", $site_dir);
|
|
|
|
if ($site_name == "global") {
|
|
|
|
$site_name = "misc";
|
2024-01-17 08:44:13 +01:00
|
|
|
$site_dir = $routerConfig["default_site"];
|
2024-01-11 15:23:14 +01:00
|
|
|
}
|
2024-01-17 11:06:02 +01:00
|
|
|
|
|
|
|
if ($site_name == "smp") {
|
2024-01-17 11:06:53 +01:00
|
|
|
$site_name = "SMP";
|
2024-01-17 11:06:02 +01:00
|
|
|
} else{
|
|
|
|
$site_name = ucfirst($site_name);
|
|
|
|
}
|
2024-01-16 20:52:53 +01:00
|
|
|
|
2024-01-16 21:31:19 +01:00
|
|
|
$site_location = $routerConfig["protocol"] . $site_dir . "." . $routerRequest["domain"] . "." . $routerRequest["tld"] . "/" . $routerConfig["default_page"];
|
2024-01-12 16:20:17 +01:00
|
|
|
|
2024-01-16 20:43:57 +01:00
|
|
|
if ($routerRequest["subdomain"] == $site_dir) {
|
2024-01-12 16:20:17 +01:00
|
|
|
//this is the current page
|
|
|
|
$site_class = "class=\"navsite_link active\"";
|
|
|
|
}
|
2024-01-16 20:43:57 +01:00
|
|
|
else{
|
|
|
|
$site_class = "class=\"navsite_link\"";
|
|
|
|
}
|
|
|
|
|
2024-01-12 16:20:17 +01:00
|
|
|
$navpages = "";
|
2024-02-02 00:34:56 +01:00
|
|
|
print_r($pages_dir);
|
2024-02-01 10:14:49 +01:00
|
|
|
foreach ($pages_dir as $page_file) {
|
2024-02-01 13:44:00 +01:00
|
|
|
$page_dir_tmp = explode(".", $page_file);
|
|
|
|
$page_dir = $page_dir_tmp[0];
|
2024-01-12 16:20:17 +01:00
|
|
|
$page_class = "class=\"navpage_link\"";
|
2024-01-16 20:43:57 +01:00
|
|
|
if ($routerRequest["subdomain"] == $site_dir && $routerRequest["page_name"] == $page_dir) {
|
2024-01-12 16:20:17 +01:00
|
|
|
$page_class = "class=\"navpage_link active\"";
|
|
|
|
}
|
2024-01-11 15:23:14 +01:00
|
|
|
|
2024-01-16 21:31:19 +01:00
|
|
|
$page_location = $routerConfig["protocol"] . $site_dir . "." . $routerRequest["domain"] . "." . $routerRequest["tld"] . "/" . $page_dir;
|
2024-01-11 15:23:14 +01:00
|
|
|
|
2024-01-12 16:20:17 +01:00
|
|
|
$page_name = str_replace("_", " ", $page_dir);
|
|
|
|
$page_name = explode(".", $page_name)[0];
|
2024-01-17 11:06:02 +01:00
|
|
|
$page_name = ucfirst($page_name);
|
2024-02-01 10:14:49 +01:00
|
|
|
$page_file = $routerConfig["page_dir"] . $site_dir . "/" . $page_file ;
|
2024-01-11 15:23:14 +01:00
|
|
|
|
2024-02-01 13:44:00 +01:00
|
|
|
if($page_dir_tmp[1] == "html"){
|
|
|
|
$page_tmp = file_get_contents($page_file);
|
|
|
|
|
|
|
|
$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);
|
2024-02-01 10:14:49 +01:00
|
|
|
}
|
|
|
|
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>";
|
2024-01-12 16:20:17 +01:00
|
|
|
}
|
2024-01-11 10:28:00 +01:00
|
|
|
}
|
|
|
|
|
2024-01-12 16:20:17 +01:00
|
|
|
return $nav_out;
|
|
|
|
}
|
2024-01-11 10:14:21 +01:00
|
|
|
|
2024-01-16 20:43:57 +01:00
|
|
|
|