From 83a4d00ca5bd9e1ac105c0a8b8c6365ac1d35b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Borovec?= Date: Thu, 18 Jul 2024 23:32:18 +0200 Subject: [PATCH] added ability to read human-readable address --- docs/www/blog/article.php | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/docs/www/blog/article.php b/docs/www/blog/article.php index ee53568..d20a99e 100644 --- a/docs/www/blog/article.php +++ b/docs/www/blog/article.php @@ -408,20 +408,35 @@ if(isset($_POST["submit"])) { die(); } -// If no ID was entered, display warning and die. -if(!isset($_GET["blogpost_id"])) { - header($_SERVER["SERVER_PROTOCOL"]." 404 Not Foud", true, 404); - include_once($_SERVER["DOCUMENT_ROOT"]."/errors/404.php"); - include_once($COMMONS."/footer.php"); - die(); +// If a human-readable address was provided, extract appropriate id. +if(isset($_GET["address"])) { + $blogAddr = sanitize_input($_GET["address"]); + + // Prepare and bind statement for gathering blogpost address + $stmt = $conn->prepare("SELECT blogpost_id + FROM blogposts WHERE readable_address = :readable_address;"); + $stmt->bindParam(":readable_address", $blogAddr); + + // Execute the statement + $stmt->execute(); + + // Fetch the blogpost + $result = $stmt->fetch(PDO::FETCH_ASSOC); + + // If post with given address was found, set the $blogId var. + if($result){ + $blogId = sanitize_input($result["blogpost_id"]); + } +} +// If a blogpost id was provided, get it. +else if(isset($_GET["blogpost_id"])) { + $blogId = sanitize_input($_GET["blogpost_id"]); } -// Get the blog id. -$blogId = sanitize_input($_GET["blogpost_id"]); - +// Attempt to load the blogpost $blogPost = load_blog($conn, $blogId); -// If no ID was entered, display warning and die. +// If blogpost could not be retieved, display warning and die. if(!$blogPost) { header($_SERVER["SERVER_PROTOCOL"]." 404 Not Foud", true, 404); include_once($_SERVER["DOCUMENT_ROOT"]."/errors/404.php");