added tag editor

This commit is contained in:
Zdenek Borovec 2024-05-12 23:13:40 +02:00
parent 9bd60ee073
commit a082ebfdae
5 changed files with 110 additions and 7 deletions

View file

@ -34,7 +34,7 @@ h1, h2, h3, h4, h5, h6 {
font-family: sans-serif; font-family: sans-serif;
} }
h3, h4, h5, h6 { h2, h3, h4, h5, h6 {
margin-bottom: 8px; margin-bottom: 8px;
} }
@ -260,16 +260,16 @@ ul {
padding-right: 1em; padding-right: 1em;
} }
.blog-metadata .blog-tag { .blog-tag {
border-style: solid; border-style: solid;
border-width: thin; border-width: thin;
border-color: black; border-color: black;
border-radius: 0.5em; border-radius: 0.5em;
padding: 0.2em; padding: 0.2em;
margin: 0.2em; display: inline-block;
} }
.blog-metadata .blog-publish-date { .blog-publish-date {
float: right; float: right;
} }

View file

@ -371,8 +371,8 @@ function load_blog($conn, $blogId){
// Check DB connection // Check DB connection
if($conn == null){ if($conn == null){
header($_SERVER["SERVER_PROTOCOL"]." 503 Not Foud", true, 503); header($_SERVER["SERVER_PROTOCOL"]." 503 Service Unavailable", true, 503);
include_once($_SERVER["DOCUMENT_ROOT"]."/errors/504.php"); include_once($_SERVER["DOCUMENT_ROOT"]."/errors/503.php");
include_once($COMMONS."/footer.php"); include_once($COMMONS."/footer.php");
die(); die();
} }

View file

@ -31,6 +31,7 @@ function display_blog_preview($blogpost_id, $title, $abstract,
Published on: %s Published on: %s
</span> </span>
</div> </div>
<hr>
<p> <p>
%s %s
</p> </p>

102
docs/www/blog/tageditor.php Normal file
View file

@ -0,0 +1,102 @@
<?php
$COMMONS = $_SERVER['DOCUMENT_ROOT'] . "/../common";
include_once($COMMONS."/header.php");
// If the user does not have the 1000 0000 permission,
// throw a 403: Forbidden error.
if(!(bool)($_SESSION["current_user"]->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("<article> <h2> Existing tags: </h2>");
print("<div>");
for($i = 0; $i < $tagCount; $i++) {
$tag = $tags[$i];
printf("
<span class=\"blog-tag\" style=\"background-color: %s;\">
%s
</span>", $tag["color"], $tag["name"]);
if($i % 7 == 0 && $i != 0 && $i != $tagCount -1) {
printf("</div><div style=\"margin-top: 0.3em;\">");
}
}
print("</div>");
print("</article>");
}
/**
* 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");
?>
<article>
<form method="post" action="<?php
echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<h2> Create a new tag: </h2>
<table class="noborder-table"><tr>
<td><label for="tag+name">Tag name:</label></td>
<td>
<input type="text" name="tag_name" tabindex="1"
autofocus="autofocus">
</td>
<td>(use-dash-case)</td>
</tr><tr>
<td><label for="tag_color">Tag color:</label></td>
<td>
<input type="text" name="tag_color" tabindex="2">
</td>
<td>(format css will eat)</td>
</tr></table>
<input name="submit" type="submit" tabindex="3" value="Send">
</form>
</article>
<?php
display_tags($conn);
include_once($COMMONS."/footer.php");
?>

View file

@ -168,7 +168,7 @@ htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<input type="text" name="blogpost_tags"> <input type="text" name="blogpost_tags">
Tags should be separated by spaces, use dash-case, use the Tags should be separated by spaces, use dash-case, use the
<a>tageditor</a> page to add new tags. <br> <a href="http://www.zdenekborovec-dev.cz/blog/tageditor">tageditor</a> page to add new tags. <br>
<div class="centered-container"> <div class="centered-container">
<textarea name="article_abstract" style="width: 100%; height: 5em;"></textarea> <textarea name="article_abstract" style="width: 100%; height: 5em;"></textarea>