Compare commits

...

5 commits

3 changed files with 288 additions and 134 deletions

View file

@ -7,6 +7,7 @@ class BlogpostComment
{ {
public $comment_id; public $comment_id;
public $blogpost_id; public $blogpost_id;
public $blogpost_addr;
public $poster_id; public $poster_id;
public $poster_name; public $poster_name;
public $parent_id; public $parent_id;
@ -18,15 +19,17 @@ class BlogpostComment
* Display the comment, and recursively it's children * Display the comment, and recursively it's children
*/ */
public function display_comment() { public function display_comment() {
if(is_null($this->blogpost_addr)) {
printf(" printf("
<div class=\"comment\" id=\"comment-%s\"> <div class=\"comment\" id=\"comment-%s\">
<div class=\"comment-own-wrapper\"> <div class=\"comment-own-wrapper\">
<span class=\"comment-author\"> By: %s </span> <span class=\"comment-author\"> By: %s </span>
<span class=\"comment-date\"> On: %s </span> <span class=\"comment-date\"> On: %s </span>
<label for=\"reveal-response-%s\" class=\"checkbox-button\"> <label for=\"reveal-response-%s\" class=\"checkbox-button\">
Respond Respond
</label> </label>
<input type=\"checkbox\" id=\"reveal-response-%s\" style=\"display: none;\"> <input type=\"checkbox\" id=\"reveal-response-%s\"
style=\"display: none;\">
<hr> <hr>
<div class=\"comment-content\"> <div class=\"comment-content\">
%s %s
@ -37,7 +40,8 @@ class BlogpostComment
<input type=\"hidden\" name=\"comment_id\" value=\"%s\"> <input type=\"hidden\" name=\"comment_id\" value=\"%s\">
<label for=\"comment_entry\">Write response:</label> <label for=\"comment_entry\">Write response:</label>
<div class=\"centered-container\"> <div class=\"centered-container\">
<textarea name=\"comment_entry\" class=\"comment-box\"> </textarea> <textarea name=\"comment_entry\"
class=\"comment-box\"></textarea>
</div> </div>
<input name=\"submit\" type=\"submit\" value=\"Send\"> <input name=\"submit\" type=\"submit\" value=\"Send\">
</form> </form>
@ -54,6 +58,49 @@ class BlogpostComment
htmlspecialchars($_SERVER["PHP_SELF"]), htmlspecialchars($_SERVER["PHP_SELF"]),
$this->blogpost_id, $this->blogpost_id,
$this->comment_id); $this->comment_id);
}
else {
printf("
<div class=\"comment\" id=\"comment-%s\">
<div class=\"comment-own-wrapper\">
<span class=\"comment-author\"> By: %s </span>
<span class=\"comment-date\"> On: %s </span>
<label for=\"reveal-response-%s\" class=\"checkbox-button\">
Respond
</label>
<input type=\"checkbox\" id=\"reveal-response-%s\"
style=\"display: none;\">
<hr>
<div class=\"comment-content\">
%s
</div>
<div class=\"comment-response\">
<form method=\"post\" action=\"%s\">
<input type=\"hidden\" name=\"blogpost_id\" value=\"%s\">
<input type=\"hidden\" name=\"address\" value=\"%s\">
<input type=\"hidden\" name=\"comment_id\" value=\"%s\">
<label for=\"comment_entry\">Write response:</label>
<div class=\"centered-container\">
<textarea name=\"comment_entry\"
class=\"comment-box\"></textarea>
</div>
<input name=\"submit\" type=\"submit\" value=\"Send\">
</form>
</div>
</div>
<div class=\"comment-child-wrapper\">
",
$this->comment_id,
$this->poster_name,
date("Y-m-d H:i", strtotime($this->timestamp)),
$this->comment_id,
$this->comment_id,
$this->content,
htmlspecialchars($_SERVER["PHP_SELF"]),
$this->blogpost_id,
$this->blogpost_addr,
$this->comment_id);
}
if($this->children != null) { if($this->children != null) {
for($i = 0; $i < count($this->children); $i++) for($i = 0; $i < count($this->children); $i++)
@ -113,7 +160,8 @@ class BlogpostComment
$commentObj = new BlogpostComment($com["comment_id"], $commentObj = new BlogpostComment($com["comment_id"],
$com["poster_id"], $username, $this->blogpost_id, $com["poster_id"], $username, $this->blogpost_id,
$com["timestamp"], $com["content"], $this->comment_id); $this->blogpost_addr, $com["timestamp"], $com["content"],
$this->comment_id);
$comments_arr[] = $commentObj; $comments_arr[] = $commentObj;
$commentObj->load_children($conn); $commentObj->load_children($conn);
} }
@ -127,14 +175,17 @@ class BlogpostComment
* $poster_id GUID of the comment author. * $poster_id GUID of the comment author.
* $poster_name Name of the comment author. * $poster_name Name of the comment author.
* $blogpost_id GUID of the blogpost this comment is under. * $blogpost_id GUID of the blogpost this comment is under.
* $blogpost_addr Human-readable address of the blogpost this
comment is under.
* $timestamp Timestamp at comment creation. * $timestamp Timestamp at comment creation.
* $content Content of the comment. * $content Content of the comment.
* $parent_id GUID of the comment this is a reply to (or NULL). * $parent_id GUID of the comment this is a reply to (or NULL).
*/ */
public function __construct($comment_id, $poster_id, $poster_name, public function __construct($comment_id, $poster_id, $poster_name,
$blogpost_id, $timestamp, $content, $parent_id) { $blogpost_id, $blogpost_address, $timestamp, $content, $parent_id) {
$this->comment_id = $comment_id; $this->comment_id = $comment_id;
$this->blogpost_id = $blogpost_id; $this->blogpost_id = $blogpost_id;
$this->blogpost_addr = $blogpost_address;
$this->poster_id = $poster_id; $this->poster_id = $poster_id;
$this->poster_name = $poster_name; $this->poster_name = $poster_name;
$this->timestamp = $timestamp; $this->timestamp = $timestamp;
@ -147,6 +198,7 @@ class BlogpostComment
class Blogpost class Blogpost
{ {
public $blogpost_id; public $blogpost_id;
public $address;
public $title; public $title;
public $content; public $content;
public $date_posted; public $date_posted;
@ -172,21 +224,25 @@ class Blogpost
return; return;
} }
if (isset($_COOKIE["PHPSESSID"]) && (bool)($_SESSION["current_user"]->permissions & 128)) { if (isset($_COOKIE["PHPSESSID"]) &&
(bool)($_SESSION["current_user"]->permissions & 128)) {
$topRight = sprintf("<td class=\"blog-publish-date\"> $topRight = sprintf("<td class=\"blog-publish-date\">
<a href=\"http://www.zdenekborovec-dev.cz/blog/writearticle/ <a href=\"http://www.zdenekborovec-dev.cz/blog/writearticle/
?guid=%s\">Edit</a></td>", $this->blogpost_id); ?guid=%s\">Edit</a></td>", $this->blogpost_id);
} }
else { else {
$topRight = sprintf("<td class=\"blog-publish-date\">Published on: %s</td>", $topRight = sprintf("<td class=\"blog-publish-date\">
Published on: %s</td>",
date("Y-m-d", strtotime($this->date_posted))); date("Y-m-d", strtotime($this->date_posted)));
} }
// Display the blog title and metadata // Display the blog title and metadata
printf("<article>"); printf("<article>");
print_r("<table class=\"noborder-table\" style=\"width: 100%; margin-top: 16px;\">"); print_r("<table class=\"noborder-table\" style=\"width: 100%;
printf("<tr><td style=\"padding: 0px;\"><h2 style=\"margin-top: 0px;\">%s</h2></td>%s</tr> margin-top: 16px;\">");
<tr><td class=\"blog-tags\">", $this->title, $topRight); printf("<tr><td style=\"padding: 0px;\"><h2 style=\"margin-top: 0px;\">
%s</h2></td>%s</tr><tr><td class=\"blog-tags\">",
$this->title, $topRight);
// Display tags // Display tags
for($i = 0; $i < count($this->tags); $i++) { for($i = 0; $i < count($this->tags); $i++) {
@ -198,8 +254,8 @@ class Blogpost
} }
// Display publish date and end metadata div // Display publish date and end metadata div
printf("</td><td class=\"blog-publish-date\">Last edited on: %s</td></tr></table>", printf("</td><td class=\"blog-publish-date\">Last edited on: %s</td>
date("Y-m-d", strtotime($this->date_edited))); </tr></table>", date("Y-m-d", strtotime($this->date_edited)));
// Display hrule, article content and end the article // Display hrule, article content and end the article
printf("</article><hr><article>%s</article>", $this->content); printf("</article><hr><article>%s</article>", $this->content);
@ -219,6 +275,7 @@ class Blogpost
/** /**
* Constructor for the blogpost. * Constructor for the blogpost.
* $blogpost_id GUID of the blogpost in the database. * $blogpost_id GUID of the blogpost in the database.
* $address Readable address of the blogpost.
* $title Title of the blogpost. * $title Title of the blogpost.
* $content Content of the blogpost article. * $content Content of the blogpost article.
* $date_posted Timestamp at publishing of article. * $date_posted Timestamp at publishing of article.
@ -227,9 +284,10 @@ class Blogpost
* $comments Array of Blogpostcomment objects, * $comments Array of Blogpostcomment objects,
* the comments of this article. * the comments of this article.
*/ */
public function __construct($blogpost_id, $title, $content, public function __construct($blogpost_id, $address, $title,
$date_posted, $date_edited, $tags, $comments){ $content, $date_posted, $date_edited, $tags, $comments){
$this->blogpost_id = $blogpost_id; $this->blogpost_id = $blogpost_id;
$this->address = $address;
$this->title = $title; $this->title = $title;
$this->content = $content; $this->content = $content;
$this->date_posted = $date_posted; $this->date_posted = $date_posted;
@ -282,7 +340,7 @@ function send_comment($conn, $blogId, $posterId, $content, $parentId) {
* Load comments under a given blog. * Load comments under a given blog.
* Returns array of BlogpostComment objects. * Returns array of BlogpostComment objects.
*/ */
function load_comments($conn, $blogId) { function load_comments($conn, $blogId, $blogAddress) {
// Prepare new statement for selecting all the child comments. // Prepare new statement for selecting all the child comments.
$stmt = $conn->prepare("SELECT comment_id, poster_id, timestamp, $stmt = $conn->prepare("SELECT comment_id, poster_id, timestamp,
content FROM blogpost_comments WHERE blogpost_id = :blogpost_id content FROM blogpost_comments WHERE blogpost_id = :blogpost_id
@ -325,7 +383,8 @@ function load_comments($conn, $blogId) {
} }
$commentObj = new BlogpostComment($com["comment_id"], $com["poster_id"], $commentObj = new BlogpostComment($com["comment_id"], $com["poster_id"],
$username, $blogId, $com["timestamp"], $com["content"], NULL); $username, $blogId, $blogAddress, $com["timestamp"],
$com["content"], NULL);
$commentObj->load_children($conn); $commentObj->load_children($conn);
$comments_arr[] = $commentObj; $comments_arr[] = $commentObj;
} }
@ -339,8 +398,9 @@ function load_comments($conn, $blogId) {
*/ */
function load_blog($conn, $blogId){ function load_blog($conn, $blogId){
// Prepare and bind statement for gathering blogpost info // Prepare and bind statement for gathering blogpost info
$stmt = $conn->prepare("SELECT title, content, date_posted, date_edited $stmt = $conn->prepare("SELECT readable_address, title, content,
FROM blogposts WHERE blogpost_id = :blogpost_id;"); date_posted, date_edited FROM blogposts WHERE
blogpost_id = :blogpost_id;");
$stmt->bindParam(":blogpost_id", $blogId); $stmt->bindParam(":blogpost_id", $blogId);
// Execute the statement // Execute the statement
@ -370,13 +430,14 @@ function load_blog($conn, $blogId){
// Set the variables // Set the variables
$blogTitle = $result["title"]; $blogTitle = $result["title"];
$blogAddress = $result["readable_address"];
$blogContent = $result["content"]; $blogContent = $result["content"];
$datePosted = $result["date_posted"]; $datePosted = $result["date_posted"];
$dateEdited = $result["date_edited"]; $dateEdited = $result["date_edited"];
$tags = $tags_arr; $tags = $tags_arr;
$comments = load_comments($conn, $blogId); $comments = load_comments($conn, $blogId, $blogAddress);
return new Blogpost($blogId, $blogTitle, $blogContent, return new Blogpost($blogId, $blogAddress, $blogTitle, $blogContent,
$datePosted, $dateEdited, $tags, $comments); $datePosted, $dateEdited, $tags, $comments);
} }
@ -396,32 +457,56 @@ if(isset($_POST["submit"])) {
$blogId = sanitize_input($_POST["blogpost_id"]); $blogId = sanitize_input($_POST["blogpost_id"]);
$commentContent = sanitize_input($_POST["comment_entry"]); $commentContent = sanitize_input($_POST["comment_entry"]);
$parentId = isset($_POST["comment_id"]) ? $_POST["comment_id"] : "NULL"; $parentId = isset($_POST["comment_id"]) ? $_POST["comment_id"] : "NULL";
$posterId = isset($_SESSION["current_user"]) ? $_SESSION["current_user"]->user_id : "NULL"; $posterId = isset($_SESSION["current_user"]) ?
$_SESSION["current_user"]->user_id : "NULL";
$address = isset($_POST["address"]) ?
sanitize_input($_POST["address"]) : NULL;
// Try to send the comment // Try to send the comment
$commentId = send_comment($conn, $blogId, $posterId, $commentId = send_comment($conn, $blogId, $posterId,
$commentContent, $parentId); $commentContent, $parentId);
// Redirect to this page with GET // Redirect to this page with GET
header("Location: http://www.zdenekborovec-dev.cz/blog/article?blogpost_id=". if(is_null($address)) {
$blogId."#comment-".$commentId); header("Location: http://www.zdenekborovec-dev.cz/blog/".
"article?blogpost_id=".$blogId."#comment-".$commentId);
}
else {
header("Location: http://www.zdenekborovec-dev.cz/blog/".
"article?address=".$address."#comment-".$commentId);
}
die(); die();
} }
// If no ID was entered, display warning and die. // If a human-readable address was provided, extract appropriate id.
if(!isset($_GET["blogpost_id"])) { if(isset($_GET["address"])) {
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Foud", true, 404); $blogAddr = sanitize_input($_GET["address"]);
include_once($_SERVER["DOCUMENT_ROOT"]."/errors/404.php");
include_once($COMMONS."/footer.php"); // Prepare and bind statement for gathering blogpost address
die(); $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. // Attempt to load the blogpost
$blogId = sanitize_input($_GET["blogpost_id"]);
$blogPost = load_blog($conn, $blogId); $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) { if(!$blogPost) {
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Foud", true, 404); header($_SERVER["SERVER_PROTOCOL"]." 404 Not Foud", true, 404);
include_once($_SERVER["DOCUMENT_ROOT"]."/errors/404.php"); include_once($_SERVER["DOCUMENT_ROOT"]."/errors/404.php");
@ -437,23 +522,49 @@ $blogPost->display_article();
printf("<hr style=\"border-style: solid;\">"); printf("<hr style=\"border-style: solid;\">");
// Display post comment form. // Display post comment form.
printf(" if(is_null($blogPost->address))
<article> {
printf("
<article>
<h2> Comments: </h2> <h2> Comments: </h2>
<form method=\"post\" action=\"%s\"> <form method=\"post\" action=\"%s\">
<input type=\"hidden\" name=\"blogpost_id\" value=\"%s\"> <input type=\"hidden\" name=\"blogpost_id\" value=\"%s\">
<label for=\"comment_entry\">Write a comment (%s):</label> <label for=\"comment_entry\">Write a comment (%s):</label>
<div class=\"centered-container\"> <div class=\"centered-container\">
<textarea name=\"comment_entry\" class=\"comment-box\" tabindex=\"1\"> </textarea> <textarea name=\"comment_entry\" class=\"comment-box\"
tabindex=\"1\"></textarea>
</div> </div>
<input name=\"submit\" type=\"submit\" tabindex=\"2\" value=\"Send\"> <input name=\"submit\" type=\"submit\" tabindex=\"2\"
value=\"Send\">
</form> </form>
</article> </article>
", ",
htmlspecialchars($_SERVER["PHP_SELF"]), $blogId, htmlspecialchars($_SERVER["PHP_SELF"]), $blogId,
isset($_SESSION["current_user"]) ? $_SESSION["current_user"]->user_name : isset($_SESSION["current_user"]) ?
"Guest"); $_SESSION["current_user"]->user_name : "Guest");
}
else
{
printf("
<article>
<h2> Comments: </h2>
<form method=\"post\" action=\"%s\">
<input type=\"hidden\" name=\"blogpost_id\" value=\"%s\">
<input type=\"hidden\" name=\"address\" value=\"%s\">
<label for=\"comment_entry\">Write a comment (%s):</label>
<div class=\"centered-container\">
<textarea name=\"comment_entry\" class=\"comment-box\"
tabindex=\"1\"></textarea>
</div>
<input name=\"submit\" type=\"submit\" tabindex=\"2\"
value=\"Send\">
</form>
</article>
",
htmlspecialchars($_SERVER["PHP_SELF"]), $blogId, $blogPost->address,
isset($_SESSION["current_user"]) ?
$_SESSION["current_user"]->user_name : "Guest");
}
// Display the blog comments // Display the blog comments
$blogPost->display_comments(); $blogPost->display_comments();

View file

@ -6,8 +6,9 @@ include_once($COMMONS."/header.php");
/** /**
* Display a blog-preview div * Display a blog-preview div
*/ */
function display_blog_preview($blogpost_id, $title, $abstract, function display_blog_preview($blogpost_id, $blogpost_addr, $title, $abstract,
$date_posted, $tags){ $date_posted, $tags){
if(is_null($blogpost_addr)) {
printf(" printf("
<div class=\"blog-preview\"> <div class=\"blog-preview\">
<a href=\"http://www.zdenekborovec-dev.cz/blog/article?blogpost_id=%s\"> <a href=\"http://www.zdenekborovec-dev.cz/blog/article?blogpost_id=%s\">
@ -16,6 +17,17 @@ function display_blog_preview($blogpost_id, $title, $abstract,
</h3> </h3>
</a> </a>
", $blogpost_id, $title); ", $blogpost_id, $title);
}
else {
printf("
<div class=\"blog-preview\">
<a href=\"http://www.zdenekborovec-dev.cz/blog/article?address=%s\">
<h3>
%s
</h3>
</a>
", $blogpost_addr, $title);
}
print_r("<table class=\"noborder-table\" style=\"width: 100%;\"> print_r("<table class=\"noborder-table\" style=\"width: 100%;\">
<tr><td class=\"blog-tags\">"); <tr><td class=\"blog-tags\">");
@ -53,8 +65,8 @@ function display_blog_previews($conn){
} }
// Prepare statement for selecting all the blogposts // Prepare statement for selecting all the blogposts
$stmt = $conn->prepare("SELECT blogpost_id, title, abstract, date_posted $stmt = $conn->prepare("SELECT blogpost_id, readable_address, title,
FROM blogposts ORDER BY date_posted DESC;"); abstract, date_posted FROM blogposts ORDER BY date_posted DESC;");
// Execute the statement // Execute the statement
$stmt->execute(); $stmt->execute();
@ -81,8 +93,9 @@ function display_blog_previews($conn){
$tags_arr = $stmt->fetchall(PDO::FETCH_ASSOC); $tags_arr = $stmt->fetchall(PDO::FETCH_ASSOC);
// Display the blog // Display the blog
display_blog_preview($blog["blogpost_id"], $blog["title"], display_blog_preview($blog["blogpost_id"], $blog["readable_address"],
$blog["abstract"], $blog["date_posted"], $tags_arr); $blog["title"], $blog["abstract"], $blog["date_posted"],
$tags_arr);
} }
} }

View file

@ -69,13 +69,15 @@ function remove_blogpost_tags($conn, $blogpost_id) {
/** /**
* Publish a new blogpost and add the specified tags to it.. * Publish a new blogpost and add the specified tags to it..
* @param $conn Active Mysql connection. * @param $conn Active Mysql connection.
* @param $blogpost_addr Human-readable address of the edited blogpost.
* @param $title Title for the blogpost. * @param $title Title for the blogpost.
* @param $tagStr String with all the tags for the blogpost * @param $tagStr String with all the tags for the blogpost
* (space-separated). * (space-separated).
* @param $abstract Abstract for the article. * @param $abstract Abstract for the article.
* @param $content Content of the article. * @param $content Content of the article.
*/ */
function publish_blogpost($conn, $title, $tagStr, $abstract, $content) { function publish_blogpost($conn, $blogpost_addr, $title, $tagStr, $abstract,
$content) {
// Get an ID for the blogpost // Get an ID for the blogpost
$stmt = $conn->prepare("SELECT UUID()"); $stmt = $conn->prepare("SELECT UUID()");
$stmt->execute(); $stmt->execute();
@ -83,9 +85,11 @@ function publish_blogpost($conn, $title, $tagStr, $abstract, $content) {
$blogpost_id = $result["UUID()"]; $blogpost_id = $result["UUID()"];
// Prepare, bind and execute the insert statement // Prepare, bind and execute the insert statement
$stmt = $conn->prepare("INSERT INTO blogposts (blogpost_id, title, abstract, $stmt = $conn->prepare("INSERT INTO blogposts (blogpost_id,
content) VALUES (:blogpost_id, :title, :abstract, :content);"); readable_address, title, abstract, content) VALUES
(:blogpost_id, :address, :title, :abstract, :content);");
$stmt->bindParam(":blogpost_id", $blogpost_id); $stmt->bindParam(":blogpost_id", $blogpost_id);
$stmt->bindParam(":address", $blogpost_addr);
$stmt->bindParam(":title", $title); $stmt->bindParam(":title", $title);
$stmt->bindParam(":abstract", $abstract); $stmt->bindParam(":abstract", $abstract);
$stmt->bindParam(":content", $content); $stmt->bindParam(":content", $content);
@ -100,18 +104,20 @@ function publish_blogpost($conn, $title, $tagStr, $abstract, $content) {
* Then update the tags. * Then update the tags.
* @param $conn Active Mysql connection. * @param $conn Active Mysql connection.
* @param $blogpost_id GUID of the edited blogpost. * @param $blogpost_id GUID of the edited blogpost.
* @param $blogpost_addr Human-readable address of the edited blogpost.
* @param $title Title for the blogpost. * @param $title Title for the blogpost.
* @param $tagStr String with all the tags for the blogpost * @param $tagStr String with all the tags for the blogpost
* (space-separated). * (space-separated).
* @param $abstract Abstract for the article. * @param $abstract Abstract for the article.
* @param $content Content of the article. * @param $content Content of the article.
*/ */
function update_blogpost($conn, $blogpost_id, $title, $tagStr, $abstract, function update_blogpost($conn, $blogpost_id, $blogpost_addr, $title,
$content) { $tagStr, $abstract, $content) {
// Prepare, bind and execute the update statement // Prepare, bind and execute the update statement
$stmt = $conn->prepare("UPDATE blogposts SET title = :title, $stmt = $conn->prepare("UPDATE blogposts SET readable_address = :address,
abstract = :abstract, content = :content, date_edited = DEFAULT title = :title, abstract = :abstract, content = :content,
WHERE blogpost_id = :blogpost_id;"); date_edited = DEFAULT WHERE blogpost_id = :blogpost_id;");
$stmt->bindParam(":address", $blogpost_addr);
$stmt->bindParam(":title", $title); $stmt->bindParam(":title", $title);
$stmt->bindParam(":abstract", $abstract); $stmt->bindParam(":abstract", $abstract);
$stmt->bindParam(":content", $content); $stmt->bindParam(":content", $content);
@ -140,16 +146,24 @@ if(isset($_POST["submit"])) {
// over the content here and only trusted users should have access // over the content here and only trusted users should have access
// to this section // to this section
$title = $_POST["blogpost_title"]; $title = $_POST["blogpost_title"];
$address = $_POST["blogpost_address"];
$tagsStr = $_POST["blogpost_tags"]; $tagsStr = $_POST["blogpost_tags"];
$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(strcmp($address, "") == 0) {
$address = null;
}
if($_POST["blogpost_id"]) { if($_POST["blogpost_id"]) {
$blogpostId = $_POST["blogpost_id"]; $blogpostId = $_POST["blogpost_id"];
update_blogpost($conn, $blogpostId, $title, $tagsStr, $abstract, $content); update_blogpost($conn, $blogpostId, $address, $title, $tagsStr,
$abstract, $content);
} }
else { else {
publish_blogpost($conn, $title, $tagsStr, $abstract, $content); publish_blogpost($conn, $address, $title, $tagsStr, $abstract,
$content);
} }
header("Location: "."http://www.zdenekborovec-dev.cz/blog"); header("Location: "."http://www.zdenekborovec-dev.cz/blog");
@ -159,7 +173,7 @@ 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
$stmt = $conn->prepare("SELECT title, abstract, content $stmt = $conn->prepare("SELECT readable_address, title, abstract, content
FROM blogposts WHERE blogpost_id = :blogpost_id"); FROM blogposts WHERE blogpost_id = :blogpost_id");
$stmt->bindParam(":blogpost_id", $blogId); $stmt->bindParam(":blogpost_id", $blogId);
$stmt->execute(); $stmt->execute();
@ -169,6 +183,7 @@ if(isset($_GET["guid"])) {
// Set prefill values for the form // Set prefill values for the form
$blogId_prefill = $blogId; $blogId_prefill = $blogId;
$title_prefill = $result["title"]; $title_prefill = $result["title"];
$address_prefill = $result["readable_address"];
$abstract_prefill = $result["abstract"]; $abstract_prefill = $result["abstract"];
$content_prefill = $result["content"]; $content_prefill = $result["content"];
@ -194,15 +209,30 @@ printf("
<form method=\"post\" action=\"\"> <form method=\"post\" action=\"\">
<input type=\"hidden\" name=\"blogpost_id\" value=\"%s\"> <input type=\"hidden\" name=\"blogpost_id\" value=\"%s\">
<table class=\"noborder-table\">
<tr><td style=\"padding: 0px 4px;\">
<label for=\"blogpost_title\">Post title:</label> <label for=\"blogpost_title\">Post title:</label>
<input type=\"text\" name=\"blogpost_title\" value=\"%s\"><br> </td><td style=\"padding: 0px 4px;\">
<input type=\"text\" name=\"blogpost_title\" value=\"%s\">
</td><td style=\"padding: 0px 4px;\">
</td></tr>
<tr><td style=\"padding: 0px 4px;\">
<label for=\"blogpost_address\">Address:</label>
</td><td style=\"padding: 0px 4px;\">
<input type=\"text\" name=\"blogpost_address\" value=\"%s\">
</td><td style=\"padding: 0px 4px;\">
Leave empty to use GUID addressing
</td></tr>
<tr><td style=\"padding: 0px 4px;\">
<label for=\"blogpost_tags\">Post tags:</label> <label for=\"blogpost_tags\">Post tags:</label>
</td><td style=\"padding: 0px 4px;\">
<input type=\"text\" name=\"blogpost_tags\" value=\"%s\"> <input type=\"text\" name=\"blogpost_tags\" value=\"%s\">
</td><td style=\"padding: 0px 4px;\">
Tags should be separated by spaces, use dash-case, use the Tags should be separated by spaces, use dash-case, use the
<a href=\"http://www.zdenekborovec-dev.cz/blog/tageditor\"> <a href=\"http://www.zdenekborovec-dev.cz/blog/tageditor\">
tageditor</a> page to add new tags. <br> tageditor</a> page to add new tags.
</td></tr>
</table>
<div class=\"centered-container\"> <div class=\"centered-container\">
<textarea name=\"article_abstract\" style=\"width: 100%%; <textarea name=\"article_abstract\" style=\"width: 100%%;
@ -215,7 +245,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, $tagStr_prefill, $abstract_prefill, ", $blogId_prefill, $title_prefill, $address_prefill, $tagStr_prefill, $abstract_prefill,
$content_prefill); $content_prefill);
include_once($COMMONS."/footer.php"); include_once($COMMONS."/footer.php");
?> ?>