summaryrefslogtreecommitdiffstats
path: root/core/include/post
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2018-02-14 04:08:45 +0100
committerThomas Lange <code@nerdmind.de>2018-02-14 14:23:20 +0100
commitd22dad11db40b4286cc0003ca844dc3874a9051f (patch)
tree46f1dfce9c43fae1d326a10d0bd1e80ab87ee7f6 /core/include/post
parent3224f6e8da7b6dc000856226f381012d778e2eca (diff)
downloadblog-d22dad11db40b4286cc0003ca844dc3874a9051f.tar.gz
blog-d22dad11db40b4286cc0003ca844dc3874a9051f.tar.xz
blog-d22dad11db40b4286cc0003ca844dc3874a9051f.zip
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/".
Diffstat (limited to 'core/include/post')
-rw-r--r--core/include/post/list.php12
1 files changed, 11 insertions, 1 deletions
diff --git a/core/include/post/list.php b/core/include/post/list.php
index 4b8ea28..3ba2dba 100644
--- a/core/include/post/list.php
+++ b/core/include/post/list.php
@@ -11,7 +11,8 @@ $Language = Application::getLanguage();
$site_size = Application::get('POST.LIST_SIZE');
$site_sort = Application::get('POST.LIST_SORT');
-$lastSite = ceil($Database->query(sprintf('SELECT COUNT(id) FROM %s', Post\Attribute::TABLE))->fetchColumn() / $site_size);
+$count = $Database->query(sprintf('SELECT COUNT(id) FROM %s', Post\Attribute::TABLE))->fetchColumn();
+$lastSite = ceil($count / $site_size);
$currentSite = HTTP::GET('site') ?? 1;
$currentSite = intval($currentSite);
@@ -21,6 +22,15 @@ if($currentSite < 1 OR ($currentSite > $lastSite AND $lastSite > 0)) {
}
#===============================================================================
+# Single redirect
+#===============================================================================
+if(Application::get('POST.SINGLE_REDIRECT') === TRUE AND $count === '1') {
+ $Statement = $Database->query(sprintf('SELECT id FROM %s LIMIT 1', Post\Attribute::TABLE));
+ $Post = Post\Factory::build($Statement->fetchColumn());
+ HTTP::redirect($Post->getURL());
+}
+
+#===============================================================================
# TRY: Template\Exception
#===============================================================================
try {