From 5ce2bcb4356633ecf5a7eab87c583af2fa5e09f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Borovec?= Date: Thu, 22 Aug 2024 01:23:38 +0200 Subject: [PATCH] make readable address mandatory --- database_schema.sql | 6 ++-- docs/www/blog/writearticle.php | 52 ++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/database_schema.sql b/database_schema.sql index a31ed7c..1f06c33 100644 --- a/database_schema.sql +++ b/database_schema.sql @@ -3,9 +3,9 @@ -- https://www.phpmyadmin.net/ -- -- Host: localhost --- Generation Time: Jul 20, 2024 at 02:33 PM +-- Generation Time: Aug 21, 2024 at 11:22 PM -- Server version: 11.4.2-MariaDB --- PHP Version: 8.3.9 +-- PHP Version: 8.3.10 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; @@ -29,7 +29,7 @@ SET time_zone = "+00:00"; CREATE TABLE IF NOT EXISTS `blogposts` ( `blogpost_id` uuid NOT NULL DEFAULT uuid() COMMENT 'uuid of the blogpost', - `readable_address` varchar(64) DEFAULT NULL COMMENT 'Human-readable addressing alternative for an article. For example, blogpost with readable_address = "example" can be accessed by article.php?address=example.', + `readable_address` varchar(64) NOT NULL COMMENT 'Human-readable addressing alternative for an article. For example, blogpost with readable_address = "example" can be accessed by blog/article/example.', `title` varchar(64) DEFAULT NULL COMMENT 'title of the blogpost', `abstract` varchar(512) DEFAULT NULL COMMENT 'short version of the blogpost to be displayed as preview, usually the first paragraph of the real article.', `content` text DEFAULT NULL COMMENT 'html for the article', diff --git a/docs/www/blog/writearticle.php b/docs/www/blog/writearticle.php index 8d62996..3b09b4e 100644 --- a/docs/www/blog/writearticle.php +++ b/docs/www/blog/writearticle.php @@ -255,25 +255,34 @@ if(isset($_POST["submit"])) { $abstract = $_POST["article_abstract"]; $content = $_POST["article_content"]; - // If adress is empty, set it to null + // If adress is empty, repopulate the prefills and show error if(strcmp($address, "") == 0) { - $address = null; - } - - if($_POST["blogpost_id"]) { - $blogpostId = $_POST["blogpost_id"]; - update_blogpost($conn, $blogpostId, $address, $title, $tagsStr, - $abstract, $content); + // Set prefill values for the form + $blogId_prefill = isset($_POST["blogpost_id"]) ? + sanitize_input($_POST["blogpost_id"]) : ""; + $title_prefill = $title; + $address_prefill = $address; + $abstract_prefill = $abstract; + $content_prefill = $content; + $tagStr_prefill = $tagsStr; + $addrErr = "Cannot be empty!"; } + // Otherwise update/create the blogpost else { - $blogpostId = publish_blogpost($conn, $address, $title, $tagsStr, - $abstract, $content); - } + if($_POST["blogpost_id"]) { + $blogpostId = sanitize_input($_POST["blogpost_id"]); + update_blogpost($conn, $blogpostId, $address, $title, $tagsStr, + $abstract, $content); + } + else { + $blogpostId = publish_blogpost($conn, $address, $title, $tagsStr, + $abstract, $content); + } - generate_atom_feed($conn); + generate_atom_feed($conn); - // Show button to generate the article - printf(" + // Show button to generate the article + printf("
@@ -283,12 +292,13 @@ if(isset($_POST["submit"])) {
-", $blogpostId, $address); - include_once($COMMONS."/footer.php"); - die; + ", $blogpostId, $address); + include_once($COMMONS."/footer.php"); + die; + } } -if(isset($_GET["guid"])) { +else if(isset($_GET["guid"])) { $blogId = sanitize_input($_GET["guid"]); // select article title, abstract and content from the database @@ -340,7 +350,7 @@ printf(" - Leave empty to use GUID addressing + %s @@ -364,7 +374,7 @@ printf(" -", $blogId_prefill, $title_prefill, $address_prefill, $tagStr_prefill, - $abstract_prefill, $content_prefill); +", $blogId_prefill, $title_prefill, $address_prefill, $addrErr, + $tagStr_prefill, $abstract_prefill, $content_prefill); include_once($COMMONS."/footer.php"); ?>