Compare commits
5 commits
933316458d
...
c3ecf326c7
Author | SHA1 | Date | |
---|---|---|---|
c3ecf326c7 | |||
47de0245d8 | |||
08c2c31644 | |||
b04d38c9e9 | |||
83a4d00ca5 |
3 changed files with 288 additions and 134 deletions
|
@ -7,6 +7,7 @@ class BlogpostComment
|
|||
{
|
||||
public $comment_id;
|
||||
public $blogpost_id;
|
||||
public $blogpost_addr;
|
||||
public $poster_id;
|
||||
public $poster_name;
|
||||
public $parent_id;
|
||||
|
@ -18,42 +19,88 @@ class BlogpostComment
|
|||
* Display the comment, and recursively it's children
|
||||
*/
|
||||
public function display_comment() {
|
||||
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=\"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>
|
||||
if(is_null($this->blogpost_addr)) {
|
||||
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=\"comment_id\" value=\"%s\">
|
||||
<label for=\"comment_entry\">Write response:</label>
|
||||
<div class=\"centered-container\">
|
||||
<textarea name=\"comment_entry\"
|
||||
class=\"comment-box\"></textarea>
|
||||
</div>
|
||||
<div class=\"comment-child-wrapper\">
|
||||
<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->comment_id);
|
||||
$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->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) {
|
||||
for($i = 0; $i < count($this->children); $i++)
|
||||
|
@ -113,7 +160,8 @@ class BlogpostComment
|
|||
|
||||
$commentObj = new BlogpostComment($com["comment_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;
|
||||
$commentObj->load_children($conn);
|
||||
}
|
||||
|
@ -127,19 +175,22 @@ class BlogpostComment
|
|||
* $poster_id GUID of the comment author.
|
||||
* $poster_name Name of the comment author.
|
||||
* $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.
|
||||
* $content Content of the comment.
|
||||
* $parent_id GUID of the comment this is a reply to (or NULL).
|
||||
*/
|
||||
public function __construct($comment_id, $poster_id, $poster_name,
|
||||
$blogpost_id, $timestamp, $content, $parent_id) {
|
||||
$this->comment_id = $comment_id;
|
||||
$this->blogpost_id = $blogpost_id;
|
||||
$this->poster_id = $poster_id;
|
||||
$this->poster_name = $poster_name;
|
||||
$this->timestamp = $timestamp;
|
||||
$this->content = $content;
|
||||
$this->parent_id = $parent_id;
|
||||
$blogpost_id, $blogpost_address, $timestamp, $content, $parent_id) {
|
||||
$this->comment_id = $comment_id;
|
||||
$this->blogpost_id = $blogpost_id;
|
||||
$this->blogpost_addr = $blogpost_address;
|
||||
$this->poster_id = $poster_id;
|
||||
$this->poster_name = $poster_name;
|
||||
$this->timestamp = $timestamp;
|
||||
$this->content = $content;
|
||||
$this->parent_id = $parent_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,6 +198,7 @@ class BlogpostComment
|
|||
class Blogpost
|
||||
{
|
||||
public $blogpost_id;
|
||||
public $address;
|
||||
public $title;
|
||||
public $content;
|
||||
public $date_posted;
|
||||
|
@ -172,21 +224,25 @@ class Blogpost
|
|||
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\">
|
||||
<a href=\"http://www.zdenekborovec-dev.cz/blog/writearticle/
|
||||
?guid=%s\">Edit</a></td>", $this->blogpost_id);
|
||||
}
|
||||
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)));
|
||||
}
|
||||
|
||||
// Display the blog title and metadata
|
||||
printf("<article>");
|
||||
print_r("<table class=\"noborder-table\" style=\"width: 100%; margin-top: 16px;\">");
|
||||
printf("<tr><td style=\"padding: 0px;\"><h2 style=\"margin-top: 0px;\">%s</h2></td>%s</tr>
|
||||
<tr><td class=\"blog-tags\">", $this->title, $topRight);
|
||||
print_r("<table class=\"noborder-table\" style=\"width: 100%;
|
||||
margin-top: 16px;\">");
|
||||
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
|
||||
for($i = 0; $i < count($this->tags); $i++) {
|
||||
|
@ -198,8 +254,8 @@ class Blogpost
|
|||
}
|
||||
|
||||
// Display publish date and end metadata div
|
||||
printf("</td><td class=\"blog-publish-date\">Last edited on: %s</td></tr></table>",
|
||||
date("Y-m-d", strtotime($this->date_edited)));
|
||||
printf("</td><td class=\"blog-publish-date\">Last edited on: %s</td>
|
||||
</tr></table>", date("Y-m-d", strtotime($this->date_edited)));
|
||||
|
||||
// Display hrule, article content and end the article
|
||||
printf("</article><hr><article>%s</article>", $this->content);
|
||||
|
@ -219,6 +275,7 @@ class Blogpost
|
|||
/**
|
||||
* Constructor for the blogpost.
|
||||
* $blogpost_id GUID of the blogpost in the database.
|
||||
* $address Readable address of the blogpost.
|
||||
* $title Title of the blogpost.
|
||||
* $content Content of the blogpost article.
|
||||
* $date_posted Timestamp at publishing of article.
|
||||
|
@ -227,15 +284,16 @@ class Blogpost
|
|||
* $comments Array of Blogpostcomment objects,
|
||||
* the comments of this article.
|
||||
*/
|
||||
public function __construct($blogpost_id, $title, $content,
|
||||
$date_posted, $date_edited, $tags, $comments){
|
||||
$this->blogpost_id = $blogpost_id;
|
||||
$this->title = $title;
|
||||
$this->content = $content;
|
||||
$this->date_posted = $date_posted;
|
||||
$this->date_edited = $date_edited;
|
||||
$this->tags = $tags;
|
||||
$this->comments = $comments;
|
||||
public function __construct($blogpost_id, $address, $title,
|
||||
$content, $date_posted, $date_edited, $tags, $comments){
|
||||
$this->blogpost_id = $blogpost_id;
|
||||
$this->address = $address;
|
||||
$this->title = $title;
|
||||
$this->content = $content;
|
||||
$this->date_posted = $date_posted;
|
||||
$this->date_edited = $date_edited;
|
||||
$this->tags = $tags;
|
||||
$this->comments = $comments;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +340,7 @@ function send_comment($conn, $blogId, $posterId, $content, $parentId) {
|
|||
* Load comments under a given blog.
|
||||
* 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.
|
||||
$stmt = $conn->prepare("SELECT comment_id, poster_id, timestamp,
|
||||
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"],
|
||||
$username, $blogId, $com["timestamp"], $com["content"], NULL);
|
||||
$username, $blogId, $blogAddress, $com["timestamp"],
|
||||
$com["content"], NULL);
|
||||
$commentObj->load_children($conn);
|
||||
$comments_arr[] = $commentObj;
|
||||
}
|
||||
|
@ -339,8 +398,9 @@ function load_comments($conn, $blogId) {
|
|||
*/
|
||||
function load_blog($conn, $blogId){
|
||||
// Prepare and bind statement for gathering blogpost info
|
||||
$stmt = $conn->prepare("SELECT title, content, date_posted, date_edited
|
||||
FROM blogposts WHERE blogpost_id = :blogpost_id;");
|
||||
$stmt = $conn->prepare("SELECT readable_address, title, content,
|
||||
date_posted, date_edited FROM blogposts WHERE
|
||||
blogpost_id = :blogpost_id;");
|
||||
$stmt->bindParam(":blogpost_id", $blogId);
|
||||
|
||||
// Execute the statement
|
||||
|
@ -370,13 +430,14 @@ function load_blog($conn, $blogId){
|
|||
|
||||
// Set the variables
|
||||
$blogTitle = $result["title"];
|
||||
$blogAddress = $result["readable_address"];
|
||||
$blogContent = $result["content"];
|
||||
$datePosted = $result["date_posted"];
|
||||
$dateEdited = $result["date_edited"];
|
||||
$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);
|
||||
}
|
||||
|
||||
|
@ -396,32 +457,56 @@ if(isset($_POST["submit"])) {
|
|||
$blogId = sanitize_input($_POST["blogpost_id"]);
|
||||
$commentContent = sanitize_input($_POST["comment_entry"]);
|
||||
$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
|
||||
$commentId = send_comment($conn, $blogId, $posterId,
|
||||
$commentContent, $parentId);
|
||||
|
||||
// Redirect to this page with GET
|
||||
header("Location: http://www.zdenekborovec-dev.cz/blog/article?blogpost_id=".
|
||||
$blogId."#comment-".$commentId);
|
||||
if(is_null($address)) {
|
||||
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();
|
||||
}
|
||||
|
||||
// If no ID was entered, display warning and die.
|
||||
if(!isset($_GET["blogpost_id"])) {
|
||||
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Foud", true, 404);
|
||||
include_once($_SERVER["DOCUMENT_ROOT"]."/errors/404.php");
|
||||
include_once($COMMONS."/footer.php");
|
||||
die();
|
||||
// If a human-readable address was provided, extract appropriate id.
|
||||
if(isset($_GET["address"])) {
|
||||
$blogAddr = sanitize_input($_GET["address"]);
|
||||
|
||||
// Prepare and bind statement for gathering blogpost address
|
||||
$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.
|
||||
$blogId = sanitize_input($_GET["blogpost_id"]);
|
||||
|
||||
// Attempt to load the blogpost
|
||||
$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) {
|
||||
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Foud", true, 404);
|
||||
include_once($_SERVER["DOCUMENT_ROOT"]."/errors/404.php");
|
||||
|
@ -437,23 +522,49 @@ $blogPost->display_article();
|
|||
printf("<hr style=\"border-style: solid;\">");
|
||||
|
||||
// Display post comment form.
|
||||
printf("
|
||||
<article>
|
||||
<h2> Comments: </h2>
|
||||
<form method=\"post\" action=\"%s\">
|
||||
<input type=\"hidden\" name=\"blogpost_id\" 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,
|
||||
isset($_SESSION["current_user"]) ? $_SESSION["current_user"]->user_name :
|
||||
"Guest");
|
||||
|
||||
if(is_null($blogPost->address))
|
||||
{
|
||||
printf("
|
||||
<article>
|
||||
<h2> Comments: </h2>
|
||||
<form method=\"post\" action=\"%s\">
|
||||
<input type=\"hidden\" name=\"blogpost_id\" 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,
|
||||
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
|
||||
$blogPost->display_comments();
|
||||
|
||||
|
|
|
@ -6,8 +6,9 @@ include_once($COMMONS."/header.php");
|
|||
/**
|
||||
* 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){
|
||||
if(is_null($blogpost_addr)) {
|
||||
printf("
|
||||
<div class=\"blog-preview\">
|
||||
<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>
|
||||
</a>
|
||||
", $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%;\">
|
||||
<tr><td class=\"blog-tags\">");
|
||||
|
@ -53,8 +65,8 @@ function display_blog_previews($conn){
|
|||
}
|
||||
|
||||
// Prepare statement for selecting all the blogposts
|
||||
$stmt = $conn->prepare("SELECT blogpost_id, title, abstract, date_posted
|
||||
FROM blogposts ORDER BY date_posted DESC;");
|
||||
$stmt = $conn->prepare("SELECT blogpost_id, readable_address, title,
|
||||
abstract, date_posted FROM blogposts ORDER BY date_posted DESC;");
|
||||
|
||||
// Execute the statement
|
||||
$stmt->execute();
|
||||
|
@ -81,8 +93,9 @@ function display_blog_previews($conn){
|
|||
$tags_arr = $stmt->fetchall(PDO::FETCH_ASSOC);
|
||||
|
||||
// Display the blog
|
||||
display_blog_preview($blog["blogpost_id"], $blog["title"],
|
||||
$blog["abstract"], $blog["date_posted"], $tags_arr);
|
||||
display_blog_preview($blog["blogpost_id"], $blog["readable_address"],
|
||||
$blog["title"], $blog["abstract"], $blog["date_posted"],
|
||||
$tags_arr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,14 +68,16 @@ function remove_blogpost_tags($conn, $blogpost_id) {
|
|||
|
||||
/**
|
||||
* Publish a new blogpost and add the specified tags to it..
|
||||
* @param $conn Active Mysql connection.
|
||||
* @param $title Title for the blogpost.
|
||||
* @param $tagStr String with all the tags for the blogpost
|
||||
* (space-separated).
|
||||
* @param $abstract Abstract for the article.
|
||||
* @param $content Content of the article.
|
||||
* @param $conn Active Mysql connection.
|
||||
* @param $blogpost_addr Human-readable address of the edited blogpost.
|
||||
* @param $title Title for the blogpost.
|
||||
* @param $tagStr String with all the tags for the blogpost
|
||||
* (space-separated).
|
||||
* @param $abstract Abstract for 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
|
||||
$stmt = $conn->prepare("SELECT UUID()");
|
||||
$stmt->execute();
|
||||
|
@ -83,9 +85,11 @@ function publish_blogpost($conn, $title, $tagStr, $abstract, $content) {
|
|||
$blogpost_id = $result["UUID()"];
|
||||
|
||||
// Prepare, bind and execute the insert statement
|
||||
$stmt = $conn->prepare("INSERT INTO blogposts (blogpost_id, title, abstract,
|
||||
content) VALUES (:blogpost_id, :title, :abstract, :content);");
|
||||
$stmt = $conn->prepare("INSERT INTO blogposts (blogpost_id,
|
||||
readable_address, title, abstract, content) VALUES
|
||||
(:blogpost_id, :address, :title, :abstract, :content);");
|
||||
$stmt->bindParam(":blogpost_id", $blogpost_id);
|
||||
$stmt->bindParam(":address", $blogpost_addr);
|
||||
$stmt->bindParam(":title", $title);
|
||||
$stmt->bindParam(":abstract", $abstract);
|
||||
$stmt->bindParam(":content", $content);
|
||||
|
@ -98,20 +102,22 @@ function publish_blogpost($conn, $title, $tagStr, $abstract, $content) {
|
|||
/**
|
||||
* Update the blogpost content, title, abstract and date edited.
|
||||
* Then update the tags.
|
||||
* @param $conn Active Mysql connection.
|
||||
* @param $blogpost_id GUID of the edited blogpost.
|
||||
* @param $title Title for the blogpost.
|
||||
* @param $tagStr String with all the tags for the blogpost
|
||||
* (space-separated).
|
||||
* @param $abstract Abstract for the article.
|
||||
* @param $content Content of the article.
|
||||
* @param $conn Active Mysql connection.
|
||||
* @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 $tagStr String with all the tags for the blogpost
|
||||
* (space-separated).
|
||||
* @param $abstract Abstract for the article.
|
||||
* @param $content Content of the article.
|
||||
*/
|
||||
function update_blogpost($conn, $blogpost_id, $title, $tagStr, $abstract,
|
||||
$content) {
|
||||
function update_blogpost($conn, $blogpost_id, $blogpost_addr, $title,
|
||||
$tagStr, $abstract, $content) {
|
||||
// Prepare, bind and execute the update statement
|
||||
$stmt = $conn->prepare("UPDATE blogposts SET title = :title,
|
||||
abstract = :abstract, content = :content, date_edited = DEFAULT
|
||||
WHERE blogpost_id = :blogpost_id;");
|
||||
$stmt = $conn->prepare("UPDATE blogposts SET readable_address = :address,
|
||||
title = :title, abstract = :abstract, content = :content,
|
||||
date_edited = DEFAULT WHERE blogpost_id = :blogpost_id;");
|
||||
$stmt->bindParam(":address", $blogpost_addr);
|
||||
$stmt->bindParam(":title", $title);
|
||||
$stmt->bindParam(":abstract", $abstract);
|
||||
$stmt->bindParam(":content", $content);
|
||||
|
@ -140,16 +146,24 @@ if(isset($_POST["submit"])) {
|
|||
// over the content here and only trusted users should have access
|
||||
// to this section
|
||||
$title = $_POST["blogpost_title"];
|
||||
$address = $_POST["blogpost_address"];
|
||||
$tagsStr = $_POST["blogpost_tags"];
|
||||
$abstract = $_POST["article_abstract"];
|
||||
$content = $_POST["article_content"];
|
||||
|
||||
// If adress is empty, set it to null
|
||||
if(strcmp($address, "") == 0) {
|
||||
$address = null;
|
||||
}
|
||||
|
||||
if($_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 {
|
||||
publish_blogpost($conn, $title, $tagsStr, $abstract, $content);
|
||||
publish_blogpost($conn, $address, $title, $tagsStr, $abstract,
|
||||
$content);
|
||||
}
|
||||
|
||||
header("Location: "."http://www.zdenekborovec-dev.cz/blog");
|
||||
|
@ -159,7 +173,7 @@ if(isset($_GET["guid"])) {
|
|||
$blogId = sanitize_input($_GET["guid"]);
|
||||
|
||||
// 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");
|
||||
$stmt->bindParam(":blogpost_id", $blogId);
|
||||
$stmt->execute();
|
||||
|
@ -169,6 +183,7 @@ if(isset($_GET["guid"])) {
|
|||
// Set prefill values for the form
|
||||
$blogId_prefill = $blogId;
|
||||
$title_prefill = $result["title"];
|
||||
$address_prefill = $result["readable_address"];
|
||||
$abstract_prefill = $result["abstract"];
|
||||
$content_prefill = $result["content"];
|
||||
|
||||
|
@ -194,15 +209,30 @@ printf("
|
|||
<form method=\"post\" action=\"\">
|
||||
<input type=\"hidden\" name=\"blogpost_id\" value=\"%s\">
|
||||
|
||||
<label for=\"blogpost_title\">Post title:</label>
|
||||
<input type=\"text\" name=\"blogpost_title\" value=\"%s\"><br>
|
||||
|
||||
<label for=\"blogpost_tags\">Post tags:</label>
|
||||
<input type=\"text\" name=\"blogpost_tags\" value=\"%s\">
|
||||
|
||||
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. <br>
|
||||
<table class=\"noborder-table\">
|
||||
<tr><td style=\"padding: 0px 4px;\">
|
||||
<label for=\"blogpost_title\">Post title:</label>
|
||||
</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>
|
||||
</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\">
|
||||
<textarea name=\"article_abstract\" style=\"width: 100%%;
|
||||
|
@ -215,7 +245,7 @@ printf("
|
|||
<input name=\"submit\" type=\"submit\" value=\"Send File\">
|
||||
</form>
|
||||
</article>
|
||||
", $blogId_prefill, $title_prefill, $tagStr_prefill, $abstract_prefill,
|
||||
", $blogId_prefill, $title_prefill, $address_prefill, $tagStr_prefill, $abstract_prefill,
|
||||
$content_prefill);
|
||||
include_once($COMMONS."/footer.php");
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue