added ability to read human-readable address

This commit is contained in:
Zdenek Borovec 2024-07-18 23:32:18 +02:00
parent 933316458d
commit 83a4d00ca5

View file

@ -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");