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', '

{param}

'); - $this->bbcode->addCodeDefinition($builder->build()); + self::$bbcode->addCodeDefinition($builder->build()); // Strike tag $builder = new CodeDefinitionBuilder('s', '{param}'); - $this->bbcode->addCodeDefinition($builder->build()); + self::$bbcode->addCodeDefinition($builder->build()); // Spoiler tag $builder = new CodeDefinitionBuilder('spoiler', '{param}'); - $this->bbcode->addCodeDefinition($builder->build()); + self::$bbcode->addCodeDefinition($builder->build()); // Box tag $builder = new CodeDefinitionBuilder('box', '
Click to open
'); - $this->bbcode->addCodeDefinition($builder->build()); + self::$bbcode->addCodeDefinition($builder->build()); // Box tag $builder = new CodeDefinitionBuilder('box', '
{option}
'); $builder->setUseOption(true); - $this->bbcode->addCodeDefinition($builder->build()); + self::$bbcode->addCodeDefinition($builder->build()); // Quote tag - $builder = new CodeDefinitionBuilder('quote', '
{param}
'); - $this->bbcode->addCodeDefinition($builder->build()); + $builder = new CodeDefinitionBuilder('quote', '
Quote
{param}
'); + self::$bbcode->addCodeDefinition($builder->build()); // Quote tag - $builder = new CodeDefinitionBuilder('quote', '
{option} wrote:
{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 @@
- {% for bbcode in posting.bbcodes %} - {% if bbcode.bbcode_display %} - - {% endif %} - {% endfor %} -
-
-
- Hover over a styling button to view a short description of what it does. + + + + + + + + + + +

@@ -29,27 +31,11 @@
{% for emoticon in posting.emoticons %} - {{ emoticon.emote_string }} + {{ emoticon.emote_string }} {% endfor %}

-
-
-
- -
-
- -
-
- -
-
-
-
-
-
diff --git a/_sakura/templates/yuuno/forum/viewtopic.tpl b/_sakura/templates/yuuno/forum/viewtopic.tpl index 8e69a2a..a846c40 100644 --- a/_sakura/templates/yuuno/forum/viewtopic.tpl +++ b/_sakura/templates/yuuno/forum/viewtopic.tpl @@ -5,18 +5,32 @@ {% set posts = thread.posts|batch(10) %} +{% if get.p and not get.page %} + {% set num = 0 %} + + {% for k,v in thread.posts %} + {% if k < get.p %} + {% set num = num + 1 %} + {% endif %} + {% endfor %} + + {% set num = (num / 10)|round + 1 %} + + {% set get = get|merge({'page': num}) %} +{% endif %} + {% set paginationPages = posts %} {% set paginationUrl %}{{ urls.format('FORUM_THREAD', [thread.id]) }}{% endset %} {% block title %}{{ thread.title }}{% endblock %} {% block css %} - + {% endblock %} {% block js %} - - + + {% endblock %} {% block content %} @@ -56,7 +70,7 @@
{{ post.timeElapsed }} diff --git a/public/content/data/yuuno/css/bbcode.css b/public/content/data/yuuno/css/bbcode.css index a4e3665..6555c86 100644 --- a/public/content/data/yuuno/css/bbcode.css +++ b/public/content/data/yuuno/css/bbcode.css @@ -3,6 +3,11 @@ */ @charset "utf-8"; +.bbcode { + line-height: 1.4; + word-wrap: break-word; +} + .bbcode h1 { text-shadow: 0 0 5px #8364A1; color: #614390; @@ -32,7 +37,9 @@ .bbcode blockquote > .quotee { font-weight: bold; border-bottom: 1px solid #9475b2; + border-right: 1px solid #9475b2; background: #B697d4; + padding-left: .5em; } .bbcode blockquote > .quote { @@ -71,3 +78,15 @@ .bbcode .spoiler-box-container > .spoiler-box-content { border-top: 1px solid #9475b2; } + +.bbcode img { + width: auto; + height: auto; + max-height: 100%; + max-width: 100%; +} + +.bbcode code { + font-size: 1.1em; +} + diff --git a/public/content/data/yuuno/css/yuuno.css b/public/content/data/yuuno/css/yuuno.css index 97b7b83..4e1d863 100644 --- a/public/content/data/yuuno/css/yuuno.css +++ b/public/content/data/yuuno/css/yuuno.css @@ -1950,7 +1950,7 @@ textarea.inputStyling { width: 100%; border-spacing: 0; table-layout: fixed; - word-break: break-all; + word-break: break-word; } .forum.viewtopic .posts td { @@ -2029,10 +2029,6 @@ textarea.inputStyling { float: right; } -.forum.viewtopic .posts .post-content img { - max-width: 850px; -} - .forum.viewtopic .posts .post-content .signature { border-top: 1px solid #B19EED; padding-top: 2px; diff --git a/public/content/data/yuuno/js/yuuno.js b/public/content/data/yuuno/js/yuuno.js index f53bc9f..dd2a767 100644 --- a/public/content/data/yuuno/js/yuuno.js +++ b/public/content/data/yuuno/js/yuuno.js @@ -810,6 +810,68 @@ function commentReply(id, session, category, action, avatar) { prepareAjaxForm(replyForm.id, 'Replying...'); } +// Inserting text into text box +// Borrowed from http://stackoverflow.com/questions/1064089/inserting-a-text-where-cursor-is-using-javascript-jquery +function insertText(areaId, text) { + var txtarea = document.getElementById(areaId); + var scrollPos = txtarea.scrollTop; + var strPos = 0; + var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? + "ff" : (document.selection ? "ie" : false)); + if (br == "ie") { + txtarea.focus(); + var range = document.selection.createRange(); + range.moveStart('character', -txtarea.value.length); + strPos = range.text.length; + } + else if (br == "ff") strPos = txtarea.selectionStart; + + var front = (txtarea.value).substring(0, strPos); + var back = (txtarea.value).substring(strPos, txtarea.value.length); + txtarea.value = front + text + back; + strPos = strPos + text.length; + if (br == "ie") { + txtarea.focus(); + var range = document.selection.createRange(); + range.moveStart('character', -txtarea.value.length); + range.moveStart('character', strPos); + range.moveEnd('character', 0); + range.select(); + } + else if (br == "ff") { + txtarea.selectionStart = strPos; + txtarea.selectionEnd = strPos; + txtarea.focus(); + } + txtarea.scrollTop = scrollPos; +} + +// Inserting a bbcode +function insertBBcode(textarea, tag, arg) { + var element = document.getElementById(textarea); + var before = "[" + tag + (arg ? "=" : "") + "]"; + var after = "[/" + tag + "]"; + + if (document.selection) { + element.focus(); + var sel = document.selection.createRange(); + sel.text = before + sel.text + after; + element.focus(); + } else if (element.selectionStart || element.selectionStart === 0) { + var startPos = element.selectionStart; + var endPos = element.selectionEnd; + var scrollTop = element.scrollTop; + element.value = element.value.substring(0, startPos) + before + element.value.substring(startPos, endPos) + after + element.value.substring(endPos, element.value.length); + element.focus(); + element.selectionStart = startPos + before.length; + element.selectionEnd = endPos + before.length; + element.scrollTop = scrollTop; + } else { + element.value += before + after; + element.focus(); + } +} + // Formatting money Number.prototype.formatMoney = function(u, c, k) { var f = this, diff --git a/public/posting.php b/public/posting.php index d9f9e4d..119538d 100644 --- a/public/posting.php +++ b/public/posting.php @@ -62,7 +62,7 @@ if ($mode != 'f') { $post = $thread['posts'][$_GET['p']]; // Add subject to render data - $posting['text'] = '[quote=' . (new User($post['poster_id']))->username() . ']' . (new BBcode($post['post_text']))->toEditor() . '[/quote]'; + $posting['text'] = '[quote=' . (new User($post['poster_id']))->username() . ']' . BBcode::toEditor($post['post_text']) . '[/quote]'; // Post editing } elseif ($mode == 'p' && isset($_GET['edit']) && $_GET['edit'] == $_GET['p'] && array_key_exists($_GET['p'], $thread['posts'])) { @@ -88,7 +88,7 @@ if ($mode != 'f') { // Set variables $posting = array_merge($posting, [ 'subject' => $post['post_subject'], - 'text' => (new BBcode($post['post_text']))->toEditor(), + 'text' => BBcode::toEditor($post['post_text']), 'id' => $post['post_id'], ]); // Post deletion