aboutsummaryrefslogtreecommitdiffstats
path: root/index.php
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2017-03-10 21:46:12 +0100
committerThomas Lange <code@nerdmind.de>2017-03-10 21:46:12 +0100
commite33c245d910e55b8cab407a03e669470509a705d (patch)
treee958504564ab47e72e0d3dcfe0b967440007b1d9 /index.php
parentaae885b9784466ab412e4010893808867e93c213 (diff)
downloadblog-e33c245d910e55b8cab407a03e669470509a705d.tar.gz
blog-e33c245d910e55b8cab407a03e669470509a705d.tar.xz
blog-e33c245d910e55b8cab407a03e669470509a705d.zip
Several changes have been made in this commit, which together with the previous commits result in version 1.1:v1.1
+ The rules for the Apache and nginx configuration have been changed and redirects now all requests to the index.php. + A router class has been added which now handles all requests that arrives at the application on the index.php. + Short-hand functions "PAGE", "POST" and "USER" for use in templates added to get specific item data by ID. + More language variables have been added to the core language.
Diffstat (limited to 'index.php')
-rw-r--r--index.php105
1 files changed, 70 insertions, 35 deletions
diff --git a/index.php b/index.php
index b07fee6..936abe2 100644
--- a/index.php
+++ b/index.php
@@ -5,50 +5,85 @@
require_once 'core/application.php';
#===============================================================================
-# TRY: Template\Exception
+# Item base directory paths
#===============================================================================
-try {
- $execSQL = 'SELECT id FROM %s ORDER BY '.Application::get('POST.LIST_SORT').' LIMIT '.Application::get('POST.LIST_SIZE');
- $Statement = $Database->query(sprintf($execSQL, Post\Attribute::TABLE));
+$PAGEPATH = Application::get('PAGE.DIRECTORY');
+$POSTPATH = Application::get('POST.DIRECTORY');
+$USERPATH = Application::get('USER.DIRECTORY');
- $postIDs = $Statement->fetchAll($Database::FETCH_COLUMN);
+#===============================================================================
+# ROUTE: Item
+#===============================================================================
+Router::add("{$PAGEPATH}/([^/]+)/", function($param) { require 'system/page/main.php'; });
+Router::add("{$POSTPATH}/([^/]+)/", function($param) { require 'system/post/main.php'; });
+Router::add("{$USERPATH}/([^/]+)/", function($param) { require 'system/user/main.php'; });
+
+#===============================================================================
+# ROUTE: Item overview
+#===============================================================================
+Router::add("{$PAGEPATH}/", function() { require 'system/page/list.php'; });
+Router::add("{$POSTPATH}/", function() { require 'system/post/list.php'; });
+Router::add("{$USERPATH}/", function() { require 'system/user/list.php'; });
+
+#===============================================================================
+# REDIRECT: Item (trailing slash)
+#===============================================================================
+Router::addRedirect("{$PAGEPATH}/([^/]+)", Application::getPageURL('$1/'));
+Router::addRedirect("{$POSTPATH}/([^/]+)", Application::getPostURL('$1/'));
+Router::addRedirect("{$USERPATH}/([^/]+)", Application::getUserURL('$1/'));
+
+#===============================================================================
+# REDIRECT: Item overview (trailing slash)
+#===============================================================================
+Router::addRedirect("{$PAGEPATH}", Application::getPageURL());
+Router::addRedirect("{$POSTPATH}", Application::getPostURL());
+Router::addRedirect("{$USERPATH}", Application::getUserURL());
+
+#===============================================================================
+# ROUTE: Home
+#===============================================================================
+Router::add('', function() {
+ require 'system/home.php';
+});
- foreach($postIDs as $postID) {
- try {
- $Post = Post\Factory::build($postID);
- $User = User\Factory::build($Post->attr('user'));
+#===============================================================================
+# ROUTE: Feed
+#===============================================================================
+Router::add('feed/', function() {
+ require 'system/feed/main.php';
+});
- $ItemTemplate = generatePostItemTemplate($Post, $User);
+#===============================================================================
+# ROUTE: Feed [item type only]
+#===============================================================================
+Router::add('feed/(page|post)/', function($param) {
+ require 'system/feed/main.php';
+});
- $posts[] = $ItemTemplate;
- }
- catch(Post\Exception $Exception){}
- catch(User\Exception $Exception){}
- }
+#===============================================================================
+# ROUTE: Search
+#===============================================================================
+Router::add('search/', function() {
+ require 'system/search/main.php';
+});
- $HomeTemplate = Template\Factory::build('home');
- $HomeTemplate->set('PAGINATION', [
- 'HTML' => generatePostNaviTemplate(1)
- ]);
- $HomeTemplate->set('LIST', [
- 'POSTS' => $posts ?? []
- ]);
+#===============================================================================
+# REDIRECT: Feed (trailing slash)
+#===============================================================================
+Router::addRedirect('feed', Application::getURL('feed/'));
- $MainTemplate = Template\Factory::build('main');
- $MainTemplate->set('HTML', $HomeTemplate);
- $MainTemplate->set('HEAD', [
- 'NAME' => Application::get('BLOGMETA.HOME'),
- 'DESC' => Application::get('BLOGMETA.NAME').' – '.Application::get('BLOGMETA.DESC'),
- 'PERM' => Application::getURL()
- ]);
+#===============================================================================
+# REDIRECT: Feed [posts or pages] (trailing slash)
+#===============================================================================
+Router::addRedirect('feed/(page|post)', Application::getURL('feed/$1/'));
- echo $MainTemplate;
-}
+#===============================================================================
+# REDIRECT: Search (trailing slash)
+#===============================================================================
+Router::addRedirect('search', Application::getURL('search/'));
#===============================================================================
-# CATCH: Template\Exception
+# Execute router and route requests
#===============================================================================
-catch(Template\Exception $Exception) {
- $Exception->defaultHandler();
-}
+Router::execute(parse_url(HTTP::requestURI(), PHP_URL_PATH));
?> \ No newline at end of file