Allow more than two levels in URL

This commit is contained in:
Miraty 2022-09-09 20:15:10 +02:00
parent d53a6e1258
commit 173f7b15d3
2 changed files with 35 additions and 19 deletions

View file

@ -30,11 +30,8 @@ if (
<head>
<meta charset="utf-8">
<title><?php
if (isset($page['title']))
echo strip_tags($page['title']) . " < ";
if (isset($page['service']))
echo strip_tags($page['service']) . " < ";
echo strip_tags(TITLES['index']);
foreach(array_reverse(TITLES_LINEAGE) as $id => $title)
echo strip_tags($title) . (array_key_last(TITLES_LINEAGE) === $id ? '' : ' < ');
?></title>
<?php
foreach (array_diff(scandir(CONF['common']['root_path'] . "/css"), array('..', '.')) as $cssPath)
@ -52,11 +49,13 @@ foreach (array_diff(scandir(CONF['common']['root_path'] . "/css"), array('..', '
<?php } ?>
</p>
<nav>
<ul><li><?php
echo (!isset($page['service'])) ? '<h1><a class="niver" href="..">' . TITLES['index'] . '</a></h1>' : "";
echo (isset($page['service']) AND PAGE == "index") ? '<a class="niver" href="..">' . TITLES['index'] . '</a><ul><li> <a href="."><h1>' . $page['service'] . '</h1></a></li></ul>' : "";
echo (PAGE != "index") ? '<a class="niver" href="..">' . TITLES['index'] . '</a><ul><li> <a href=".">' . $page['service'] . '</a><ul><li> <a href="' . PAGE . '"><h1>' . $page['title'] . "</h1></a></li></ul></li></ul>" : "";
?></li></ul>
<?php
foreach (TITLES_LINEAGE as $id => $title) {
$lastTitle = (TITLES_LINEAGE[array_key_last(TITLES_LINEAGE)] === $title);
echo '<ul><li>' . ($lastTitle ? '<h1>' : '') . '<a' . (($id === 0) ? ' class="niver"' : '') . ' href="' . CONF['common']['prefix'] . ($lastTitle ? '/' . PAGE_URL : '/' . implode('/', array_slice(PAGE_LINEAGE, 0, $id)) . (($lastTitle OR $id === 0) ? '' : '/')) . '">' . $title . '</a>' . ($lastTitle ? '</h1>' : '') . "\n";
}
echo str_repeat('</li></ul>', count(TITLES_LINEAGE));
?>
</nav>
</header>

View file

@ -19,29 +19,46 @@ if (strpos($pageAddress, "?") !== false) {
parse_str(substr($pageAddress, strpos($pageAddress, "?") + 1), $_GET);
$pageAddress = substr($pageAddress, 0, strpos($pageAddress, "?"));
}
if (substr($pageAddress, -1) === '/' OR $pageAddress === '')
$pageAddress .= 'index';
define("PAGE_ADDRESS", $pageAddress);
define("PAGE_URL", $pageAddress);
define("PAGE_ADDRESS", $pageAddress . ((substr($pageAddress, -1) === '/' OR $pageAddress === '') ? 'index' : ''));
define("PAGE_LINEAGE", explode('/', PAGE_ADDRESS));
define("SERVICE", dirname(PAGE_ADDRESS));
define("PAGE", basename(PAGE_ADDRESS, '.php'));
require "pages.php";
if (SERVICE !== '.') {
if (!isset(TITLES[SERVICE]['index'])) {
if (PAGE !== 'index') {
if (!isset(TITLES[SERVICE][PAGE])) {
http_response_code(404);
exit('Page not found.');
}
$page['service'] = TITLES[SERVICE]['index'];
if (PAGE !== 'index') {
if (!isset(TITLES[SERVICE][PAGE])) {
if (SERVICE !== '.') {
if (!isset(TITLES[SERVICE]['index'])) {
http_response_code(404);
exit('Page not found.');
}
$page['title'] = TITLES[SERVICE][PAGE];
}
}
for (
$path_i = PAGE_LINEAGE , $results = [] , $firstIteration = true ;
$title = TITLES , $path_i !== [] ;
array_pop($path_i) , $results[] = $title
) {
foreach ($path_i as $el) {
if (end($path_i) !== $el)
$title = $title[$el];
else {
if ($firstIteration AND end($path_i) !== 'index')
$results[] = $title[$el];
$firstIteration = false;
$title = $title['index'];
}
}
}
define('TITLES_LINEAGE', array_reverse($results));
require "html.php";
function executePage() {