Use getTitlesLineage() to check if page exists

This commit is contained in:
Miraty 2022-09-09 22:15:52 +02:00
parent 9775de3a40
commit bd37c14ef9

View file

@ -28,33 +28,25 @@ define("PAGE", basename(PAGE_ADDRESS, '.php'));
require "pages.php";
if (PAGE !== 'index') {
if (!isset(TITLES[SERVICE][PAGE])) {
http_response_code(404);
exit('Page not found.');
}
if (SERVICE !== '.') {
if (!isset(TITLES[SERVICE]['index'])) {
http_response_code(404);
exit('Page not found.');
}
}
}
function getTitlesLineage($titles, $pageElements) {
if (!isset($titles['index']) OR $pageElements[0] === 'index')
return [$titles[$pageElements[0]]];
return [$titles[$pageElements[0]] ?? false];
$result = $titles['index'];
if (!isset($pageElements[1]))
unset($titles['index']);
else
$titles = $titles[array_shift($pageElements)];
$titles = $titles[array_shift($pageElements)] ?? false;
$results = getTitlesLineage($titles, $pageElements);
$results[] = $result;
return $results;
}
define('TITLES_LINEAGE', array_reverse(getTitlesLineage(TITLES, PAGE_LINEAGE)));
if (!TITLES_LINEAGE[array_key_last(TITLES_LINEAGE)]) {
http_response_code(404);
exit('Page not found.');
}
if (
isset($_COOKIE['niver-session-key']) // Resume session
OR