From a082ebfdae0e02140fb5c923ca3b8aa0513a877b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Borovec?= Date: Sun, 12 May 2024 23:13:40 +0200 Subject: [PATCH] added tag editor --- assets/common/styles.css | 8 +-- docs/www/blog/article.php | 4 +- docs/www/blog/index.php | 1 + docs/www/blog/tageditor.php | 102 +++++++++++++++++++++++++++++++++ docs/www/blog/writearticle.php | 2 +- 5 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 docs/www/blog/tageditor.php diff --git a/assets/common/styles.css b/assets/common/styles.css index 58cbadc..12557d3 100755 --- a/assets/common/styles.css +++ b/assets/common/styles.css @@ -34,7 +34,7 @@ h1, h2, h3, h4, h5, h6 { font-family: sans-serif; } -h3, h4, h5, h6 { +h2, h3, h4, h5, h6 { margin-bottom: 8px; } @@ -260,16 +260,16 @@ ul { padding-right: 1em; } -.blog-metadata .blog-tag { +.blog-tag { border-style: solid; border-width: thin; border-color: black; border-radius: 0.5em; padding: 0.2em; - margin: 0.2em; + display: inline-block; } -.blog-metadata .blog-publish-date { +.blog-publish-date { float: right; } diff --git a/docs/www/blog/article.php b/docs/www/blog/article.php index e0855e6..86b1ad7 100644 --- a/docs/www/blog/article.php +++ b/docs/www/blog/article.php @@ -371,8 +371,8 @@ function load_blog($conn, $blogId){ // Check DB connection if($conn == null){ - header($_SERVER["SERVER_PROTOCOL"]." 503 Not Foud", true, 503); - include_once($_SERVER["DOCUMENT_ROOT"]."/errors/504.php"); + header($_SERVER["SERVER_PROTOCOL"]." 503 Service Unavailable", true, 503); + include_once($_SERVER["DOCUMENT_ROOT"]."/errors/503.php"); include_once($COMMONS."/footer.php"); die(); } diff --git a/docs/www/blog/index.php b/docs/www/blog/index.php index a10643c..fe2cf92 100755 --- a/docs/www/blog/index.php +++ b/docs/www/blog/index.php @@ -31,6 +31,7 @@ function display_blog_preview($blogpost_id, $title, $abstract, Published on: %s +

%s

diff --git a/docs/www/blog/tageditor.php b/docs/www/blog/tageditor.php new file mode 100644 index 0000000..2bb1d1a --- /dev/null +++ b/docs/www/blog/tageditor.php @@ -0,0 +1,102 @@ +permissions & 128)) { + header($_SERVER["SERVER_PROTOCOL"]." 403 Forbidden", true, 403); + include_once($_SERVER["DOCUMENT_ROOT"]."/errors/403.php"); + include_once($COMMONS."/footer.php"); + die(); +} + +/** + * Display tags existing in the database. + */ +function display_tags($conn) { + $stmt = $conn->prepare("SELECT tag_id, name, color + FROM blogpost_tags ORDER BY tag_id ASC;"); + $stmt->execute(); + $tags = $stmt->fetchall(PDO::FETCH_ASSOC); + + $tagCount = count($tags); + + print("

Existing tags:

"); + print("
"); + for($i = 0; $i < $tagCount; $i++) { + $tag = $tags[$i]; + printf(" + + %s + ", $tag["color"], $tag["name"]); + + if($i % 7 == 0 && $i != 0 && $i != $tagCount -1) { + printf("
"); + } + } + print("
"); + print("
"); +} + +/** + * Add the tag to the database. + */ +function add_tag($conn, $name, $color) { + $stmt = $conn->prepare("INSERT INTO blogpost_tags (name, color) + VALUES (:name, :color)"); + $stmt->bindParam(":name", $name); + $stmt->bindParam(":color", $color); + $stmt->execute(); +} + +// Check DB connection +if($conn == null){ + header($_SERVER["SERVER_PROTOCOL"]." 503 Service Unavailable", true, 503); + include_once($_SERVER["DOCUMENT_ROOT"]."/errors/503.php"); + include_once($COMMONS."/footer.php"); + die(); +} + +if(isset($_POST["submit"])) { + $name = $_POST["tag_name"]; + $color = $_POST["tag_color"]; + + if($name && $color) { + add_tag($conn, $name, $color); + } + header(sprintf("Location: %s", sanitize_input($_SERVER["PHP_SELF"]))); +} + +display_header("Tag Editor"); +?> + +
+
"> +

Create a new tag:

+ + + + + + + + +
+ + (use-dash-case)
+ + (format css will eat)
+ +
+
+ + diff --git a/docs/www/blog/writearticle.php b/docs/www/blog/writearticle.php index a72fc35..0b267d4 100644 --- a/docs/www/blog/writearticle.php +++ b/docs/www/blog/writearticle.php @@ -168,7 +168,7 @@ htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> Tags should be separated by spaces, use dash-case, use the - tageditor page to add new tags.
+ tageditor page to add new tags.