From 3ee4fc2d67dc3aecdb72ad39f23fb0ec3637cb08 Mon Sep 17 00:00:00 2001 From: horus Date: Mon, 15 Mar 2021 22:38:27 +0100 Subject: Changes to trailing slash. --- functions.php | 8 ++++++++ public/index.php | 23 ++++++++++++++--------- views/index.html | 6 +++--- views/snippets/navbar.html | 6 +++--- views/tools.html | 10 +++++----- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/functions.php b/functions.php index 0b7d369..9bd65e4 100644 --- a/functions.php +++ b/functions.php @@ -15,3 +15,11 @@ function str_starts_with( $haystack, $needle ) { $length = strlen( $needle ); return substr( $haystack, 0, $length ) === $needle; } + +function str_ends_with( $haystack, $needle) { + $len = strlen($needle); + if ($len == 0) { + return true; + } + return substr($haystack, -$len) === $needle; +} diff --git a/public/index.php b/public/index.php index 7e44159..1de542e 100644 --- a/public/index.php +++ b/public/index.php @@ -9,24 +9,21 @@ switch( $url ) { case("/"): echo $twig->render('index.html'); break; -case("/about"): +case("/about/"): echo $twig->render('about.html'); break; -case("/projects"): +case("/projects/"): echo $twig->render('projects.html'); break; -case("/tools"): +case("/tools/"): echo $twig->render('tools.html'); break; -case("/tools/faces"): case("/tools/faces/"): echo $twig->render('tools/faces/index.html', [ "faces" => get_faces() ]); break; -case("/tools/pizza"): case("/tools/pizza/"): echo $twig->render('tools/pizza/index.html'); break; -case("/tools/untrack"): case("/tools/untrack/"): $_url = ""; if ( isset($_REQUEST['url']) ) { @@ -34,11 +31,19 @@ case("/tools/untrack/"): } echo $twig->render('tools/untrack/index.html', [ "url" => $_url ]); break; -case("/tools/zeitumstellung"): case("/tools/zeitumstellung/"): echo $twig->render('tools/zeitumstellung/index.html', [ "tc" => new Zeitumstellung() ]); break; +case("/tools/tanz/"): + echo $twig->render('tools/bpm/index.html', [ "dances" => get_dances() ]); + break; default: - http_response_code(404); - echo $twig->render('404.html'); + if ( str_ends_with($url, "/") ) { + http_response_code(404); + echo $twig->render('404.html'); + } else { + $url = $url . "/"; + header("Location: " . $url); + exit; + } } diff --git a/views/index.html b/views/index.html index 9e7151a..5b653b7 100644 --- a/views/index.html +++ b/views/index.html @@ -42,7 +42,7 @@ while lazy; do
- Hobby => Projects() + Hobby => Projects()
endwhile
@@ -54,7 +54,7 @@ while crazy; do
- eval("boot up tools page") + eval("boot up tools page")
endwhile
@@ -66,7 +66,7 @@ if interested; do
- About.Me() + About.Me() or Contact.Me()
diff --git a/views/snippets/navbar.html b/views/snippets/navbar.html index 1b28707..9a63ad9 100644 --- a/views/snippets/navbar.html +++ b/views/snippets/navbar.html @@ -13,13 +13,13 @@ diff --git a/views/tools.html b/views/tools.html index 0b3faad..01ac33e 100644 --- a/views/tools.html +++ b/views/tools.html @@ -16,19 +16,19 @@