From a44711e57478c6f9d1fa38582deae72cad240560 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 6 Jul 2015 19:17:40 +0200 Subject: [ticket/13990] Reparse markup inside of forum rules/description PHPBB3-13990 --- phpBB/phpbb/textreparser/base.php | 25 ++++++--- .../textreparser/plugins/forum_description.php | 1 + phpBB/phpbb/textreparser/plugins/forum_rules.php | 1 + .../textreparser/plugins/group_description.php | 1 + phpBB/phpbb/textreparser/plugins/poll_option.php | 2 +- phpBB/phpbb/textreparser/plugins/poll_title.php | 2 +- tests/text_reparser/plugins/fixtures/forums.xml | 22 ++++++++ tests/text_reparser/plugins/fixtures/groups.xml | 8 +-- .../plugins/fixtures/poll_options.xml | 60 ++++++++++++++++++++++ tests/text_reparser/plugins/fixtures/polls.xml | 40 +++++++++++++-- tests/text_reparser/plugins/poll_option_test.php | 17 +++++- 11 files changed, 160 insertions(+), 19 deletions(-) diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 87a4268d0d..ed6c2376c7 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -47,11 +47,22 @@ abstract class base implements reparser_interface { if (!isset($record['enable_bbcode'], $record['enable_smilies'], $record['enable_magic_url'])) { - $record += array( - 'enable_bbcode' => $this->guess_bbcodes($record), - 'enable_smilies' => $this->guess_smilies($record), - 'enable_magic_url' => $this->guess_magic_url($record), - ); + if (isset($record['options'])) + { + $record += array( + 'enable_bbcode' => (bool) ($record['options'] & OPTION_FLAG_BBCODE), + 'enable_smilies' => (bool) ($record['options'] & OPTION_FLAG_SMILIES), + 'enable_magic_url' => (bool) ($record['options'] & OPTION_FLAG_LINKS), + ); + } + else + { + $record += array( + 'enable_bbcode' => $this->guess_bbcodes($record), + 'enable_smilies' => $this->guess_smilies($record), + 'enable_magic_url' => $this->guess_magic_url($record), + ); + } } // Those BBCodes are disabled based on context and user permissions and that value is never @@ -92,7 +103,7 @@ abstract class base implements reparser_interface } } - if (substr($record['text'], 0, 2) == '[/url] @@ -124,7 +135,7 @@ abstract class base implements reparser_interface } } - if (substr($record['text'], 0, 2) == '\\[/\\w+\\])', $match); diff --git a/phpBB/phpbb/textreparser/plugins/forum_description.php b/phpBB/phpbb/textreparser/plugins/forum_description.php index 7798e4b20b..0302dc3082 100644 --- a/phpBB/phpbb/textreparser/plugins/forum_description.php +++ b/phpBB/phpbb/textreparser/plugins/forum_description.php @@ -24,6 +24,7 @@ class forum_description extends \phpbb\textreparser\row_based_plugin 'id' => 'forum_id', 'text' => 'forum_desc', 'bbcode_uid' => 'forum_desc_uid', + 'options' => 'forum_desc_options', ); } diff --git a/phpBB/phpbb/textreparser/plugins/forum_rules.php b/phpBB/phpbb/textreparser/plugins/forum_rules.php index 57c666a556..ce550225f2 100644 --- a/phpBB/phpbb/textreparser/plugins/forum_rules.php +++ b/phpBB/phpbb/textreparser/plugins/forum_rules.php @@ -24,6 +24,7 @@ class forum_rules extends \phpbb\textreparser\row_based_plugin 'id' => 'forum_id', 'text' => 'forum_rules', 'bbcode_uid' => 'forum_rules_uid', + 'options' => 'forum_rules_options', ); } diff --git a/phpBB/phpbb/textreparser/plugins/group_description.php b/phpBB/phpbb/textreparser/plugins/group_description.php index ddd0e1d1c5..3346ccf25e 100644 --- a/phpBB/phpbb/textreparser/plugins/group_description.php +++ b/phpBB/phpbb/textreparser/plugins/group_description.php @@ -24,6 +24,7 @@ class group_description extends \phpbb\textreparser\row_based_plugin 'id' => 'group_id', 'text' => 'group_desc', 'bbcode_uid' => 'group_desc_uid', + 'options' => 'group_desc_options', ); } diff --git a/phpBB/phpbb/textreparser/plugins/poll_option.php b/phpBB/phpbb/textreparser/plugins/poll_option.php index 7b803146c4..44cacfae62 100644 --- a/phpBB/phpbb/textreparser/plugins/poll_option.php +++ b/phpBB/phpbb/textreparser/plugins/poll_option.php @@ -48,7 +48,7 @@ class poll_option extends \phpbb\textreparser\base */ protected function get_records_by_range($min_id, $max_id) { - $sql = 'SELECT o.topic_id, o.poll_option_id, o.poll_option_text AS text, p.bbcode_uid + $sql = 'SELECT o.topic_id, o.poll_option_id, o.poll_option_text AS text, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.bbcode_uid FROM ' . POLL_OPTIONS_TABLE . ' o, ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE o.topic_id BETWEEN ' . $min_id . ' AND ' . $max_id .' AND t.topic_id = o.topic_id diff --git a/phpBB/phpbb/textreparser/plugins/poll_title.php b/phpBB/phpbb/textreparser/plugins/poll_title.php index b447004527..038ae0c366 100644 --- a/phpBB/phpbb/textreparser/plugins/poll_title.php +++ b/phpBB/phpbb/textreparser/plugins/poll_title.php @@ -31,7 +31,7 @@ class poll_title extends \phpbb\textreparser\row_based_plugin */ protected function get_records_by_range_query($min_id, $max_id) { - $sql = 'SELECT t.topic_id AS id, t.poll_title AS text, p.bbcode_uid + $sql = 'SELECT t.topic_id AS id, t.poll_title AS text, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.bbcode_uid FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id BETWEEN ' . $min_id . ' AND ' . $max_id .' AND t.poll_max_options > 0 diff --git a/tests/text_reparser/plugins/fixtures/forums.xml b/tests/text_reparser/plugins/fixtures/forums.xml index 39c172c969..c12c8d6d48 100644 --- a/tests/text_reparser/plugins/fixtures/forums.xml +++ b/tests/text_reparser/plugins/fixtures/forums.xml @@ -5,87 +5,109 @@ forum_parents forum_desc forum_desc_uid + forum_desc_options forum_rules forum_rules_uid + forum_rules_options 1 This row should be [b]ignored[/b] abcd1234 + 0 This row should be [b]ignored[/b] abcd1234 + 0 2 [b]Not bold[/b] :) http://example.org abcd1234 + 0 [b]Not bold[/b] :) http://example.org abcd1234 + 0 3 [b:abcd1234]Bold[/b:abcd1234] :) http://example.org abcd1234 + 1 [b:abcd1234]Bold[/b:abcd1234] :) http://example.org abcd1234 + 1 4 :) http://example.org]]> abcd1234 + 2 :) http://example.org]]> abcd1234 + 2 5 http://example.org]]> abcd1234 + 4 http://example.org]]> abcd1234 + 4 6 abcd1234 + 1 abcd1234 + 1 7 abcd1234 + 0 abcd1234 + 0 8 abcd1234 + 1 abcd1234 + 1 9 abcd1234 + 0 abcd1234 + 0 1000 This row should be [b]ignored[/b] abcd1234 + 0 This row should be [b]ignored[/b] abcd1234 + 0 diff --git a/tests/text_reparser/plugins/fixtures/groups.xml b/tests/text_reparser/plugins/fixtures/groups.xml index d3df0131a3..15151426bc 100644 --- a/tests/text_reparser/plugins/fixtures/groups.xml +++ b/tests/text_reparser/plugins/fixtures/groups.xml @@ -38,25 +38,25 @@ 6 - 7 + 1 abcd1234 7 - 7 + 1 abcd1234 8 - 7 + 1 abcd1234 9 - 7 + 1 abcd1234 diff --git a/tests/text_reparser/plugins/fixtures/poll_options.xml b/tests/text_reparser/plugins/fixtures/poll_options.xml index c2fad9f764..48ba024315 100644 --- a/tests/text_reparser/plugins/fixtures/poll_options.xml +++ b/tests/text_reparser/plugins/fixtures/poll_options.xml @@ -29,6 +29,21 @@ 2 http://example.org]]> + + 1 + 11 + [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + + + 1 + 12 + :) http://example.org]]> + + + 1 + 13 + http://example.org]]> + 1 123 @@ -42,9 +57,39 @@ post_id + enable_bbcode + enable_smilies + enable_magic_urlpost_textbbcode_uid + 1 + 1 + 1 + 1 + + abcd1234 + + + 11 + 1 + 0 + 0 + + abcd1234 + + + 12 + 0 + 1 + 0 + + abcd1234 + + + 13 + 0 + 0 1 abcd1234 @@ -64,6 +109,21 @@ 1 This row should be [b]ignored[/b] + + 11 + 11 + BBCode + + + 12 + 12 + Smilies + + + 13 + 13 + Magic URLs + 123 1 diff --git a/tests/text_reparser/plugins/fixtures/polls.xml b/tests/text_reparser/plugins/fixtures/polls.xml index 9baf813c97..2960d640a9 100644 --- a/tests/text_reparser/plugins/fixtures/polls.xml +++ b/tests/text_reparser/plugins/fixtures/polls.xml @@ -2,9 +2,39 @@
post_id + enable_bbcode + enable_smilies + enable_magic_urlpost_textbbcode_uid + 1 + 0 + 0 + 0 + + abcd1234 + + + 2 + 1 + 0 + 0 + + abcd1234 + + + 3 + 0 + 1 + 0 + + abcd1234 + + + 4 + 0 + 0 1 abcd1234 @@ -26,22 +56,22 @@ 3 - 1 + 2 [b:abcd1234]Bold[/b:abcd1234] :) http://example.org 4 - 1 + 3 :) http://example.org]]> 5 - 1 + 4 http://example.org]]> 6 - 1 + 2 @@ -51,7 +81,7 @@ 8 - 1 + 2 diff --git a/tests/text_reparser/plugins/poll_option_test.php b/tests/text_reparser/plugins/poll_option_test.php index e043858597..acabda2146 100644 --- a/tests/text_reparser/plugins/poll_option_test.php +++ b/tests/text_reparser/plugins/poll_option_test.php @@ -49,7 +49,7 @@ class phpbb_textreparser_poll_option_test extends phpbb_database_test_case public function testReparse() { $reparser = $this->get_reparser(); - $reparser->reparse_range(2, 3); + $reparser->reparse_range(2, 13); $sql = 'SELECT topic_id, poll_option_id, poll_option_text FROM ' . POLL_OPTIONS_TABLE . ' @@ -84,6 +84,21 @@ class phpbb_textreparser_poll_option_test extends phpbb_database_test_case 'poll_option_id' => 3, 'poll_option_text' => 'http://example.org', ), + array( + 'topic_id' => 11, + 'poll_option_id' => 1, + 'poll_option_text' => '[b]Bold[/b] :) http://example.org', + ), + array( + 'topic_id' => 12, + 'poll_option_id' => 1, + 'poll_option_text' => '[b]Not bold[/b] :) http://example.org', + ), + array( + 'topic_id' => 13, + 'poll_option_id' => 1, + 'poll_option_text' => '[b]Not bold[/b] :) http://example.org', + ), array( 'topic_id' => 123, 'poll_option_id' => 1, -- cgit v1.2.1