diff --git a/router.php b/router.php index fd23782..a53ef96 100644 --- a/router.php +++ b/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 $_SERVER[\'SERVER_NAME\']'); if (in_array($_SERVER['SERVER_NAME'], CONF['common']['public_domains'], true) !== true)