diff --git a/_sakura/components/Forum.php b/_sakura/components/Forum.php index 4cb73c7..6fddc7c 100644 --- a/_sakura/components/Forum.php +++ b/_sakura/components/Forum.php @@ -78,7 +78,7 @@ class Forum public function getThreads() { // Get all rows with the forum id for this forum - $threadRows = Database::fetch('topics', true, ['forum_id' => [$this->id, '=']]); + $threadRows = Database::fetch('topics', true, ['forum_id' => [$this->id, '=']], ['topic_last_reply', true]); // Create a storage array $threads = []; @@ -129,4 +129,18 @@ class Forum { return Database::count('posts', ['forum_id' => [$this->id, '=']])[0]; } + + // Read status + public function unread($user) + { + // Check each thread + foreach ($this->threads as $thread) { + if ($thread->unread($user)) { + return true; + } + } + + // Return false if negative + return false; + } } diff --git a/_sakura/components/Forums.php b/_sakura/components/Forums.php index 09e0b6c..4afb597 100755 --- a/_sakura/components/Forums.php +++ b/_sakura/components/Forums.php @@ -266,10 +266,8 @@ class Forums // Switch between modes switch ($mode) { case 1: - return Main::bbParse($text); - case 2: - return Main::mdParse($text); + return Main::bbParse($text); case 0: default: @@ -340,6 +338,16 @@ class Forums 'post_id' => [Database::lastInsertID(), '='], ]); + // Update the topic with the last details + Database::update('topics', [ + [ + 'topic_last_reply' => time(), + ], + [ + 'topic_id' => [$getPost['topic_id'], '='], + ], + ]); + // Return success return [1, 'SUCCESS', $getPost['forum_id'], $getPost['topic_id'], $getPost['post_id']]; } diff --git a/_sakura/components/Post.php b/_sakura/components/Post.php index 542fc2d..7d888b0 100644 --- a/_sakura/components/Post.php +++ b/_sakura/components/Post.php @@ -53,7 +53,8 @@ class Post } // Parse the markup - $this->parsed = Forums::parseMarkUp($this->text, $this->parse, $this->emotes); + $this->parsed = $this->parse ? Main::bbParse($this->text) : $this->text; + $this->parsed = $this->emotes ? Main::parseEmotes($this->parsed) : $this->parsed; } // Time elapsed since creation diff --git a/_sakura/components/Thread.php b/_sakura/components/Thread.php index 9797f95..a8cc582 100644 --- a/_sakura/components/Thread.php +++ b/_sakura/components/Thread.php @@ -91,4 +91,65 @@ class Thread { return Main::timeElapsed($this->statusChange); } + + // Read status + public function unread($user) + { + // Attempt to get track row from the database + $track = Database::fetch('topics_track', false, ['user_id' => [$user, '='], 'topic_id' => [$this->id, '=']]); + + // If nothing was returned it's obvious that the status is unread + if (!$track) { + return true; + } + + // Check if the last time the user has been here is less than the creation timestamp of the latest post + if ($track['mark_time'] < $this->lastPost->time) { + return true; + } + + // Else just return false meaning everything is read + return false; + } + + // Update read status + public function trackUpdate($user) + { + // Check if we already have a track record + $track = Database::fetch('topics_track', false, ['user_id' => [$user, '='], 'topic_id' => [$this->id, '='], 'forum_id' => [$this->forum, '=']]); + + // If so update it + if ($track) { + Database::update('topics_track', [ + [ + 'mark_time' => time(), + ], + [ + 'user_id' => [$user, '='], + 'topic_id' => [$this->id, '='], + ], + ]); + } else { + // If not create a new record + Database::insert('topics_track', [ + 'user_id' => $user, + 'topic_id' => $this->id, + 'forum_id' => $this->forum, + 'mark_time' => time(), + ]); + } + } + + // Update views + public function viewsUpdate() + { + Database::update('topics', [ + [ + 'topic_views' => $this->views + 1, + ], + [ + 'topic_id' => [$this->id, '='], + ], + ]); + } } diff --git a/_sakura/sakura.php b/_sakura/sakura.php index 4846735..c49dc54 100755 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20151115'); +define('SAKURA_VERSION', '20151116'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_STABLE', false); diff --git a/_sakura/templates/yuuno/elements/pagination.tpl b/_sakura/templates/yuuno/elements/pagination.tpl index bc5e63c..54a3ba8 100755 --- a/_sakura/templates/yuuno/elements/pagination.tpl +++ b/_sakura/templates/yuuno/elements/pagination.tpl @@ -2,13 +2,19 @@ {% set paginationPage = get.page|default(1) %}