diff --git a/_sakura/components/BBcode.php b/_sakura/components/BBcode.php index 8ae4663..7c4c3c2 100644 --- a/_sakura/components/BBcode.php +++ b/_sakura/components/BBcode.php @@ -16,58 +16,53 @@ use JBBCode\CodeDefinitionBuilder; class BBcode { // Parser container - private $bbcode; + private static $bbcode = null; // Constructor - public function __construct($text = null) + public static function init() { // Create new parser class - $this->bbcode = new Parser(); + self::$bbcode = new Parser(); // Add the standard definitions - $this->loadStandardCodes(); - - // Immediately parse the text if set - if ($text != null) { - $this->bbcode->parse($text); - } + self::loadStandardCodes(); } // Add basic bbcodes - public function loadStandardCodes() + public static function loadStandardCodes() { // Add the standard definitions - $this->bbcode->addCodeDefinitionSet(new DefaultCodeDefinitionSet()); + self::$bbcode->addCodeDefinitionSet(new DefaultCodeDefinitionSet()); // Header tag $builder = new CodeDefinitionBuilder('header', '
'); - $this->bbcode->addCodeDefinition($builder->build()); + $builder = new CodeDefinitionBuilder('quote', '{param}
'); + self::$bbcode->addCodeDefinition($builder->build()); // Quote tag - $builder = new CodeDefinitionBuilder('quote', 'Quote{param}
'); + $builder = new CodeDefinitionBuilder('quote', '{option} wrote:{param}
'); $builder->setUseOption(true); - $this->bbcode->addCodeDefinition($builder->build()); + self::$bbcode->addCodeDefinition($builder->build()); // Add special definitions (PHP files MUST have the same name as the definition class foreach (glob(ROOT . '_sakura/components/BBcodeDefinitions/*.php') as $ext) { @@ -83,20 +78,30 @@ class BBcode $className = __NAMESPACE__ . '\\' . $ext; // Add the BBcode definition - $this->bbcode->addCodeDefinition(new $className); + self::$bbcode->addCodeDefinition(new $className); } } // Set text - public function text($text) + public static function text($text) { - $this->bbcode->parse($text); + // Check if $bbcode is still null + if (self::$bbcode == null) { + self::init(); + } + + self::$bbcode->parse($text); } // Get as HTML - public function toHTML() + public static function toHTML($text = null) { - $parsed = nl2br($this->bbcode->getAsHtml()); + // Check if text isn't null + if ($text !== null) { + self::text($text); + } + + $parsed = nl2br(self::$bbcode->getAsHtml()); $parsed = Main::fixCodeTags($parsed); $parsed = Main::parseEmotes($parsed); @@ -105,14 +110,24 @@ class BBcode } // Get as BBmarkup - public function toEditor() + public static function toEditor($text = null) { - return $this->bbcode->getAsBBCode(); + // Check if text isn't null + if ($text !== null) { + self::text($text); + } + + return self::$bbcode->getAsBBCode(); } // Get as plaintext - public function toPlain() + public static function toPlain($text = null) { - return $this->bbcode->getAsText(); + // Check if text isn't null + if ($text !== null) { + self::text($text); + } + + return self::$bbcode->getAsText(); } } diff --git a/_sakura/components/DBWrapper/mysql.php b/_sakura/components/DBWrapper/mysql.php index fed6ecd..43c25b7 100644 --- a/_sakura/components/DBWrapper/mysql.php +++ b/_sakura/components/DBWrapper/mysql.php @@ -376,6 +376,5 @@ class mysql public function lastInsertID($name = null) { return $this->sql->lastInsertID($name); - ; } } diff --git a/_sakura/components/Forum/Forums.php b/_sakura/components/Forum/Forums.php index 20975ef..e794d45 100644 --- a/_sakura/components/Forum/Forums.php +++ b/_sakura/components/Forum/Forums.php @@ -209,7 +209,7 @@ class Forums 'user' => (new User($post['poster_id'])), 'elapsed' => Main::timeElapsed($post['post_time']), 'is_op' => ($post['poster_id'] == $firstPost['poster_id'] ? '1' : '0'), - 'parsed_post' => (new BBcode($post['post_text']))->toHTML(), + 'parsed_post' => BBcode::toHTML($post['post_text']), ]); // Just in case diff --git a/_sakura/components/Forum/Post.php b/_sakura/components/Forum/Post.php index 705eb86..59a87bb 100644 --- a/_sakura/components/Forum/Post.php +++ b/_sakura/components/Forum/Post.php @@ -56,7 +56,7 @@ class Post } // Parse the markup - $this->parsed = (new BBcode(htmlentities($this->text)))->toHTML(); + $this->parsed = BBcode::toHTML(htmlentities($this->text)); } // Time elapsed since creation diff --git a/_sakura/components/Forum/Posting.php b/_sakura/components/Forum/Posting.php new file mode 100644 index 0000000..bc4fa23 --- /dev/null +++ b/_sakura/components/Forum/Posting.php @@ -0,0 +1,23 @@ +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() + public function posts() { - // Get all rows with the thread id - $postRows = Database::fetch('posts', true, ['topic_id' => [$this->id, '=']]); + // Check if _posts is something + if (!count($this->_posts)) { - // Create a storage array - $posts = []; + // Get all rows with the thread id + $postRows = Database::fetch('posts', true, ['topic_id' => [$this->id, '=']]); - // Create new post objects for each post - foreach ($postRows as $post) { - $posts[$post['post_id']] = new Post($post['post_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']); + } + + $this->_posts = $posts; + } else { + $posts = $this->_posts; } // Return the post objects return $posts; } + // Get the opening post + public function firstPost() { + return $this->posts() ? array_values($this->_posts)[0] : (new Post(0)); + } + + // Get the last reply + public function lastPost() { + return $this->posts() ? end($this->_posts) : (new Post(0)); + } + // Reply count public function replyCount() { @@ -106,7 +114,7 @@ class Thread } // 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) { + if ($track['mark_time'] < $this->lastPost()->time) { return true; } diff --git a/_sakura/components/User.php b/_sakura/components/User.php index 7f5451e..5038b78 100644 --- a/_sakura/components/User.php +++ b/_sakura/components/User.php @@ -659,11 +659,11 @@ class User public function signature() { return isset($this->data['user_data']['signature']) ? - (new BBcode( + BBcode::toHTML( base64_decode( $this->data['user_data']['signature'] ) - ))->toHTML() : + ) : null; } diff --git a/_sakura/sakura.php b/_sakura/sakura.php index b277db8..9cbb26f 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20151202'); +define('SAKURA_VERSION', '20151203'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_STABLE', false); diff --git a/_sakura/templates/yuuno/forum/posting.tpl b/_sakura/templates/yuuno/forum/posting.tpl index 1c0f7b3..b887553 100644 --- a/_sakura/templates/yuuno/forum/posting.tpl +++ b/_sakura/templates/yuuno/forum/posting.tpl @@ -12,15 +12,17 @@{option} wrote{param}