diff --git a/_sakura/components/Forum.php b/_sakura/components/Forum.php index dd7a392..4cb73c7 100644 --- a/_sakura/components/Forum.php +++ b/_sakura/components/Forum.php @@ -19,17 +19,19 @@ class Forum public $category = 0; public $type = 0; public $icon = ""; - public $firstReply = []; - public $lastReply = []; + public $firstPost = null; + public $lastPost = null; + public $forums = []; + public $threads = []; // Constructor - public function __construct($forumId) + public function __construct($forumId = 0) { // Get the row from the database $forumRow = Database::fetch('forums', false, ['forum_id' => [$forumId, '=']]); // Populate the variables - if (!$forumRow) { + if ($forumRow) { $this->id = $forumRow['forum_id']; $this->name = $forumRow['forum_name']; $this->description = $forumRow['forum_desc']; @@ -37,19 +39,30 @@ class Forum $this->category = $forumRow['forum_category']; $this->type = $forumRow['forum_type']; $this->icon = $forumRow['forum_icon']; - } else { - // Else just set the ID to $forumId and imitate an blank forum - $this->id = $forumId; + } elseif ($forumId != 0) { + $this->id = -1; } + + // Populate the forums array + $this->forums = $this->getForums(); + + // and the threads array + $this->threads = $this->getThreads(); + + // and the first post + $this->firstPost = $this->getFirstPost(); + + // and finally the last post + $this->lastPost = $this->getLastPost(); } // Subforums - public function forums() + public function getForums() { // Get all rows with the category id set to the forum id $forumRows = Database::fetch('forums', true, ['forum_category' => [$this->id, '=']]); - // Get a storage array + // Create a storage array $forums = []; // Create new objects for each forum @@ -61,23 +74,59 @@ class Forum return $forums; } - // Last post - public function lastPost() + // Threads + public function getThreads() { - // Return a post - $postRow = Database::fetch('posts', false, ['forum_id' => [$this->id, '=']], ['post_id', true]); + // Get all rows with the forum id for this forum + $threadRows = Database::fetch('topics', true, ['forum_id' => [$this->id, '=']]); + // Create a storage array + $threads = []; + + // Create new objects for each thread + foreach ($threadRows as $thread) { + $threads[$thread['topic_id']] = new Thread($thread['topic_id']); + } + + // Return the thread objects + return $threads; + } + + // First post + public function getFirstPost() + { + // Get the row + $firstPost = Database::fetch('posts', false, ['forum_id' => [$this->id, '=']], ['post_id'], [1]); + + // Create the post object + $post = new Post(empty($firstPost) ? 0 : $firstPost['post_id']); + + // Return the post object + return $post; + } + + // Last post + public function getLastPost() + { + // Get the row + $lastPost = Database::fetch('posts', false, ['forum_id' => [$this->id, '=']], ['post_id', true], [1]); + + // Create the post object + $post = new Post(empty($lastPost) ? 0 : $lastPost['post_id']); + + // Return the post object + return $post; } // Thread count public function threadCount() { - return Database::count('topics', ['forum_id', [$this->id, '=']])[0]; + return Database::count('topics', ['forum_id' => [$this->id, '=']])[0]; } // Post count public function postCount() { - return Database::count('posts', ['forum_id', [$this->id, '=']])[0]; + return Database::count('posts', ['forum_id' => [$this->id, '=']])[0]; } } diff --git a/_sakura/components/Forums.php b/_sakura/components/Forums.php index b979614..45b3bb1 100755 --- a/_sakura/components/Forums.php +++ b/_sakura/components/Forums.php @@ -23,62 +23,6 @@ class Forums 'forum_topics' => 0, ]; - // Getting the forum list - public static function getForumList() - { - - // Get the content from the database - $forums = Database::fetch('forums'); - - // Create return array - $return = [ - 0 => [ - 'forum' => self::$emptyForum, - 'forums' => [], - ], - ]; - - // Resort the forums - foreach ($forums as $forum) { - // If the forum type is a category create a new one - if ($forum['forum_type'] == 1) { - $return[$forum['forum_id']]['forum'] = $forum; - } else { - // For link and reg. forum add it to the category - $return[$forum['forum_category']]['forums'][$forum['forum_id']] = $forum; - - // Get the topic count - $return[$forum['forum_category']]['forums'][$forum['forum_id']]['topic_count'] = - Database::count('topics', [ - 'forum_id' => [$forum['forum_id'], '='], - ])[0]; - - // Get the post count - $return[$forum['forum_category']]['forums'][$forum['forum_id']]['post_count'] = - Database::count('posts', [ - 'forum_id' => [$forum['forum_id'], '='], - ])[0]; - - // Get last post in forum - $lastPost = Database::fetch('posts', false, [ - 'forum_id' => [$forum['forum_id'], '='], - ], ['post_id', true]); - - // Add last poster data and the details about the post as well - $return[$forum['forum_category']]['forums'][$forum['forum_id']]['last_poster'] = new User($lastPost['poster_id']); - - // Add last poster data and the details about the post as well - $return[$forum['forum_category']]['forums'][$forum['forum_id']]['last_post'] = array_merge( - empty($lastPost) ? [] : $lastPost, - ['elapsed' => Main::timeElapsed($lastPost['post_time'])] - ); - } - } - - // Return the resorted data - return $return; - } - // Get a forum or category public static function getForum($id) { @@ -138,50 +82,6 @@ class Forums return $forum; } - // Getting all topics from a forum - public static function getTopics($id) - { - - // Get the topics from the database - $topics = Database::fetch('topics', true, [ - 'forum_id' => [$id, '='], - ]); - - // Get the userdata related to last posts - foreach ($topics as $key => $topic) { - // Get the reply count - $topics[$key]['reply_count'] = Database::count('posts', [ - 'topic_id' => [$topic['topic_id'], '='], - ])[0]; - - // Get first post in topics - $firstPost = Database::fetch('posts', false, [ - 'topic_id' => [$topic['topic_id'], '='], - ]); - - $topics[$key]['first_poster'] = new User($firstPost['poster_id']); - - $topics[$key]['first_post'] = array_merge( - empty($firstPost) ? [] : $firstPost, - ['elapsed' => Main::timeElapsed($firstPost['post_time'])] - ); - - // Get last post in topics - $lastPost = Database::fetch('posts', false, [ - 'topic_id' => [$topic['topic_id'], '='], - ], ['post_id', true]); - - $topics[$key]['last_poster'] = new User($lastPost['poster_id']); - - $topics[$key]['last_post'] = array_merge( - empty($lastPost) ? [] : $lastPost, - ['elapsed' => Main::timeElapsed($lastPost['post_time'])] - ); - } - - return $topics; - } - // Get posts of a thread public static function getTopic($id, $ignoreView = false) { diff --git a/_sakura/components/Main.php b/_sakura/components/Main.php index 8396d75..d729204 100755 --- a/_sakura/components/Main.php +++ b/_sakura/components/Main.php @@ -690,7 +690,7 @@ class Main } // Time elapsed - public static function timeElapsed($timestamp, $append = ' ago', $none = 'Just now', $floor = false) + public static function timeElapsed($timestamp, $append = ' ago', $none = 'Just now') { // Subtract the entered timestamp from the current timestamp diff --git a/_sakura/components/Post.php b/_sakura/components/Post.php index d1008f7..542fc2d 100644 --- a/_sakura/components/Post.php +++ b/_sakura/components/Post.php @@ -23,6 +23,7 @@ class Post public $emotes = 0; public $subject = ""; public $text = ""; + public $parsed = ""; public $editTime = 0; public $editReason = ""; public $editUser = []; @@ -50,5 +51,20 @@ class Post $this->editReason = $postRow['post_edit_reason']; $this->editUser = new User($postRow['post_edit_user']); } + + // Parse the markup + $this->parsed = Forums::parseMarkUp($this->text, $this->parse, $this->emotes); + } + + // Time elapsed since creation + public function timeElapsed() + { + return Main::timeElapsed($this->time); + } + + // Time elapsed since last edit + public function editTimeElapsed() + { + return Main::timeElapsed($this->editTime); } } diff --git a/_sakura/components/Thread.php b/_sakura/components/Thread.php index 1e41a1a..9797f95 100644 --- a/_sakura/components/Thread.php +++ b/_sakura/components/Thread.php @@ -22,6 +22,9 @@ class Thread public $status = 0; public $statusChange = 0; public $type = 0; + public $firstPost = null; + public $lastPost = null; + public $posts = []; // Constructor public function __construct($threadId) @@ -42,11 +45,50 @@ class Thread $this->statusChange = $threadRow['topic_status_change']; $this->type = $threadRow['topic_type']; } + + // Populate the posts array + $this->posts = $this->getPosts(); + + // Get first post + $this->firstPost = $this->posts ? array_values($this->posts)[0] : (new Thread(0)); + + // And the last post + $this->lastPost = $this->posts ? end($this->posts) : (new Thread(0)); + } + + // Posts + public function getPosts() + { + // Get all rows with the thread id + $postRows = Database::fetch('posts', true, ['topic_id' => [$this->id, '=']]); + + // Create a storage array + $posts = []; + + // Create new post objects for each post + foreach ($postRows as $post) { + $posts[$post['post_id']] = new Post($post['post_id']); + } + + // Return the post objects + return $posts; } // Reply count public function replyCount() { - return Database::count('posts', ['topic_id', [$this->id, '=']])[0]; + return Database::count('posts', ['topic_id' => [$this->id, '=']])[0]; + } + + // Time elapsed since creation + public function timeElapsed() + { + return Main::timeElapsed($this->time); + } + + // Time elapsed since status change + public function statusChangeElapsed() + { + return Main::timeElapsed($this->statusChange); } } diff --git a/_sakura/sakura.php b/_sakura/sakura.php index e5a0dd4..4846735 100755 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20151113'); +define('SAKURA_VERSION', '20151115'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_STABLE', false); @@ -152,6 +152,9 @@ if (!defined('SAKURA_NO_TPL')) { 'user' => $currentUser, 'urls' => $urls, + + 'get' => $_GET, + 'post' => $_POST, ]; // Site closing diff --git a/_sakura/templates/yuuno/elements/indexPanel.tpl b/_sakura/templates/yuuno/elements/indexPanel.tpl index 0897252..101b65d 100755 --- a/_sakura/templates/yuuno/elements/indexPanel.tpl +++ b/_sakura/templates/yuuno/elements/indexPanel.tpl @@ -1,7 +1,7 @@
- + | - {{ topic.topic_title }} + {{ thread.title }} | - {% if topic.first_poster.id %} - {{ topic.first_poster.username }} + {% if thread.firstPost.poster.id %} + {{ thread.firstPost.poster.username }} {% else %} [deleted user] {% endif %} |
- {{ topic.reply_count }}
- {{ topic.topic_views }}
+ {{ thread.replyCount }}
+ {{ thread.views }}
|
- {% if topic.last_poster.id %}
- {{ topic.last_poster.username }}
+ {% if thread.lastPost.poster.id %}
+ {{ thread.lastPost.poster.username }}
{% else %}
[deleted user]
- {% endif %} - {{ topic.last_post.elapsed }} + {% endif %} + {{ thread.lastPost.timeElapsed }} |
- {% if not post.user.checkPermission('SITE', 'DEACTIVATED') or post.user.checkPermission('SITE', 'RESTRICTED') %}{{ post.user.username }}
-
+ {% if not post.poster.checkPermission('SITE', 'DEACTIVATED') or post.poster.checkPermission('SITE', 'RESTRICTED') %}{{ post.poster.username }}
+
{% else %}
[deleted user]
{% endif %}
-
@@ -39,20 +39,20 @@
{% if not post.user.userTitle %}{{ post.rank.title }}{% else %}{{ post.user.userTitle }}{% endif %}
-
+ {{ post.poster.userTitle }}
+
{% if session.checkLogin %}
- {% if user.id == post.user.id %}
-
-
- {% elseif not post.user.checkPermission('SITE', 'DEACTIVATED') or post.user.checkPermission('SITE', 'RESTRICTED') %}
- {% if user.isFriends(post.user.id) != 0 %}
-
+ {% if user.id == post.poster.id %}
+
+
+ {% elseif not post.poster.checkPermission('SITE', 'DEACTIVATED') or post.poster.checkPermission('SITE', 'RESTRICTED') %}
+ {% if user.isFriends(post.poster.id) != 0 %}
+
{% endif %}
-
-
+
+
{% endif %}
-
+
{% endif %}
|
- {{ post.parsed_post|raw }}
+ {{ post.parsed|raw }}
- {% if post.user.signature and post.post_signature %}
+ {% if post.poster.signature and post.signature %}
- {{ post.user.signature|raw|nl2br }}
+ {{ post.poster.signature|raw|nl2br }}
{% endif %}
|
diff --git a/public/content/data/yuuno/css/yuuno.css b/public/content/data/yuuno/css/yuuno.css
index 4f5ad6a..7e490d8 100755
--- a/public/content/data/yuuno/css/yuuno.css
+++ b/public/content/data/yuuno/css/yuuno.css
@@ -1,4 +1,4 @@
-/*
+/*
* Sakura Yuuno Stylesheet
* By Flashwave