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 --- model/Post.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'model/Post.php') 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 '
#' . $this->id . ''; echo ' Posted by ' . $this->author->name . ''; - echo ' on ' . date('m/d/Y g:ia', strtotime($this->date)); + echo ' on ' . date('m/d/Y g:ia', strtotime($this->date_created)); + if (!is_null($this->date_edited)) { + echo ' edited ' . date('m/d/Y g:ia', strtotime($this->date_edited)) . ''; + } if (isset($_SESSION['signed_in']) && $_SESSION['user_id'] == $this->author->id) { echo ''; echo '[Edit] '; -- cgit v1.2.3