From ed410c62816f5f31866a7caa1bb44f957b5cff30 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Wed, 1 Jul 2020 15:49:39 +0200 Subject: [PATCH] Handle missing guide --- index.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/index.php b/index.php index b8270d2..cd92b82 100644 --- a/index.php +++ b/index.php @@ -123,14 +123,24 @@ if(is_array($match) && is_callable($match['target'])) { case 'guideId': $id = htmlspecialchars($match['params']['id']); - $content = file_get_contents("pages/template.html"); - $guideTitle = file_get_contents("pages/guides/$id.title.html"); - $guideContent = file_get_contents("pages/guides/$id.content.html"); - $guideContent = "

Back to guides

".$guideContent; - $content = str_replace('%TITLE%', $guideTitle, $content); - $content = str_replace('%CONTENT%', $guideContent, $content); - header('Content-Type: text/html; charset=utf-8'); - echo($content); + if (file_exists("pages/guides/$id.title.html")) { + $content = file_get_contents("pages/template.html"); + $guideTitle = file_get_contents("pages/guides/$id.title.html"); + $guideContent = file_get_contents("pages/guides/$id.content.html"); + $guideContent = "

Back to guides

".$guideContent; + $content = str_replace('%TITLE%', $guideTitle, $content); + $content = str_replace('%CONTENT%', $guideContent, $content); + header('Content-Type: text/html; charset=utf-8'); + echo($content); + } else { + $content = file_get_contents("pages/template.html"); + $pageTitle = "Guide not found"; + $pageContent = "

404 - This guide could not be found :(

"; + $content = str_replace('%TITLE%', $pageTitle, $content); + $content = str_replace('%CONTENT%', $pageContent, $content); + header('Content-Type: text/html; charset=utf-8'); + echo($content); + } break; case 'util': @@ -146,7 +156,7 @@ if(is_array($match) && is_callable($match['target'])) { // No route was matched $content = file_get_contents("pages/template.html"); $pageTitle = "404"; - $pageContent = "404 - This page could not be found :("; + $pageContent = "

404 - This page could not be found :(

"; $content = str_replace('%TITLE%', $pageTitle, $content); $content = str_replace('%CONTENT%', $pageContent, $content); header('Content-Type: text/html; charset=utf-8');