diff --git a/index.php b/index.php index 8b2fb8d9..8cd36247 100644 --- a/index.php +++ b/index.php @@ -167,7 +167,7 @@ else { } // handle ?fbclid=x, etc. (show news page) -if (!$found && count($_GET) > 0 && !isset($_REQUEST['subtopic']) && !isset($_REQUEST['p'])) { +if (!$found && count($_GET) > 0 && !isset($_REQUEST['subtopic']) && !isset($_REQUEST['p']) && !in_array($_SERVER['QUERY_STRING'], getDatabasePages())) { $_REQUEST['p'] = $_REQUEST['subtopic'] = 'news'; $found = true; } diff --git a/system/functions.php b/system/functions.php index 9107491b..bdb402f4 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1255,6 +1255,28 @@ function displayErrorBoxWithBackButton($errors, $action = null) { ]); } +function getDatabasePages($withHidden = false): array +{ + global $db, $logged_access; + + if (!isset($logged_access)) { + $logged_access = 1; + } + + $pages = $db->query('SELECT `name` FROM ' . TABLE_PREFIX . 'pages WHERE ' . ($withHidden ? '' : '`hidden` != 1 AND ') . '`access` <= ' . $db->quote($logged_access)); + $ret = []; + + if ($pages->rowCount() < 1) { + return $ret; + } + + foreach($pages->fetchAll() as $page) { + $ret[] = $page['name']; + } + + return $ret; +} + // validator functions require_once LIBS . 'validator.php'; require_once SYSTEM . 'compat/base.php';