focus comment after posting
This commit is contained in:
parent
c8caf0dfac
commit
60d2a67620
1 changed files with 24 additions and 8 deletions
|
@ -19,7 +19,7 @@ class BlogpostComment
|
||||||
*/
|
*/
|
||||||
public function display_comment() {
|
public function display_comment() {
|
||||||
printf("
|
printf("
|
||||||
<div class=\"comment\">
|
<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>
|
||||||
|
@ -45,7 +45,9 @@ class BlogpostComment
|
||||||
</div>
|
</div>
|
||||||
<div class=\"comment-child-wrapper\">
|
<div class=\"comment-child-wrapper\">
|
||||||
",
|
",
|
||||||
$this->poster_name, date("Y-m-d H:i", strtotime($this->timestamp)),
|
$this->comment_id,
|
||||||
|
$this->poster_name,
|
||||||
|
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,
|
||||||
|
@ -232,15 +234,27 @@ class Blogpost
|
||||||
* If the poster is not signed in, send "NULL" (as a string) as the $posterID
|
* If the poster is not signed in, send "NULL" (as a string) as the $posterID
|
||||||
* The same goes for $parentId (that is the parent comment,
|
* The same goes for $parentId (that is the parent comment,
|
||||||
* if this one is a response)
|
* if this one is a response)
|
||||||
* Returns: error message string or null on success.
|
* Returns: GUID PK of the newly added comment.
|
||||||
*/
|
*/
|
||||||
function send_comment($conn, $blogId, $posterId, $content, $parentId) {
|
function send_comment($conn, $blogId, $posterId, $content, $parentId) {
|
||||||
|
// If content is empty, do not post
|
||||||
|
if(empty($content)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a uuid for the comment
|
||||||
|
$stmt = $conn->prepare("SELECT UUID()");
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
$uuid = $result["UUID()"];
|
||||||
|
|
||||||
// Prepare the statemtnt
|
// Prepare the statemtnt
|
||||||
$stmt = $conn->prepare("INSERT INTO blogpost_comments
|
$stmt = $conn->prepare("INSERT INTO blogpost_comments
|
||||||
( parent_id, blogpost_id, poster_id, content) VALUES
|
( comment_id, parent_id, blogpost_id, poster_id, content) VALUES
|
||||||
(:parent_id, :blogpost_id, :poster_id, :content);");
|
(:comment_id, :parent_id, :blogpost_id, :poster_id, :content);");
|
||||||
|
|
||||||
// Bind all the parameters
|
// Bind all the parameters
|
||||||
|
$stmt->bindValue(":comment_id", $uuid, PDO::PARAM_STR);
|
||||||
$stmt->bindValue(":parent_id", $parentId == "NULL"
|
$stmt->bindValue(":parent_id", $parentId == "NULL"
|
||||||
? NULL : $parentId, PDO::PARAM_STR);
|
? NULL : $parentId, PDO::PARAM_STR);
|
||||||
$stmt->bindValue(":blogpost_id", $blogId, PDO::PARAM_STR);
|
$stmt->bindValue(":blogpost_id", $blogId, PDO::PARAM_STR);
|
||||||
|
@ -251,7 +265,7 @@ function send_comment($conn, $blogId, $posterId, $content, $parentId) {
|
||||||
// Execute the statement
|
// Execute the statement
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
return null;
|
return $uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -378,10 +392,12 @@ if(isset($_POST["submit"])) {
|
||||||
$posterId = isset($_SESSION["current_user"]) ? $_SESSION["current_user"]->user_id : "NULL";
|
$posterId = isset($_SESSION["current_user"]) ? $_SESSION["current_user"]->user_id : "NULL";
|
||||||
|
|
||||||
// Try to send the comment
|
// Try to send the comment
|
||||||
send_comment($conn, $blogId, $posterId, $commentContent, $parentId);
|
$commentId = send_comment($conn, $blogId, $posterId,
|
||||||
|
$commentContent, $parentId);
|
||||||
|
|
||||||
// Redirect to this page with GET
|
// Redirect to this page with GET
|
||||||
header("Location: http://www.zdenekborovec-dev.cz/blog/article?guid=".$blogId);
|
header("Location: http://www.zdenekborovec-dev.cz/blog/article?guid=".
|
||||||
|
$blogId."#comment-".$commentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the blog id.
|
// Get the blog id.
|
||||||
|
|
Loading…
Reference in a new issue