aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--.ht-nginx25
-rw-r--r--.htaccess15
-rw-r--r--core/application.php2
-rw-r--r--core/configuration-example.php52
-rw-r--r--core/functions.php42
-rw-r--r--core/language/de.php7
-rw-r--r--core/language/en.php7
-rw-r--r--core/namespace/Router.php64
-rw-r--r--index.php105
-rw-r--r--system/feed/main.php11
-rw-r--r--system/home.php55
-rw-r--r--system/page/list.php5
-rw-r--r--system/page/main.php13
-rw-r--r--system/post/list.php5
-rw-r--r--system/post/main.php13
-rw-r--r--system/search/main.php6
-rw-r--r--system/user/list.php5
-rw-r--r--system/user/main.php13
-rw-r--r--template/standard/html/feed/main.php10
-rw-r--r--template/standard/html/main.php32
-rw-r--r--template/standard/lang/de.php6
-rw-r--r--template/standard/lang/en.php6
22 files changed, 348 insertions, 151 deletions
diff --git a/.ht-nginx b/.ht-nginx
index 814bea9..9d3053f 100644
--- a/.ht-nginx
+++ b/.ht-nginx
@@ -4,7 +4,8 @@
# #
# This file contains the configuration from the Apaches .htaccess file written #
# for the nginx high performance web server. Put the content of this file into #
-# the "server {}" block of your nginx virtual host configuration file. #
+# the "server {}" block of your nginx virtual host configuration file. If your #
+# blog installation is within a sub directory, you need to adjust this values! #
# #
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
@@ -17,21 +18,13 @@ error_page 404 /system/404.php;
#===============================================================================
# Forbidden directories
#===============================================================================
-location ~ ^/core|template/(.*)/(html|lang)/ {
- return 403;
+location ~ ^/(core|template/([^/]+)/(html|lang)/) {
+ return 403;
}
-#===========================================================================
+#===============================================================================
# Main rules
-#===========================================================================
-rewrite ^/(page|post|user)/([^/]+)/$ /system/$1/main.php?param=$2 break;
-rewrite ^/(page|post|user)/$ /system/$1/list.php break;
-rewrite ^/feed/(page|post)/$ /system/feed/main.php?item=$1 break;
-rewrite ^/(feed|search)/$ /system/$1/main.php break;
-
-#===========================================================================
-# Trailing slashes
-#===========================================================================
-rewrite ^/(page|post|user)/([^/]+)$ /$1/$2/ redirect;
-rewrite ^/(page|post|user|feed|search)$ /$1/ redirect;
-rewrite ^/feed/(post|page)$ /feed/$1/ redirect; \ No newline at end of file
+#===============================================================================
+if (!-e $request_filename) {
+ rewrite ^(.*)$ /index.php break;
+} \ No newline at end of file
diff --git a/.htaccess b/.htaccess
index af8639d..2a87ccc 100644
--- a/.htaccess
+++ b/.htaccess
@@ -23,19 +23,12 @@ ErrorDocument 404 /system/404.php
#===============================================================================
# Forbidden directories
#===============================================================================
-RewriteRule ^core|template/(.*)/(html|lang)/ - [F]
+RewriteRule ^(core|template/([^/]+)/(html|lang)/) - [F]
#===============================================================================
# Main rules
#===============================================================================
-RewriteRule ^(page|post|user)/([^/]+)/$ system/$1/main.php?param=$2 [L]
-RewriteRule ^(page|post|user)/$ system/$1/list.php [L]
-RewriteRule ^feed/(page|post)/$ system/feed/main.php?item=$1 [L]
-RewriteRule ^(feed|search)/$ system/$1/main.php [L]
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
-#===============================================================================
-# Trailing slashes
-#===============================================================================
-RewriteRule ^(page|post|user)/([^/]+)$ %{REQUEST_URI}/ [R,L]
-RewriteRule ^(page|post|user|feed|search)$ %{REQUEST_URI}/ [R,L]
-RewriteRule ^feed/(post|page)$ %{REQUEST_URI}/ [R,L] \ No newline at end of file
+RewriteRule ^(.*)$ index.php [L] \ No newline at end of file
diff --git a/core/application.php b/core/application.php
index 58dd728..11f5b83 100644
--- a/core/application.php
+++ b/core/application.php
@@ -3,7 +3,7 @@
# Application initialization [Thomas Lange <code@nerdmind.de>] #
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
# #
-# This file is included by each file from the system or admin directory. #
+# This file brings the application up! #
# #
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
diff --git a/core/configuration-example.php b/core/configuration-example.php
index 1416621..d56ce84 100644
--- a/core/configuration-example.php
+++ b/core/configuration-example.php
@@ -23,7 +23,7 @@ Application::set('BLOGMETA.MAIL', 'mail@example.org');
Application::set('BLOGMETA.LANG', 'en');
#===============================================================================
-# Settings for database connection
+# Database configuration
#===============================================================================
Application::set('DATABASE.HOSTNAME', 'localhost');
Application::set('DATABASE.BASENAME', 'blog');
@@ -31,33 +31,47 @@ Application::set('DATABASE.USERNAME', '');
Application::set('DATABASE.PASSWORD', '');
#===============================================================================
-# Backend configuration
+# Template configuration
#===============================================================================
-Application::set('ADMIN.TEMPLATE', 'admin');
-Application::set('ADMIN.LANGUAGE', Application::get('CORE.LANGUAGE'));
+Application::set('TEMPLATE.NAME', 'standard');
+Application::set('TEMPLATE.LANG', Application::get('CORE.LANGUAGE'));
#===============================================================================
-# Settings for template configuration
+# Backend configuration
#===============================================================================
-Application::set('TEMPLATE.NAME', 'standard');
-Application::set('TEMPLATE.LANG', Application::get('CORE.LANGUAGE'));
+Application::set('ADMIN.TEMPLATE', 'admin');
+Application::set('ADMIN.LANGUAGE', Application::get('CORE.LANGUAGE'));
#===============================================================================
-# Protocol, hostname and path for this installation
+# Protocol, hostname and base directory for this installation
#===============================================================================
Application::set('PATHINFO.PROT', $_SERVER['REQUEST_SCHEME']);
Application::set('PATHINFO.HOST', $_SERVER['HTTP_HOST']);
Application::set('PATHINFO.BASE', '');
#===============================================================================
-# Enable or disable the use of slug URLs for item permalinks
+# Item base directories
+#===============================================================================
+Application::set('PAGE.DIRECTORY', 'page');
+Application::set('POST.DIRECTORY', 'post');
+Application::set('USER.DIRECTORY', 'user');
+
+#===============================================================================
+# Use slug URLs for item permalinks
#===============================================================================
Application::set('PAGE.SLUG_URLS', TRUE);
Application::set('POST.SLUG_URLS', TRUE);
Application::set('USER.SLUG_URLS', TRUE);
#===============================================================================
-# Number of items to display on feed and overview sites
+# Parse emoticons in items content
+#===============================================================================
+Application::set('PAGE.EMOTICONS', TRUE);
+Application::set('POST.EMOTICONS', TRUE);
+Application::set('USER.EMOTICONS', TRUE);
+
+#===============================================================================
+# Number of items to show on feed and item overview
#===============================================================================
Application::set('PAGE.LIST_SIZE', 10);
Application::set('POST.LIST_SIZE', 10);
@@ -66,28 +80,14 @@ Application::set('PAGE.FEED_SIZE', 25);
Application::set('POST.FEED_SIZE', 25);
#===============================================================================
-# Settings for item URL generation (you have to change the .htaccess as well!)
-#===============================================================================
-Application::set('PAGE.DIRECTORY', 'page');
-Application::set('POST.DIRECTORY', 'post');
-Application::set('USER.DIRECTORY', 'user');
-
-#===============================================================================
-# Enable or disable the use of emoticons for item content
-#===============================================================================
-Application::set('PAGE.EMOTICONS', TRUE);
-Application::set('POST.EMOTICONS', TRUE);
-Application::set('USER.EMOTICONS', TRUE);
-
-#===============================================================================
-# Number of characters to display in the items <meta> description
+# Number of characters to show in the items <meta> description
#===============================================================================
Application::set('PAGE.DESCRIPTION_SIZE', 200);
Application::set('POST.DESCRIPTION_SIZE', 200);
Application::set('USER.DESCRIPTION_SIZE', 200);
#===============================================================================
-# "ORDER BY" clause for item sorting on feed and overview sites
+# "ORDER BY" clause for item sorting on feed and item overview
#===============================================================================
Application::set('PAGE.LIST_SORT', 'time_insert DESC');
Application::set('POST.LIST_SORT', 'time_insert DESC');
diff --git a/core/functions.php b/core/functions.php
index 726e96f..471c14f 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -308,9 +308,9 @@ function excerpt($string, $length = 500, $replace = ' […]') {
return $string;
}
-#====================================================================================================
+#===============================================================================
# Generate a valid slug URL part from a string
-#====================================================================================================
+#===============================================================================
function makeSlugURL($string) {
$string = strtolower($string);
$string = str_replace(['ä', 'ö', 'ü', 'ß'], ['ae', 'oe', 'ue', 'ss'], $string);
@@ -319,4 +319,40 @@ function makeSlugURL($string) {
return trim($string, '-');
}
-?>
+
+#===============================================================================
+# Function to get data from specific page in templates
+#===============================================================================
+function PAGE($id) {
+ try {
+ $Page = Page\Factory::build($id);
+ return generatePageItemData($Page);
+ } catch(Page\Exception $Exception) {
+ return NULL;
+ }
+}
+
+#===============================================================================
+# Function to get data from specific post in templates
+#===============================================================================
+function POST($id) {
+ try {
+ $Post = Post\Factory::build($id);
+ return generatePostItemData($Post);
+ } catch(Post\Exception $Exception) {
+ return NULL;
+ }
+}
+
+#===============================================================================
+# Function to get data from specific user in templates
+#===============================================================================
+function USER($id) {
+ try {
+ $User = User\Factory::build($id);
+ return generateUserItemData($User);
+ } catch(User\Exception $Exception) {
+ return NULL;
+ }
+}
+?> \ No newline at end of file
diff --git a/core/language/de.php b/core/language/de.php
index dc6e924..c310719 100644
--- a/core/language/de.php
+++ b/core/language/de.php
@@ -191,4 +191,11 @@ $LANGUAGE['title_user_overview'] = "{$LANGUAGE['user_overview']} [%d]";
#===============================================================================
$LANGUAGE['title_search_request'] = 'Volltextsuche';
$LANGUAGE['title_search_results'] = 'Ergebnisse für "%s"';
+
+#===============================================================================
+# Feed names
+#===============================================================================
+$LANGUAGE['feed_name_items'] = '%s [alle Inhalte]';
+$LANGUAGE['feed_name_pages'] = '%s [nur Seiten]';
+$LANGUAGE['feed_name_posts'] = '%s [nur Beiträge]';
?> \ No newline at end of file
diff --git a/core/language/en.php b/core/language/en.php
index 3e48191..55c0ce3 100644
--- a/core/language/en.php
+++ b/core/language/en.php
@@ -191,4 +191,11 @@ $LANGUAGE['title_user_overview'] = "{$LANGUAGE['user_overview']} [%d]";
#===============================================================================
$LANGUAGE['title_search_request'] = 'Fulltext search';
$LANGUAGE['title_search_results'] = 'Results for "%s"';
+
+#===============================================================================
+# Feed names
+#===============================================================================
+$LANGUAGE['feed_name_items'] = '%s [all content]';
+$LANGUAGE['feed_name_pages'] = '%s [only pages]';
+$LANGUAGE['feed_name_posts'] = '%s [only posts]';
?> \ No newline at end of file
diff --git a/core/namespace/Router.php b/core/namespace/Router.php
new file mode 100644
index 0000000..22784c2
--- /dev/null
+++ b/core/namespace/Router.php
@@ -0,0 +1,64 @@
+<?php
+class Router {
+ private static $routes = [];
+
+ #===============================================================================
+ # Add route
+ #===============================================================================
+ public static function add($pattern, callable $callback) {
+ $pattern = Application::get('PATHINFO.BASE').$pattern;
+
+ return self::$routes[] = [
+ 'type' => 'route',
+ 'pattern' => $pattern,
+ 'callback' => $callback
+ ];
+ }
+
+ #===============================================================================
+ # Add redirect
+ #===============================================================================
+ public static function addRedirect($pattern, $location, $code = 302) {
+ $pattern = Application::get('PATHINFO.BASE').$pattern;
+
+ return self::$routes[] = [
+ 'type' => 'redirect',
+ 'code' => $code,
+ 'pattern' => $pattern,
+ 'location' => $location
+ ];
+ }
+
+ #===============================================================================
+ # Execute routing
+ #===============================================================================
+ public static function execute($path) {
+ $path = ltrim($path, '/');
+ $route_found = FALSE;
+
+ foreach(self::$routes as $route) {
+ if($route['type'] === 'redirect') {
+ $location = preg_replace("#^{$route['pattern']}$#", $route['location'], $path, -1, $count);
+
+ if($count) {
+ HTTP::redirect($location, $route['code']);
+ }
+ }
+
+ else {
+ if(preg_match("#^{$route['pattern']}$#", $path, $matches)) {
+ # Remove the first element from matches which contains the whole string.
+ array_shift($matches);
+
+ $route_found = TRUE;
+ call_user_func_array($route['callback'], $matches);
+ }
+ }
+ }
+
+ if($route_found === FALSE) {
+ require_once 'system/404.php';
+ }
+ }
+}
+?> \ No newline at end of file
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
diff --git a/system/feed/main.php b/system/feed/main.php
index 00ac4b8..ffb9b3a 100644
--- a/system/feed/main.php
+++ b/system/feed/main.php
@@ -1,8 +1,9 @@
<?php
#===============================================================================
-# INCLUDE: Main configuration
+# Get instances
#===============================================================================
-require_once '../../core/application.php';
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
#===============================================================================
# HEADER: Content-Type for XML document
@@ -13,7 +14,7 @@ HTTP::responseHeader(HTTP::HEADER_CONTENT_TYPE, HTTP::CONTENT_TYPE_XML);
# TRY: Template\Exception
#===============================================================================
try {
- if(HTTP::GET('item') !== 'page') {
+ if(!isset($param) OR $param !== 'page') {
$execSQL = 'SELECT id FROM %s ORDER BY '.Application::get('POST.FEED_SORT').' LIMIT '.Application::get('POST.FEED_SIZE');
$postIDs = $Database->query(sprintf($execSQL, Post\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN);
@@ -34,7 +35,7 @@ try {
}
}
- if(HTTP::GET('item') !== 'post') {
+ if(!isset($param) OR $param !== 'post') {
$execSQL = 'SELECT id FROM %s ORDER BY '.Application::get('PAGE.FEED_SORT').' LIMIT '.Application::get('PAGE.FEED_SIZE');
$pageIDs = $Database->query(sprintf($execSQL, Page\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN);
@@ -57,7 +58,7 @@ try {
$FeedTemplate = Template\Factory::build('feed/main');
$FeedTemplate->set('FEED', [
- 'TYPE' => HTTP::GET('item'),
+ 'TYPE' => $param ?? NULL,
'LIST' => [
'POSTS' => $posts ?? [],
'PAGES' => $pages ?? [],
diff --git a/system/home.php b/system/home.php
new file mode 100644
index 0000000..3d20097
--- /dev/null
+++ b/system/home.php
@@ -0,0 +1,55 @@
+<?php
+#===============================================================================
+# Get instances
+#===============================================================================
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
+
+#===============================================================================
+# TRY: Template\Exception
+#===============================================================================
+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));
+
+ $postIDs = $Statement->fetchAll($Database::FETCH_COLUMN);
+
+ foreach($postIDs as $postID) {
+ try {
+ $Post = Post\Factory::build($postID);
+ $User = User\Factory::build($Post->attr('user'));
+
+ $ItemTemplate = generatePostItemTemplate($Post, $User);
+
+ $posts[] = $ItemTemplate;
+ }
+ catch(Post\Exception $Exception){}
+ catch(User\Exception $Exception){}
+ }
+
+ $HomeTemplate = Template\Factory::build('home');
+ $HomeTemplate->set('PAGINATION', [
+ 'HTML' => generatePostNaviTemplate(1)
+ ]);
+ $HomeTemplate->set('LIST', [
+ 'POSTS' => $posts ?? []
+ ]);
+
+ $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()
+ ]);
+
+ echo $MainTemplate;
+}
+
+#===============================================================================
+# CATCH: Template\Exception
+#===============================================================================
+catch(Template\Exception $Exception) {
+ $Exception->defaultHandler();
+}
+?> \ No newline at end of file
diff --git a/system/page/list.php b/system/page/list.php
index 5d07d30..7c3956e 100644
--- a/system/page/list.php
+++ b/system/page/list.php
@@ -1,8 +1,9 @@
<?php
#===============================================================================
-# INCLUDE: Main configuration
+# Get instances
#===============================================================================
-require_once '../../core/application.php';
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
$site_size = Application::get('PAGE.LIST_SIZE');
$site_sort = Application::get('PAGE.LIST_SORT');
diff --git a/system/page/main.php b/system/page/main.php
index cf723d2..88652fd 100644
--- a/system/page/main.php
+++ b/system/page/main.php
@@ -1,19 +1,20 @@
<?php
#===============================================================================
-# INCLUDE: Main configuration
+# Get instances
#===============================================================================
-require_once '../../core/application.php';
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
#===============================================================================
# TRY: Page\Exception, User\Exception
#===============================================================================
try {
if(Application::get('PAGE.SLUG_URLS')) {
- $Page = Page\Factory::buildBySlug(HTTP::GET('param'));
+ $Page = Page\Factory::buildBySlug($param);
}
else {
- $Page = Page\Factory::build(HTTP::GET('param'));
+ $Page = Page\Factory::build($param);
}
$User = User\Factory::build($Page->attr('user'));
@@ -68,9 +69,9 @@ try {
catch(Page\Exception $Exception) {
try {
if(Application::get('PAGE.SLUG_URLS') === FALSE) {
- $Page = Page\Factory::buildBySlug(HTTP::GET('param'));
+ $Page = Page\Factory::buildBySlug($param);
} else {
- $Page = Page\Factory::build(HTTP::GET('param'));
+ $Page = Page\Factory::build($param);
}
HTTP::redirect($Page->getURL());
diff --git a/system/post/list.php b/system/post/list.php
index a7d6ce7..7b0630c 100644
--- a/system/post/list.php
+++ b/system/post/list.php
@@ -1,8 +1,9 @@
<?php
#===============================================================================
-# INCLUDE: Main configuration
+# Get instances
#===============================================================================
-require_once '../../core/application.php';
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
$site_size = Application::get('POST.LIST_SIZE');
$site_sort = Application::get('POST.LIST_SORT');
diff --git a/system/post/main.php b/system/post/main.php
index b880bb7..8411d9a 100644
--- a/system/post/main.php
+++ b/system/post/main.php
@@ -1,19 +1,20 @@
<?php
#===============================================================================
-# INCLUDE: Main configuration
+# Get instances
#===============================================================================
-require_once '../../core/application.php';
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
#===============================================================================
# TRY: Post\Exception, User\Exception
#===============================================================================
try {
if(Application::get('POST.SLUG_URLS')) {
- $Post = Post\Factory::buildBySlug(HTTP::GET('param'));
+ $Post = Post\Factory::buildBySlug($param);
}
else {
- $Post = Post\Factory::build(HTTP::GET('param'));
+ $Post = Post\Factory::build($param);
}
$User = User\Factory::build($Post->attr('user'));
@@ -68,9 +69,9 @@ try {
catch(Post\Exception $Exception) {
try {
if(Application::get('POST.SLUG_URLS') === FALSE) {
- $Post = Post\Factory::buildBySlug(HTTP::GET('param'));
+ $Post = Post\Factory::buildBySlug($param);
} else {
- $Post = Post\Factory::build(HTTP::GET('param'));
+ $Post = Post\Factory::build($param);
}
HTTP::redirect($Post->getURL());
diff --git a/system/search/main.php b/system/search/main.php
index fe18e7e..97fe8bb 100644
--- a/system/search/main.php
+++ b/system/search/main.php
@@ -1,8 +1,10 @@
<?php
#===============================================================================
-# INCLUDE: Main configuration
+# Get instances
#===============================================================================
-require_once '../../core/application.php';
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
+
$SEARCH_SUCCESS = FALSE;
$D_LIST = $Database->query(sprintf('SELECT DISTINCT DAY(time_insert) AS temp FROM %s ORDER BY temp', Post\Attribute::TABLE));
$M_LIST = $Database->query(sprintf('SELECT DISTINCT MONTH(time_insert) AS temp FROM %s ORDER BY temp', Post\Attribute::TABLE));
diff --git a/system/user/list.php b/system/user/list.php
index 1f29473..b724fe8 100644
--- a/system/user/list.php
+++ b/system/user/list.php
@@ -1,8 +1,9 @@
<?php
#===============================================================================
-# INCLUDE: Main configuration
+# Get instances
#===============================================================================
-require_once '../../core/application.php';
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
$site_size = Application::get('USER.LIST_SIZE');
$site_sort = Application::get('USER.LIST_SORT');
diff --git a/system/user/main.php b/system/user/main.php
index 79f4222..7dcd6da 100644
--- a/system/user/main.php
+++ b/system/user/main.php
@@ -1,19 +1,20 @@
<?php
#===============================================================================
-# INCLUDE: Main configuration
+# Get instances
#===============================================================================
-require_once '../../core/application.php';
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
#===============================================================================
# TRY: User\Exception
#===============================================================================
try {
if(Application::get('USER.SLUG_URLS')) {
- $User = User\Factory::buildBySlug(HTTP::GET('param'));
+ $User = User\Factory::buildBySlug($param);
}
else {
- $User = User\Factory::build(HTTP::GET('param'));
+ $User = User\Factory::build($param);
}
$user_data = generateUserItemData($User);
@@ -83,9 +84,9 @@ try {
catch(User\Exception $Exception) {
try {
if(Application::get('USER.SLUG_URLS') === FALSE) {
- $User = User\Factory::buildBySlug(HTTP::GET('param'));
+ $User = User\Factory::buildBySlug($param);
} else {
- $User = User\Factory::build(HTTP::GET('param'));
+ $User = User\Factory::build($param);
}
HTTP::redirect($User->getURL());
diff --git a/template/standard/html/feed/main.php b/template/standard/html/feed/main.php
index 174a841..c8dcc3c 100644
--- a/template/standard/html/feed/main.php
+++ b/template/standard/html/feed/main.php
@@ -7,17 +7,19 @@
# #
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+$BLOGMETA_NAME = escapeHTML($BLOGMETA['NAME']);
+
switch($FEED['TYPE']) {
case 'post':
- $title = escapeHTML($BLOGMETA['NAME']).' ['.$Language->template('feed_only_posts').']';
+ $title = $Language->text('feed_name_posts', $BLOGMETA_NAME);
$self = Application::getURL('feed/post/');
break;
case 'page':
- $title = escapeHTML($BLOGMETA['NAME']).' ['.$Language->template('feed_only_pages').']';
+ $title = $Language->text('feed_name_pages', $BLOGMETA_NAME);
$self = Application::getURL('feed/page/');
break;
default:
- $title = escapeHTML($BLOGMETA['NAME']);
+ $title = $Language->text('feed_name_items', $BLOGMETA_NAME);
$self = Application::getURL('feed/');
}
?>
@@ -32,7 +34,7 @@ switch($FEED['TYPE']) {
<atom:link href="<?=$self?>" rel="self" type="application/rss+xml" />
<image>
- <title><?=escapeHTML($BLOGMETA['NAME'])?></title>
+ <title><?=$BLOGMETA_NAME?></title>
<url><?=Application::getTemplateURL('rsrc/logo.png')?></url>
<link><?=$self?></link>
</image>
diff --git a/template/standard/html/main.php b/template/standard/html/main.php
index 19d3b29..e6c0e10 100644
--- a/template/standard/html/main.php
+++ b/template/standard/html/main.php
@@ -6,6 +6,14 @@
# [see documentation] #
# #
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+
+#===============================================================================
+# Escape parameters which are used several times here to reduce escapeHTML calls
+#===============================================================================
+$HEAD_NAME = isset($HEAD['NAME']) ? escapeHTML($HEAD['NAME']) : NULL;
+$HEAD_DESC = isset($HEAD['DESC']) ? escapeHTML($HEAD['DESC']) : NULL;
+$BLOGMETA_NAME = escapeHTML($BLOGMETA['NAME']);
+$BLOGMETA_DESC = escapeHTML($BLOGMETA['DESC']);
?>
<!DOCTYPE html>
<html lang="<?=$BLOGMETA['LANG']?>">
@@ -14,16 +22,16 @@
<meta name="referrer" content="origin-when-crossorigin" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
-<?php if(isset($HEAD['DESC'])): ?>
- <meta name="description" content="<?=escapeHTML($HEAD['DESC'])?>" />
+<?php if(isset($HEAD_DESC)): ?>
+ <meta name="description" content="<?=$HEAD_DESC?>" />
<?php endif; ?>
<?php if(isset($HEAD['PERM'])): ?>
<link rel="canonical" href="<?=$HEAD['PERM']?>" />
<?php endif; ?>
- <meta property="og:site_name" content="<?=escapeHTML($BLOGMETA['NAME'])?>" />
- <meta property="og:title" content="<?=escapeHTML($HEAD['NAME'])?>" />
+ <meta property="og:site_name" content="<?=$BLOGMETA_NAME?>" />
+ <meta property="og:title" content="<?=$HEAD_NAME?>" />
<meta property="og:image" content="<?=Application::getTemplateURL('rsrc/logo.png')?>" />
<?php if(isset($HEAD['OG_IMAGES'])): ?>
@@ -35,18 +43,18 @@
<link rel="icon" href="<?=Application::getURL('favicon.ico')?>" />
<link rel="stylesheet" href="<?=Application::getTemplateURL('rsrc/main.css')?>" />
- <link rel="alternate" type="application/rss+xml" href="<?=Application::getURL('feed/')?>" title="<?=escapeHTML($BLOGMETA['NAME'])?>" />
- <link rel="alternate" type="application/rss+xml" href="<?=Application::getURL('feed/post/')?>" title="<?=escapeHTML($BLOGMETA['NAME'])?> [<?=$Language->template('feed_only_posts')?>]" />
- <link rel="alternate" type="application/rss+xml" href="<?=Application::getURL('feed/page/')?>" title="<?=escapeHTML($BLOGMETA['NAME'])?> [<?=$Language->template('feed_only_pages')?>]" />
+ <link rel="alternate" type="application/rss+xml" title="<?=$Language->text('feed_name_items', $BLOGMETA_NAME)?>" href="<?=Application::getURL('feed/')?>" />
+ <link rel="alternate" type="application/rss+xml" title="<?=$Language->text('feed_name_posts', $BLOGMETA_NAME)?>" href="<?=Application::getURL('feed/post/')?>" />
+ <link rel="alternate" type="application/rss+xml" title="<?=$Language->text('feed_name_pages', $BLOGMETA_NAME)?>" href="<?=Application::getURL('feed/page/')?>" />
- <title><?=escapeHTML("{$HEAD['NAME']} | {$BLOGMETA['NAME']} {$BLOGMETA['DESC']}")?></title>
+ <title><?="{$HEAD_NAME} | {$BLOGMETA_NAME} {$BLOGMETA_DESC}"?></title>
</head>
<body>
<section id="container">
<header id="main-header">
<section>
- <a href="<?=Application::getURL()?>" title="<?=escapeHTML("{$BLOGMETA['NAME']} {$BLOGMETA['DESC']}")?>">
- <img id="main-logo" src="<?=Application::getTemplateURL('rsrc/logo.png')?>" alt="<?=escapeHTML($BLOGMETA['NAME'])?>" />
+ <a href="<?=Application::getURL()?>" title="<?="{$BLOGMETA_NAME} {$BLOGMETA_DESC}"?>">
+ <img id="main-logo" src="<?=Application::getTemplateURL('rsrc/logo.png')?>" alt="<?=$BLOGMETA_NAME?>" />
</a>
</section>
<nav id="main-navi">
@@ -54,7 +62,7 @@
<input type="checkbox" id="toogle-nav" />
<ul>
<li>
- <a href="<?=Application::getURL()?>" title="<?=$Language->template('navigation_home_desc', escapeHTML($BLOGMETA['NAME']))?>">
+ <a href="<?=Application::getURL()?>" title="<?=$Language->template('navigation_home_desc', $BLOGMETA_NAME)?>">
<i class="fa fa-home"></i><?=$Language->template('navigation_home_text')?>
</a>
</li>
@@ -85,7 +93,7 @@
<?=$HTML?>
</main>
<footer id="main-footer">
- &copy; <?=escapeHTML($BLOGMETA['NAME'])?>
+ &copy; <?=$BLOGMETA_NAME?>
</footer>
</section>
</body>
diff --git a/template/standard/lang/de.php b/template/standard/lang/de.php
index 9a59847..d2b094c 100644
--- a/template/standard/lang/de.php
+++ b/template/standard/lang/de.php
@@ -14,12 +14,6 @@
$LANGUAGE['date_format'] = '[D].[M].[Y] [H]:[I]';
#===============================================================================
-# Specific item only feed
-#===============================================================================
-$LANGUAGE['feed_only_posts'] = 'nur Beiträge';
-$LANGUAGE['feed_only_pages'] = 'nur Seiten';
-
-#===============================================================================
# Main navigation strings
#===============================================================================
$LANGUAGE['navigation_home_text'] = 'Home';
diff --git a/template/standard/lang/en.php b/template/standard/lang/en.php
index 416574f..c00ec36 100644
--- a/template/standard/lang/en.php
+++ b/template/standard/lang/en.php
@@ -14,12 +14,6 @@
$LANGUAGE['date_format'] = '[Y]-[M]-[D] [H]:[I]';
#===============================================================================
-# Specific item only feed
-#===============================================================================
-$LANGUAGE['feed_only_posts'] = 'only posts';
-$LANGUAGE['feed_only_pages'] = 'only pages';
-
-#===============================================================================
# Main navigation strings
#===============================================================================
$LANGUAGE['navigation_home_text'] = 'Home';