From bc36d74bba93a719edc15286d48ba973097454c7 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 16 Nov 2015 23:05:45 +0100 Subject: [PATCH] r20151116 Signed-off-by: Flashwave --- _sakura/components/Forum.php | 16 ++++- _sakura/components/Forums.php | 14 ++++- _sakura/components/Post.php | 3 +- _sakura/components/Thread.php | 61 +++++++++++++++++++ _sakura/sakura.php | 2 +- .../templates/yuuno/elements/pagination.tpl | 22 ++++--- _sakura/templates/yuuno/forum/forumEntry.tpl | 2 +- _sakura/templates/yuuno/forum/posting.tpl | 11 +--- _sakura/templates/yuuno/forum/topicEntry.tpl | 2 +- public/content/data/yuuno/css/yuuno.css | 3 - public/posting.php | 17 +----- public/viewtopic.php | 6 ++ 12 files changed, 116 insertions(+), 43 deletions(-) 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) %}
- {% if paginationPage > 1 %} - - {% endif %} - {% for id,page in paginationPages %} - {{ id + 1 }} - {% endfor %} - {% if paginationPage < paginationPages|length %} - + {% if paginationPages|length > 1 %} + {% if paginationPage > 1 %} + + + {% endif %} + {% for id,page in paginationPages %} + {% if (id + 1) > (paginationPage - 3) and (id + 1) < (paginationPage + 3) %} + {{ id + 1 }} + {% endif %} + {% endfor %} + {% if paginationPage < paginationPages|length %} + + + {% endif %} {% endif %}
diff --git a/_sakura/templates/yuuno/forum/forumEntry.tpl b/_sakura/templates/yuuno/forum/forumEntry.tpl index 1848c12..1f6356b 100755 --- a/_sakura/templates/yuuno/forum/forumEntry.tpl +++ b/_sakura/templates/yuuno/forum/forumEntry.tpl @@ -1,5 +1,5 @@
-
+
diff --git a/_sakura/templates/yuuno/forum/posting.tpl b/_sakura/templates/yuuno/forum/posting.tpl index 762b83c..1c0f7b3 100755 --- a/_sakura/templates/yuuno/forum/posting.tpl +++ b/_sakura/templates/yuuno/forum/posting.tpl @@ -41,14 +41,9 @@
-
-
- - +
+ +
diff --git a/_sakura/templates/yuuno/forum/topicEntry.tpl b/_sakura/templates/yuuno/forum/topicEntry.tpl index a1343e9..6fc8f21 100755 --- a/_sakura/templates/yuuno/forum/topicEntry.tpl +++ b/_sakura/templates/yuuno/forum/topicEntry.tpl @@ -1,5 +1,5 @@ - +
diff --git a/public/content/data/yuuno/css/yuuno.css b/public/content/data/yuuno/css/yuuno.css index 7e490d8..579a0bd 100755 --- a/public/content/data/yuuno/css/yuuno.css +++ b/public/content/data/yuuno/css/yuuno.css @@ -1902,9 +1902,6 @@ textarea.inputStyling { .forum .topicList tbody .topicIcon { width: 40px; text-align: center; -} - -.forum .topicList tbody .topicIcon.read { color: #444; text-shadow: 0 0 5px #444; } diff --git a/public/posting.php b/public/posting.php index e9859bd..c053048 100755 --- a/public/posting.php +++ b/public/posting.php @@ -172,23 +172,8 @@ if ($mode != 'f') { // Check if a post is being made if (isset($_POST['post'])) { - // Set post mode - switch ($_POST['parseMode']) { - // BBcode - case '1': - $parse = '1'; - break; - // Markdown - case '2': - $parse = '2'; - break; - // Raw - default: - $parse = '0'; - } - // Attempt to make the post - $makePost = Forums::createPost($currentUser->id(), $_POST['subject'], $_POST['text'], $forumId, $topicId, $parse, 1, 1); + $makePost = Forums::createPost($currentUser->id(), $_POST['subject'], $_POST['text'], $forumId, $topicId, 1, 1, 1); // Add page specific things $renderData['page'] = [ diff --git a/public/viewtopic.php b/public/viewtopic.php index 7df7288..c067033 100755 --- a/public/viewtopic.php +++ b/public/viewtopic.php @@ -40,6 +40,12 @@ if (!$thread) { exit; } +// Update the tracking status +$thread->trackUpdate($currentUser->id()); + +// Update views +$thread->viewsUpdate(); + // Set additional render data $renderData = array_merge($renderData, [ 'thread' => $thread,