From 5c0314a75d2722bb99918ef44473f4204462835a Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Wed, 14 Apr 2021 17:23:56 -0600 Subject: Add 'date edited' attribute to posts --- includes/functions_insert.php | 4 ++-- model/Post.php | 15 +++++++++++---- model/Thread.php | 4 ++-- setup.sql | 3 ++- viewcategory.php | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/includes/functions_insert.php b/includes/functions_insert.php index e13b80e..4f60701 100644 --- a/includes/functions_insert.php +++ b/includes/functions_insert.php @@ -16,7 +16,7 @@ function insert_thread($dbc, $thread_subject, $thread_cat, $thread_author) { } function insert_post($dbc, $post_content, $post_thread, $post_author, $post_category) { - $sql = "INSERT INTO posts(post_content, post_date, post_thread, post_author) VALUES (?, CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), ?, ?);"; + $sql = "INSERT INTO posts(post_content, post_date_created, post_thread, post_author) VALUES (?, CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), ?, ?);"; $stmt = mysqli_stmt_init($dbc); if (!mysqli_stmt_prepare($stmt, $sql)) { @@ -32,4 +32,4 @@ function insert_post($dbc, $post_content, $post_thread, $post_author, $post_cate $sql = "UPDATE threads SET thread_date_lastpost = CONVERT_TZ(NOW(), 'SYSTEM', '+00:00') WHERE thread_id = " . $post_thread . ";"; mysqli_query($dbc, $sql); -} \ No newline at end of file +} diff --git a/model/Post.php b/model/Post.php index 5d85f20..d7aba72 100644 --- a/model/Post.php +++ b/model/Post.php @@ -25,13 +25,14 @@ function add_quote($dbc, $thread_id, $matches) { class Post { public $id; public $content; - public $date; + public $date_created; + public $date_edited; public $thread; public $author; function get_from_database($id, $dbc) { // TODO: Potential SQL injection risk? - $sql = "SELECT post_content, post_date, post_thread, post_author FROM posts WHERE post_id = " . mysqli_real_escape_string($dbc, $id); + $sql = "SELECT post_content, post_date_created, post_date_edited, post_thread, post_author FROM posts WHERE post_id = " . mysqli_real_escape_string($dbc, $id); $result = mysqli_query($dbc, $sql); if (!$result) { @@ -39,11 +40,13 @@ class Post { } if (mysqli_num_rows($result) == 0) { + return 0; } else { while ($row = mysqli_fetch_assoc($result)) { $this->id = $id; $this->content = $row['post_content']; - $this->date = $row['post_date']; + $this->date_created = $row['post_date_created']; + $this->date_edited = $row['post_date_edited']; $this->thread = new Thread(); $this->thread->get_from_database($row['post_thread'], $dbc); @@ -54,12 +57,16 @@ class Post { } mysqli_free_result($result); + return 1; } function display_content($dbc) { echo '