From d22dad11db40b4286cc0003ca844dc3874a9051f Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Wed, 14 Feb 2018 04:08:45 +0100 Subject: Add configuration option "$ITEM.SINGLE_REDIRECT" Each option can be set to "TRUE" or "FALSE" (the default value is "FALSE"). For example, if you only have one user and "USER.SINGLE_REDIRECT" is set to "TRUE", then requests to "/user/" will be automatically redirected to "/user/username/". --- core/include/page/list.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'core/include/page') diff --git a/core/include/page/list.php b/core/include/page/list.php index f80c461..022478e 100644 --- a/core/include/page/list.php +++ b/core/include/page/list.php @@ -11,7 +11,8 @@ $Language = Application::getLanguage(); $site_size = Application::get('PAGE.LIST_SIZE'); $site_sort = Application::get('PAGE.LIST_SORT'); -$lastSite = ceil($Database->query(sprintf('SELECT COUNT(id) FROM %s', Page\Attribute::TABLE))->fetchColumn() / $site_size); +$count = $Database->query(sprintf('SELECT COUNT(id) FROM %s', Page\Attribute::TABLE))->fetchColumn(); +$lastSite = ceil($count / $site_size); $currentSite = HTTP::GET('site') ?? 1; $currentSite = intval($currentSite); @@ -20,6 +21,15 @@ if($currentSite < 1 OR ($currentSite > $lastSite AND $lastSite > 0)) { Application::error404(); } +#=============================================================================== +# Single redirect +#=============================================================================== +if(Application::get('PAGE.SINGLE_REDIRECT') === TRUE AND $count === '1') { + $Statement = $Database->query(sprintf('SELECT id FROM %s LIMIT 1', Page\Attribute::TABLE)); + $Page = Page\Factory::build($Statement->fetchColumn()); + HTTP::redirect($Page->getURL()); +} + #=============================================================================== # TRY: Template\Exception #=============================================================================== -- cgit v1.2.3