Allow more than two levels in URL
This commit is contained in:
parent
d53a6e1258
commit
173f7b15d3
2 changed files with 35 additions and 19 deletions
19
html.php
19
html.php
|
@ -30,11 +30,8 @@ if (
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title><?php
|
<title><?php
|
||||||
if (isset($page['title']))
|
foreach(array_reverse(TITLES_LINEAGE) as $id => $title)
|
||||||
echo strip_tags($page['title']) . " < ";
|
echo strip_tags($title) . (array_key_last(TITLES_LINEAGE) === $id ? '' : ' < ');
|
||||||
if (isset($page['service']))
|
|
||||||
echo strip_tags($page['service']) . " < ";
|
|
||||||
echo strip_tags(TITLES['index']);
|
|
||||||
?></title>
|
?></title>
|
||||||
<?php
|
<?php
|
||||||
foreach (array_diff(scandir(CONF['common']['root_path'] . "/css"), array('..', '.')) as $cssPath)
|
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 } ?>
|
<?php } ?>
|
||||||
</p>
|
</p>
|
||||||
<nav>
|
<nav>
|
||||||
<ul><li><?php
|
<?php
|
||||||
echo (!isset($page['service'])) ? '<h1><a class="niver" href="..">' . TITLES['index'] . '</a></h1>' : "";
|
foreach (TITLES_LINEAGE as $id => $title) {
|
||||||
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>' : "";
|
$lastTitle = (TITLES_LINEAGE[array_key_last(TITLES_LINEAGE)] === $title);
|
||||||
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>" : "";
|
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";
|
||||||
?></li></ul>
|
}
|
||||||
|
echo str_repeat('</li></ul>', count(TITLES_LINEAGE));
|
||||||
|
?>
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
35
router.php
35
router.php
|
@ -19,29 +19,46 @@ if (strpos($pageAddress, "?") !== false) {
|
||||||
parse_str(substr($pageAddress, strpos($pageAddress, "?") + 1), $_GET);
|
parse_str(substr($pageAddress, strpos($pageAddress, "?") + 1), $_GET);
|
||||||
$pageAddress = substr($pageAddress, 0, strpos($pageAddress, "?"));
|
$pageAddress = substr($pageAddress, 0, strpos($pageAddress, "?"));
|
||||||
}
|
}
|
||||||
if (substr($pageAddress, -1) === '/' OR $pageAddress === '')
|
|
||||||
$pageAddress .= 'index';
|
define("PAGE_URL", $pageAddress);
|
||||||
define("PAGE_ADDRESS", $pageAddress);
|
define("PAGE_ADDRESS", $pageAddress . ((substr($pageAddress, -1) === '/' OR $pageAddress === '') ? 'index' : ''));
|
||||||
|
define("PAGE_LINEAGE", explode('/', PAGE_ADDRESS));
|
||||||
define("SERVICE", dirname(PAGE_ADDRESS));
|
define("SERVICE", dirname(PAGE_ADDRESS));
|
||||||
define("PAGE", basename(PAGE_ADDRESS, '.php'));
|
define("PAGE", basename(PAGE_ADDRESS, '.php'));
|
||||||
|
|
||||||
require "pages.php";
|
require "pages.php";
|
||||||
|
|
||||||
if (SERVICE !== '.') {
|
if (PAGE !== 'index') {
|
||||||
if (!isset(TITLES[SERVICE]['index'])) {
|
if (!isset(TITLES[SERVICE][PAGE])) {
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
exit('Page not found.');
|
exit('Page not found.');
|
||||||
}
|
}
|
||||||
$page['service'] = TITLES[SERVICE]['index'];
|
if (SERVICE !== '.') {
|
||||||
if (PAGE !== 'index') {
|
if (!isset(TITLES[SERVICE]['index'])) {
|
||||||
if (!isset(TITLES[SERVICE][PAGE])) {
|
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
exit('Page not found.');
|
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";
|
require "html.php";
|
||||||
|
|
||||||
function executePage() {
|
function executePage() {
|
||||||
|
|
Loading…
Reference in a new issue