fix router error for /index/nonexistent
This commit is contained in:
parent
7330f3a769
commit
2bdff41e80
1 changed files with 11 additions and 9 deletions
20
router.php
20
router.php
|
@ -11,18 +11,25 @@ define('PAGE_ADDRESS', $pageAddress . ((substr($pageAddress, -1) === '/' OR $pag
|
|||
define('PAGE_LINEAGE', explode('/', PAGE_ADDRESS));
|
||||
define('SERVICE', dirname(PAGE_ADDRESS));
|
||||
|
||||
function pageNotFound(): never {
|
||||
http_response_code(404);
|
||||
exit(_('Page not found.'));
|
||||
}
|
||||
function getPageInformations(array $pages, array $pageElements): array { // Recursively retrieves page metadata from pages.php
|
||||
if (!isset($pages['index']) OR $pageElements[0] === 'index')
|
||||
if (!isset($pages['index']) OR $pageElements[0] === 'index') {
|
||||
if (count($pageElements) !== 1)
|
||||
pageNotFound();
|
||||
return [
|
||||
'titles_lineage' => [$pages[$pageElements[0]]['title'] ?? false],
|
||||
'page_metadata' => $pages[$pageElements[0]] ?? NULL,
|
||||
'titles_lineage' => [$pages[$pageElements[0]]['title'] ?? pageNotFound()],
|
||||
'page_metadata' => $pages[$pageElements[0]],
|
||||
'terminal' => $pageElements[0] !== 'index'
|
||||
];
|
||||
}
|
||||
$result = $pages['index']['title'];
|
||||
if (!isset($pageElements[1]))
|
||||
unset($pages['index']);
|
||||
else
|
||||
$pages = $pages[array_shift($pageElements)] ?? false;
|
||||
$pages = $pages[array_shift($pageElements)] ?? [];
|
||||
$results = getPageInformations($pages, $pageElements);
|
||||
$results['titles_lineage'][] = $result;
|
||||
return $results;
|
||||
|
@ -32,11 +39,6 @@ define('TITLES_LINEAGE', array_reverse($pageInformations['titles_lineage']));
|
|||
define('PAGE_METADATA', $pageInformations['page_metadata']);
|
||||
define('PAGE_TERMINAL', $pageInformations['terminal']);
|
||||
|
||||
if (!TITLES_LINEAGE[array_key_last(TITLES_LINEAGE)]) {
|
||||
http_response_code(404);
|
||||
exit('Page not found.');
|
||||
}
|
||||
|
||||
if (isset($_SERVER['SERVER_NAME']) !== true)
|
||||
exit('Missing <code>$_SERVER[\'SERVER_NAME\']</code>');
|
||||
if (in_array($_SERVER['SERVER_NAME'], CONF['common']['public_domains'], true) !== true)
|
||||
|
|
Loading…
Reference in a new issue