make readable address mandatory

This commit is contained in:
Zdenek Borovec 2024-08-22 01:23:38 +02:00
parent 50e128f43f
commit 5ce2bcb435
2 changed files with 34 additions and 24 deletions

View file

@ -3,9 +3,9 @@
-- https://www.phpmyadmin.net/ -- https://www.phpmyadmin.net/
-- --
-- Host: localhost -- 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 -- Server version: 11.4.2-MariaDB
-- PHP Version: 8.3.9 -- PHP Version: 8.3.10
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION; START TRANSACTION;
@ -29,7 +29,7 @@ SET time_zone = "+00:00";
CREATE TABLE IF NOT EXISTS `blogposts` ( CREATE TABLE IF NOT EXISTS `blogposts` (
`blogpost_id` uuid NOT NULL DEFAULT uuid() COMMENT 'uuid of the blogpost', `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', `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.', `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', `content` text DEFAULT NULL COMMENT 'html for the article',

View file

@ -255,25 +255,34 @@ if(isset($_POST["submit"])) {
$abstract = $_POST["article_abstract"]; $abstract = $_POST["article_abstract"];
$content = $_POST["article_content"]; $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) { if(strcmp($address, "") == 0) {
$address = null; // Set prefill values for the form
} $blogId_prefill = isset($_POST["blogpost_id"]) ?
sanitize_input($_POST["blogpost_id"]) : "";
if($_POST["blogpost_id"]) { $title_prefill = $title;
$blogpostId = $_POST["blogpost_id"]; $address_prefill = $address;
update_blogpost($conn, $blogpostId, $address, $title, $tagsStr, $abstract_prefill = $abstract;
$abstract, $content); $content_prefill = $content;
$tagStr_prefill = $tagsStr;
$addrErr = "Cannot be empty!";
} }
// Otherwise update/create the blogpost
else { else {
$blogpostId = publish_blogpost($conn, $address, $title, $tagsStr, if($_POST["blogpost_id"]) {
$abstract, $content); $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 // Show button to generate the article
printf(" printf("
<article> <article>
<form method=\"post\" <form method=\"post\"
action=\"http://www.zdenekborovec-dev.cz/blog/generatearticle/\"> action=\"http://www.zdenekborovec-dev.cz/blog/generatearticle/\">
@ -283,12 +292,13 @@ if(isset($_POST["submit"])) {
<input name=\"submit\" type=\"submit\" value=\"Generate article\"> <input name=\"submit\" type=\"submit\" value=\"Generate article\">
</form> </form>
</article> </article>
", $blogpostId, $address); ", $blogpostId, $address);
include_once($COMMONS."/footer.php"); include_once($COMMONS."/footer.php");
die; die;
}
} }
if(isset($_GET["guid"])) { else if(isset($_GET["guid"])) {
$blogId = sanitize_input($_GET["guid"]); $blogId = sanitize_input($_GET["guid"]);
// select article title, abstract and content from the database // select article title, abstract and content from the database
@ -340,7 +350,7 @@ printf("
</td><td style=\"padding: 0px 4px;\"> </td><td style=\"padding: 0px 4px;\">
<input type=\"text\" name=\"blogpost_address\" value=\"%s\"> <input type=\"text\" name=\"blogpost_address\" value=\"%s\">
</td><td style=\"padding: 0px 4px;\"> </td><td style=\"padding: 0px 4px;\">
Leave empty to use GUID addressing %s
</td></tr> </td></tr>
<tr><td style=\"padding: 0px 4px;\"> <tr><td style=\"padding: 0px 4px;\">
<label for=\"blogpost_tags\">Post tags:</label> <label for=\"blogpost_tags\">Post tags:</label>
@ -364,7 +374,7 @@ printf("
<input name=\"submit\" type=\"submit\" value=\"Send File\"> <input name=\"submit\" type=\"submit\" value=\"Send File\">
</form> </form>
</article> </article>
", $blogId_prefill, $title_prefill, $address_prefill, $tagStr_prefill, ", $blogId_prefill, $title_prefill, $address_prefill, $addrErr,
$abstract_prefill, $content_prefill); $tagStr_prefill, $abstract_prefill, $content_prefill);
include_once($COMMONS."/footer.php"); include_once($COMMONS."/footer.php");
?> ?>