This commit is contained in:
Bruno Rybársky 2024-01-11 15:23:14 +01:00
parent ed9a5bd936
commit d34edd78cd

@ -1,24 +1,46 @@
<?php <?php
ob_start(); ob_start();
$navsite_template = '<li><a class="navsite_link" href="__LOCATION__" __CLASS__>__NAME__</a><ul class="navpage_list"></ul></li>'; $navsite_template = '<li><a href="__LOCATION__" __CLASS__>__NAME__</a><ul class="navpage_list">__NAVPAGES__</ul></li>';
$navpage_template = '<li><a class="navpage_link" href="__LOCATION__" __CLASS__>__NAME__</a></li>'; $navpage_template = '<li><a class="navpage_link" href="__LOCATION__" __CLASS__>__NAME__</a></li>';
$page_dir = "pages";
$site_dirs = array_diff(scandir($page_dir), array('.', '..')); $site_dirs = array_diff(scandir($page_dir), array('.', '..'));
$domain = basename(explode('.', $_SERVER['HTTP_HOST'])[1]);
$tld = basename(explode('.', $_SERVER['HTTP_HOST'])[2]);
foreach($site_dirs as $site_dir){ foreach($site_dirs as $site_dir){
$pages_dir = array_diff(scandir("$page_dir/$site_dir"), array('.', '..')); $pages_dir = array_diff(scandir("$page_dir/$site_dir"), array('.', '..'));
$navsite = $navpage_template;
$site_location = "$site_dir.$domain.$tld/$default_page";
$site_class = "class=\"navsite_link\"";
$site_name = str_replace("_", " ", $site_location);
$navsite = str_replace("__CLASS__", $site_class, $navsite);
$navsite = str_replace("__LOCATION__", $site_location, $navsite);
$navsite = str_replace("__NAME__", $site_name, $navsite);
if($subdomain == $site_dir){
//this is the current page
$site_class = "class=\"navsite_link active\"";
}
$navpages = ""; $navpages = "";
foreach($pages_dir as $page_dir){ foreach($pages_dir as $page_dir){
$navpage = $navpage_template; $navpage = $navpage_template;
$navpage = $page_class = "class=\"navpage_link\"";
if($subdomain == $site_dir && $page_name == $page_dir){
$page_class = "class=\"navpage_link active\"";
}
$page_location = "$site_dir.$domain.$tld/$page_dir";
$page_name = str_replace("_", " ", $page_location);
$navpage = str_replace("__CLASS__", $page_class, $navpage);
$navpage = str_replace("__LOCATION__", $page_location, $navpage);
$navpage = str_replace("__NAME__", $page_name, $navpage);
$navpages .= $navpage; $navpages .= $navpage;
} }
$navsite = str_replace("__NAVPAGES__", $navpages, $navsite);
} }
return ob_get_clean(); return ob_get_clean();