Recursive function getTitlesLineage()
This commit is contained in:
parent
173f7b15d3
commit
21e20c9008
1 changed files with 12 additions and 16 deletions
28
router.php
28
router.php
|
@ -41,23 +41,19 @@ if (PAGE !== 'index') {
|
|||
}
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
}
|
||||
function getTitlesLineage($titles, $pageElements) {
|
||||
if (!isset($titles['index']) OR $pageElements[0] === 'index')
|
||||
return [$titles[$pageElements[0]]];
|
||||
$result = $titles['index'];
|
||||
if (!isset($pageElements[1]))
|
||||
unset($titles['index']);
|
||||
else
|
||||
$titles = $titles[array_shift($pageElements)];
|
||||
$results = getTitlesLineage($titles, $pageElements);
|
||||
$results[] = $result;
|
||||
return $results;
|
||||
}
|
||||
define('TITLES_LINEAGE', array_reverse($results));
|
||||
define('TITLES_LINEAGE', array_reverse(getTitlesLineage(TITLES, PAGE_LINEAGE)));
|
||||
|
||||
require "html.php";
|
||||
|
||||
|
|
Loading…
Reference in a new issue