Compare commits

..

No commits in common. "c3ecf326c730bcd8b1d36b33e2806752cd739a9b" and "933316458d40ab54536479e44ddf9aa3e34b7675" have entirely different histories.

3 changed files with 134 additions and 288 deletions

View file

@ -7,7 +7,6 @@ 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;
@ -19,88 +18,42 @@ 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\" <hr>
style=\"display: none;\"> <div class=\"comment-content\">
<hr> %s
<div class=\"comment-content\"> </div>
%s <div class=\"comment-response\">
</div> <form method=\"post\" action=\"%s\">
<div class=\"comment-response\"> <input type=\"hidden\" name=\"blogpost_id\" value=\"%s\">
<form method=\"post\" action=\"%s\"> <input type=\"hidden\" name=\"comment_id\" value=\"%s\">
<input type=\"hidden\" name=\"blogpost_id\" value=\"%s\"> <label for=\"comment_entry\">Write response:</label>
<input type=\"hidden\" name=\"comment_id\" value=\"%s\"> <div class=\"centered-container\">
<label for=\"comment_entry\">Write response:</label> <textarea name=\"comment_entry\" class=\"comment-box\"> </textarea>
<div class=\"centered-container\"> </div>
<textarea name=\"comment_entry\" <input name=\"submit\" type=\"submit\" value=\"Send\">
class=\"comment-box\"></textarea> </form>
</div>
</div> </div>
<input name=\"submit\" type=\"submit\" value=\"Send\"> <div class=\"comment-child-wrapper\">
</form>
</div>
</div>
<div class=\"comment-child-wrapper\">
", ",
$this->comment_id, $this->comment_id,
$this->poster_name, $this->poster_name,
date("Y-m-d H:i", strtotime($this->timestamp)), date("Y-m-d H:i", strtotime($this->timestamp)),
$this->comment_id, $this->comment_id,
$this->comment_id, $this->comment_id,
$this->content, $this->content,
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++)
@ -160,8 +113,7 @@ 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,
$this->blogpost_addr, $com["timestamp"], $com["content"], $com["timestamp"], $com["content"], $this->comment_id);
$this->comment_id);
$comments_arr[] = $commentObj; $comments_arr[] = $commentObj;
$commentObj->load_children($conn); $commentObj->load_children($conn);
} }
@ -175,22 +127,19 @@ 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, $blogpost_address, $timestamp, $content, $parent_id) { $blogpost_id, $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; $this->content = $content;
$this->content = $content; $this->parent_id = $parent_id;
$this->parent_id = $parent_id;
} }
} }
@ -198,7 +147,6 @@ 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;
@ -224,25 +172,21 @@ class Blogpost
return; return;
} }
if (isset($_COOKIE["PHPSESSID"]) && if (isset($_COOKIE["PHPSESSID"]) && (bool)($_SESSION["current_user"]->permissions & 128)) {
(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\"> $topRight = sprintf("<td class=\"blog-publish-date\">Published on: %s</td>",
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%; print_r("<table class=\"noborder-table\" style=\"width: 100%; margin-top: 16px;\">");
margin-top: 16px;\">"); printf("<tr><td style=\"padding: 0px;\"><h2 style=\"margin-top: 0px;\">%s</h2></td>%s</tr>
printf("<tr><td style=\"padding: 0px;\"><h2 style=\"margin-top: 0px;\"> <tr><td class=\"blog-tags\">", $this->title, $topRight);
%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++) {
@ -254,8 +198,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> printf("</td><td class=\"blog-publish-date\">Last edited on: %s</td></tr></table>",
</tr></table>", date("Y-m-d", strtotime($this->date_edited))); 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);
@ -275,7 +219,6 @@ 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.
@ -284,16 +227,15 @@ 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, $address, $title, public function __construct($blogpost_id, $title, $content,
$content, $date_posted, $date_edited, $tags, $comments){ $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; $this->date_edited = $date_edited;
$this->date_edited = $date_edited; $this->tags = $tags;
$this->tags = $tags; $this->comments = $comments;
$this->comments = $comments;
} }
} }
@ -340,7 +282,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, $blogAddress) { function load_comments($conn, $blogId) {
// 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
@ -383,8 +325,7 @@ function load_comments($conn, $blogId, $blogAddress) {
} }
$commentObj = new BlogpostComment($com["comment_id"], $com["poster_id"], $commentObj = new BlogpostComment($com["comment_id"], $com["poster_id"],
$username, $blogId, $blogAddress, $com["timestamp"], $username, $blogId, $com["timestamp"], $com["content"], NULL);
$com["content"], NULL);
$commentObj->load_children($conn); $commentObj->load_children($conn);
$comments_arr[] = $commentObj; $comments_arr[] = $commentObj;
} }
@ -398,9 +339,8 @@ function load_comments($conn, $blogId, $blogAddress) {
*/ */
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 readable_address, title, content, $stmt = $conn->prepare("SELECT title, content, date_posted, date_edited
date_posted, date_edited FROM blogposts WHERE FROM blogposts WHERE blogpost_id = :blogpost_id;");
blogpost_id = :blogpost_id;");
$stmt->bindParam(":blogpost_id", $blogId); $stmt->bindParam(":blogpost_id", $blogId);
// Execute the statement // Execute the statement
@ -430,14 +370,13 @@ 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, $blogAddress); $comments = load_comments($conn, $blogId);
return new Blogpost($blogId, $blogAddress, $blogTitle, $blogContent, return new Blogpost($blogId, $blogTitle, $blogContent,
$datePosted, $dateEdited, $tags, $comments); $datePosted, $dateEdited, $tags, $comments);
} }
@ -457,56 +396,32 @@ 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"]) ? $posterId = isset($_SESSION["current_user"]) ? $_SESSION["current_user"]->user_id : "NULL";
$_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
if(is_null($address)) { header("Location: http://www.zdenekborovec-dev.cz/blog/article?blogpost_id=".
header("Location: http://www.zdenekborovec-dev.cz/blog/". $blogId."#comment-".$commentId);
"article?blogpost_id=".$blogId."#comment-".$commentId);
}
else {
header("Location: http://www.zdenekborovec-dev.cz/blog/".
"article?address=".$address."#comment-".$commentId);
}
die(); die();
} }
// If a human-readable address was provided, extract appropriate id. // If no ID was entered, display warning and die.
if(isset($_GET["address"])) { if(!isset($_GET["blogpost_id"])) {
$blogAddr = sanitize_input($_GET["address"]); header($_SERVER["SERVER_PROTOCOL"]." 404 Not Foud", true, 404);
include_once($_SERVER["DOCUMENT_ROOT"]."/errors/404.php");
// Prepare and bind statement for gathering blogpost address include_once($COMMONS."/footer.php");
$stmt = $conn->prepare("SELECT blogpost_id die();
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"]);
} }
// Attempt to load the blogpost // Get the blog id.
$blogId = sanitize_input($_GET["blogpost_id"]);
$blogPost = load_blog($conn, $blogId); $blogPost = load_blog($conn, $blogId);
// If blogpost could not be retieved, display warning and die. // If no ID was entered, 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");
@ -522,49 +437,23 @@ $blogPost->display_article();
printf("<hr style=\"border-style: solid;\">"); printf("<hr style=\"border-style: solid;\">");
// Display post comment form. // Display post comment form.
if(is_null($blogPost->address)) printf("
{ <article>
printf(" <h2> Comments: </h2>
<article> <form method=\"post\" action=\"%s\">
<h2> Comments: </h2> <input type=\"hidden\" name=\"blogpost_id\" value=\"%s\">
<form method=\"post\" action=\"%s\"> <label for=\"comment_entry\">Write a comment (%s):</label>
<input type=\"hidden\" name=\"blogpost_id\" value=\"%s\"> <div class=\"centered-container\">
<label for=\"comment_entry\">Write a comment (%s):</label> <textarea name=\"comment_entry\" class=\"comment-box\" tabindex=\"1\"> </textarea>
<div class=\"centered-container\"> </div>
<textarea name=\"comment_entry\" class=\"comment-box\" <input name=\"submit\" type=\"submit\" tabindex=\"2\" value=\"Send\">
tabindex=\"1\"></textarea> </form>
</div> </article>
<input name=\"submit\" type=\"submit\" tabindex=\"2\" ",
value=\"Send\"> htmlspecialchars($_SERVER["PHP_SELF"]), $blogId,
</form> isset($_SESSION["current_user"]) ? $_SESSION["current_user"]->user_name :
</article> "Guest");
",
htmlspecialchars($_SERVER["PHP_SELF"]), $blogId,
isset($_SESSION["current_user"]) ?
$_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,9 +6,8 @@ include_once($COMMONS."/header.php");
/** /**
* Display a blog-preview div * Display a blog-preview div
*/ */
function display_blog_preview($blogpost_id, $blogpost_addr, $title, $abstract, function display_blog_preview($blogpost_id, $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\">
@ -17,17 +16,6 @@ function display_blog_preview($blogpost_id, $blogpost_addr, $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\">");
@ -65,8 +53,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, readable_address, title, $stmt = $conn->prepare("SELECT blogpost_id, title, abstract, date_posted
abstract, date_posted FROM blogposts ORDER BY date_posted DESC;"); FROM blogposts ORDER BY date_posted DESC;");
// Execute the statement // Execute the statement
$stmt->execute(); $stmt->execute();
@ -93,9 +81,8 @@ 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["readable_address"], display_blog_preview($blog["blogpost_id"], $blog["title"],
$blog["title"], $blog["abstract"], $blog["date_posted"], $blog["abstract"], $blog["date_posted"], $tags_arr);
$tags_arr);
} }
} }

View file

@ -68,16 +68,14 @@ 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, $blogpost_addr, $title, $tagStr, $abstract, function publish_blogpost($conn, $title, $tagStr, $abstract, $content) {
$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();
@ -85,11 +83,9 @@ function publish_blogpost($conn, $blogpost_addr, $title, $tagStr, $abstract,
$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, $stmt = $conn->prepare("INSERT INTO blogposts (blogpost_id, title, abstract,
readable_address, title, abstract, content) VALUES content) VALUES (:blogpost_id, :title, :abstract, :content);");
(: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);
@ -102,22 +98,20 @@ function publish_blogpost($conn, $blogpost_addr, $title, $tagStr, $abstract,
/** /**
* Update the blogpost content, title, abstract and date edited. * Update the blogpost content, title, abstract and date edited.
* 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, $blogpost_addr, $title, function update_blogpost($conn, $blogpost_id, $title, $tagStr, $abstract,
$tagStr, $abstract, $content) { $content) {
// Prepare, bind and execute the update statement // Prepare, bind and execute the update statement
$stmt = $conn->prepare("UPDATE blogposts SET readable_address = :address, $stmt = $conn->prepare("UPDATE blogposts SET title = :title,
title = :title, abstract = :abstract, content = :content, abstract = :abstract, content = :content, date_edited = DEFAULT
date_edited = DEFAULT WHERE blogpost_id = :blogpost_id;"); 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);
@ -146,24 +140,16 @@ 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, $address, $title, $tagsStr, update_blogpost($conn, $blogpostId, $title, $tagsStr, $abstract, $content);
$abstract, $content);
} }
else { else {
publish_blogpost($conn, $address, $title, $tagsStr, $abstract, publish_blogpost($conn, $title, $tagsStr, $abstract, $content);
$content);
} }
header("Location: "."http://www.zdenekborovec-dev.cz/blog"); header("Location: "."http://www.zdenekborovec-dev.cz/blog");
@ -173,7 +159,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 readable_address, title, abstract, content $stmt = $conn->prepare("SELECT 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();
@ -183,7 +169,6 @@ 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"];
@ -209,30 +194,15 @@ 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\"> <label for=\"blogpost_title\">Post title:</label>
<tr><td style=\"padding: 0px 4px;\"> <input type=\"text\" name=\"blogpost_title\" value=\"%s\"><br>
<label for=\"blogpost_title\">Post title:</label>
</td><td style=\"padding: 0px 4px;\"> <label for=\"blogpost_tags\">Post tags:</label>
<input type=\"text\" name=\"blogpost_title\" value=\"%s\"> <input type=\"text\" name=\"blogpost_tags\" value=\"%s\">
</td><td style=\"padding: 0px 4px;\">
</td></tr> Tags should be separated by spaces, use dash-case, use the
<tr><td style=\"padding: 0px 4px;\"> <a href=\"http://www.zdenekborovec-dev.cz/blog/tageditor\">
<label for=\"blogpost_address\">Address:</label> tageditor</a> page to add new tags. <br>
</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>
</td><td style=\"padding: 0px 4px;\">
<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
<a href=\"http://www.zdenekborovec-dev.cz/blog/tageditor\">
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%%;
@ -245,7 +215,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, $abstract_prefill, ", $blogId_prefill, $title_prefill, $tagStr_prefill, $abstract_prefill,
$content_prefill); $content_prefill);
include_once($COMMONS."/footer.php"); include_once($COMMONS."/footer.php");
?> ?>