Cofem/templates/navpages.php

59 lines
2.2 KiB
PHP
Raw Normal View History

2024-01-11 10:14:21 +01:00
<?php
2024-01-12 16:20:17 +01:00
function generateNavigation($static_page_dir, $protocol, $subdomain, $domain, $tld, $default_page, $page_name)
{
$navsite_template = '<li class="navsite_item"><a href="__LOCATION__" __CLASS__>__NAME__</a><ul class="navpage_list">__NAVPAGES__</ul></li>';
$navpage_template = '<li class="navpage_item"><a href="__LOCATION__" __CLASS__>__NAME__</a></li>';
2024-01-11 10:14:21 +01:00
2024-01-12 16:20:17 +01:00
$site_dirs = array_diff(scandir($static_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) {
$pages_dir = array_diff(scandir("$static_page_dir$site_dir"), array('.', '..'));
2024-01-11 16:02:10 +01:00
2024-01-12 16:20:17 +01:00
$navsite = $navsite_template;
$site_class = "class=\"navsite_link\"";
$site_name = str_replace("_", " ", $site_dir);
if ($site_name == "global") {
$site_name = "misc";
$site_dir = $default_page;
2024-01-11 15:23:14 +01:00
}
2024-01-12 16:20:17 +01:00
$site_location = "$protocol$site_dir.$domain.$tld/$default_page";
$navsite = str_replace("__CLASS__", $site_class, $navsite);
$navsite = str_replace("__LOCATION__", $site_location, $navsite);
2024-01-16 19:03:58 +01:00
$navsite = str_replace("__NAME__", $site_name.ucfirst(), $navsite);
2024-01-12 16:20:17 +01:00
if ($subdomain == $site_dir) {
//this is the current page
$site_class = "class=\"navsite_link active\"";
}
$navpages = "";
foreach ($pages_dir as $page_dir) {
$page_dir = explode(".", $page_dir)[0];
$navpage = $navpage_template;
$page_class = "class=\"navpage_link\"";
if ($subdomain == $site_dir && $page_name == $page_dir) {
$page_class = "class=\"navpage_link active\"";
}
2024-01-11 15:23:14 +01:00
2024-01-12 16:20:17 +01:00
$page_location = "$protocol$site_dir.$domain.$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-11 15:23:14 +01:00
2024-01-12 16:20:17 +01:00
$navpage = str_replace("__CLASS__", $page_class, $navpage);
$navpage = str_replace("__LOCATION__", $page_location, $navpage);
$navpage = str_replace("__NAME__", $page_name, $navpage);
$navpages .= $navpage;
}
$navsite = str_replace("__NAVPAGES__", $navpages, $navsite);
$nav_out .= $navsite;
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-12 16:20:17 +01:00
?>