diff options
-rw-r--r-- | includes/functions_insert.php | 4 | ||||
-rw-r--r-- | model/Post.php | 15 | ||||
-rw-r--r-- | model/Thread.php | 4 | ||||
-rw-r--r-- | setup.sql | 3 | ||||
-rw-r--r-- | 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 '<div class="header" id="p' . $this->id . '"><b>#' . $this->id . '</b>'; echo ' Posted by <a href="viewuser.php?id='. $this->author->id . '">' . $this->author->name . '</a>'; - 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 ' <small>edited ' . date('m/d/Y g:ia', strtotime($this->date_edited)) . '</small>'; + } if (isset($_SESSION['signed_in']) && $_SESSION['user_id'] == $this->author->id) { echo '<span style="float:right;">'; echo '[<a href="includes/manage_post.php?action=edit&id=' . $this->id . '">Edit</a>] '; diff --git a/model/Thread.php b/model/Thread.php index aa48cfd..a9dc690 100644 --- a/model/Thread.php +++ b/model/Thread.php @@ -65,7 +65,7 @@ class Thread { } function get_latest_post($dbc) { - $sql = "SELECT post_id FROM posts WHERE post_thread = " . $this->id . " ORDER BY post_date DESC LIMIT 1"; + $sql = "SELECT post_id FROM posts WHERE post_thread = " . $this->id . " ORDER BY post_date_created DESC LIMIT 1"; $result = mysqli_query($dbc, $sql); if (!$result) { @@ -108,4 +108,4 @@ function get_all_threads($dbc) { mysqli_free_result($result); return $threads; -}
\ No newline at end of file +} @@ -31,7 +31,8 @@ CREATE TABLE threads ( CREATE TABLE posts ( post_id INT(8) NOT NULL AUTO_INCREMENT, post_content TEXT NOT NULL, - post_date DATETIME NOT NULL, + post_date_created DATETIME NOT NULL, + post_date_edited DATETIME, post_thread INT(8) NOT NULL, post_author INT(8) NOT NULL, PRIMARY KEY (post_id) diff --git a/viewcategory.php b/viewcategory.php index 0d69ed8..a10afce 100644 --- a/viewcategory.php +++ b/viewcategory.php @@ -59,7 +59,7 @@ if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) { echo '<small> by <b><a href="viewuser.php?id=' . $thread->author->id . '">' . $thread->author->name . '</a></b> on ' . date('M d, Y', strtotime($thread->date_created)) . '</small></td>'; if (!is_null($latest_post)) { - echo '<td>by <b><a href="viewuser.php?id=' . $latest_post->author->id . '">' . $latest_post->author->name . '</a></b><small> on ' . $latest_post->date . '</small></td>'; + echo '<td>by <b><a href="viewuser.php?id=' . $latest_post->author->id . '">' . $latest_post->author->name . '</a></b><small> on ' . $latest_post->date_created . '</small></td>'; } else { echo '<td>No posts yet!</td>'; } |