From de52580a78bcab47a2311f3993fd9952f963d563 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 1 May 2015 05:15:56 +0200 Subject: [PATCH 01/27] [ticket/13803] WIP implementation PHPBB3-13803 --- .../container/services_text_reparser.yml | 63 ++++++++++++ phpBB/phpbb/textreparser/base.php | 97 +++++++++++++++++++ phpBB/phpbb/textreparser/forumdescription.php | 63 ++++++++++++ phpBB/phpbb/textreparser/forumrules.php | 63 ++++++++++++ phpBB/phpbb/textreparser/groupdescription.php | 63 ++++++++++++ phpBB/phpbb/textreparser/pmtext.php | 56 +++++++++++ phpBB/phpbb/textreparser/posttext.php | 56 +++++++++++ .../phpbb/textreparser/reparser_interface.php | 32 ++++++ tests/text_reparser/fixtures/posts.xml | 19 ++++ tests/text_reparser/posttext_test.php | 67 +++++++++++++ 10 files changed, 579 insertions(+) create mode 100644 phpBB/config/default/container/services_text_reparser.yml create mode 100644 phpBB/phpbb/textreparser/base.php create mode 100644 phpBB/phpbb/textreparser/forumdescription.php create mode 100644 phpBB/phpbb/textreparser/forumrules.php create mode 100644 phpBB/phpbb/textreparser/groupdescription.php create mode 100644 phpBB/phpbb/textreparser/pmtext.php create mode 100644 phpBB/phpbb/textreparser/posttext.php create mode 100644 phpBB/phpbb/textreparser/reparser_interface.php create mode 100644 tests/text_reparser/fixtures/posts.xml create mode 100644 tests/text_reparser/posttext_test.php diff --git a/phpBB/config/default/container/services_text_reparser.yml b/phpBB/config/default/container/services_text_reparser.yml new file mode 100644 index 0000000000..3113c02f6d --- /dev/null +++ b/phpBB/config/default/container/services_text_reparser.yml @@ -0,0 +1,63 @@ +services: + text_reparser.admin_contact_info: + class: phpbb\textreparser\admincontactinfo + arguments: + - @dbal.conn + tags: + - { name: text_reparser.plugin } + + text_reparser.forum_description: + class: phpbb\textreparser\forumdescription + arguments: + - @dbal.conn + tags: + - { name: text_reparser.plugin } + + text_reparser.forum_rules: + class: phpbb\textreparser\forumrules + arguments: + - @dbal.conn + tags: + - { name: text_reparser.plugin } + + text_reparser.group_description: + class: phpbb\textreparser\groupdescription + arguments: + - @dbal.conn + tags: + - { name: text_reparser.plugin } + + text_reparser.pm_text: + class: phpbb\textreparser\pmtext + arguments: + - @dbal.conn + tags: + - { name: text_reparser.plugin } + + text_reparser.poll_option: + class: phpbb\textreparser\polloption + arguments: + - @dbal.conn + tags: + - { name: text_reparser.plugin } + + text_reparser.poll_title: + class: phpbb\textreparser\polltitle + arguments: + - @dbal.conn + tags: + - { name: text_reparser.plugin } + + text_reparser.post_text: + class: phpbb\textreparser\posttext + arguments: + - @dbal.conn + tags: + - { name: text_reparser.plugin } + + text_reparser.user_signature: + class: phpbb\textreparser\usersignature + arguments: + - @dbal.conn + tags: + - { name: text_reparser.plugin } diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php new file mode 100644 index 0000000000..6aa20d0015 --- /dev/null +++ b/phpBB/phpbb/textreparser/base.php @@ -0,0 +1,97 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser; + +abstract class base implements reparser_interface +{ + /** + * @var \phpbb\db\driver\driver_interface + */ + protected $db; + + /** + * Constructor + * + * @param \phpbb\db\driver\driver_interface $db Database connection + */ + public function __construct(\phpbb\db\driver\driver_interface $db) + { + $this->db = $db; + } + + /** + * {@inheritdoc} + */ + abstract public function get_max_id(); + + /** + * Return all records in given range + * + * @param integer $min_id Lower bound + * @param integer $max_id Upper bound + * @return array Array of record + */ + abstract protected function get_records($min_id, $max_id); + + /** + * {@inheritdoc} + */ + public function reparse_range($min_id, $max_id) + { + foreach ($this->get_records($min_id, $max_id) as $record) + { + $this->reparse_record($record); + } + } + + /** + * Reparse given record + * + * @param array $record Associative array containing the record's data + */ + protected function reparse_record(array $record) + { + $unparsed = array_merge( + $record, + generate_text_for_edit( + $record['text'], + $record['bbcode_uid'], + OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES | OPTION_FLAG_LINKS + ) + ); + $bitfield = $flags = null; + $parsed_text = $unparsed['text']; + generate_text_for_storage( + $parsed_text, + $unparsed['bbcode_uid'], + $bitfield, + $flags, + $unparsed['enable_bbcode'], + $unparsed['enable_smilies'], + $unparsed['enable_magic_url'] + ); + + // Save the new text if it has changed + if ($parsed_text !== $record['text']) + { + $record['text'] = $parsed_text; + $this->save_record($record); + } + } + + /** + * {@inheritdoc} + */ + abstract protected function save_record(array $record); +} diff --git a/phpBB/phpbb/textreparser/forumdescription.php b/phpBB/phpbb/textreparser/forumdescription.php new file mode 100644 index 0000000000..b715abd825 --- /dev/null +++ b/phpBB/phpbb/textreparser/forumdescription.php @@ -0,0 +1,63 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser; + +class forumdescription extends base +{ + /** + * {@inheritdoc} + */ + public function get_max_id() + { + $sql = 'SELECT MAX(forum_id) AS max_id FROM ' . FORUMS_TABLE; + $result = $this->db->sql_query($sql); + $max_id = (int) $this->db->sql_fetchfield('max_id'); + $this->db->sql_freeresult($result); + + return $max_id; + } + + /** + * {@inheritdoc} + */ + protected function get_records($min_id, $max_id) + { + $sql = 'SELECT forum_id AS id, forum_desc AS text, forum_desc_uid AS bbcode_uid + FROM ' . FORUMS_TABLE . ' + WHERE forum_id BETWEEN ' . $min_id . ' AND ' . $max_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Those fields are not saved to the database, we need to guess their original value + $row['enable_bbcode'] = !empty($row['bbcode_uid']); + $row['enable_smilies'] = (strpos($row['text'], '') !== false); + } + $records = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $records; + } + + /** + * {@inheritdoc} + */ + protected function save_record(array $record) + { + $sql = 'UPDATE ' . FORUMS_TABLE . " + SET forum_desc = '" . $this->db->sql_escape($record['text']) . "' + WHERE forum_id = " . $record['id']; + $this->db->sql_query($sql); + } +} diff --git a/phpBB/phpbb/textreparser/forumrules.php b/phpBB/phpbb/textreparser/forumrules.php new file mode 100644 index 0000000000..c0538f6cce --- /dev/null +++ b/phpBB/phpbb/textreparser/forumrules.php @@ -0,0 +1,63 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser; + +class forumrules extends base +{ + /** + * {@inheritdoc} + */ + public function get_max_id() + { + $sql = 'SELECT MAX(forum_id) AS max_id FROM ' . FORUMS_TABLE; + $result = $this->db->sql_query($sql); + $max_id = (int) $this->db->sql_fetchfield('max_id'); + $this->db->sql_freeresult($result); + + return $max_id; + } + + /** + * {@inheritdoc} + */ + protected function get_records($min_id, $max_id) + { + $sql = 'SELECT forum_id AS id, forum_rules AS text, forum_rules_uid AS bbcode_uid + FROM ' . FORUMS_TABLE . ' + WHERE forum_id BETWEEN ' . $min_id . ' AND ' . $max_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Those fields are not saved to the database, we need to guess their original value + $row['enable_bbcode'] = !empty($row['bbcode_uid']); + $row['enable_smilies'] = (strpos($row['text'], '') !== false); + } + $records = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $records; + } + + /** + * {@inheritdoc} + */ + protected function save_record(array $record) + { + $sql = 'UPDATE ' . FORUMS_TABLE . " + SET forum_rules = '" . $this->db->sql_escape($record['text']) . "' + WHERE forum_id = " . $record['id']; + $this->db->sql_query($sql); + } +} diff --git a/phpBB/phpbb/textreparser/groupdescription.php b/phpBB/phpbb/textreparser/groupdescription.php new file mode 100644 index 0000000000..608cc806b6 --- /dev/null +++ b/phpBB/phpbb/textreparser/groupdescription.php @@ -0,0 +1,63 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser; + +class groupdescription extends base +{ + /** + * {@inheritdoc} + */ + public function get_max_id() + { + $sql = 'SELECT MAX(group_id) AS max_id FROM ' . GROUPS_TABLE; + $result = $this->db->sql_query($sql); + $max_id = (int) $this->db->sql_fetchfield('max_id'); + $this->db->sql_freeresult($result); + + return $max_id; + } + + /** + * {@inheritdoc} + */ + protected function get_records($min_id, $max_id) + { + $sql = 'SELECT group_id AS id, group_desc AS text, group_desc_uid AS bbcode_uid + FROM ' . GROUPS_TABLE . ' + WHERE group_id BETWEEN ' . $min_id . ' AND ' . $max_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Those fields are not saved to the database, we need to guess their original value + $row['enable_bbcode'] = !empty($row['bbcode_uid']); + $row['enable_smilies'] = (strpos($row['text'], '') !== false); + } + $records = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $records; + } + + /** + * {@inheritdoc} + */ + protected function save_record(array $record) + { + $sql = 'UPDATE ' . GROUPS_TABLE . " + SET group_desc = '" . $this->db->sql_escape($record['text']) . "' + WHERE group_id = " . $record['id']; + $this->db->sql_query($sql); + } +} diff --git a/phpBB/phpbb/textreparser/pmtext.php b/phpBB/phpbb/textreparser/pmtext.php new file mode 100644 index 0000000000..e1b27e60fe --- /dev/null +++ b/phpBB/phpbb/textreparser/pmtext.php @@ -0,0 +1,56 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser; + +class pmtext extends base +{ + /** + * {@inheritdoc} + */ + public function get_max_id() + { + $sql = 'SELECT MAX(msg_id) AS max_id FROM ' . PRIVMSGS_TABLE; + $result = $this->db->sql_query($sql); + $max_id = (int) $this->db->sql_fetchfield('max_id'); + $this->db->sql_freeresult($result); + + return $max_id; + } + + /** + * {@inheritdoc} + */ + protected function get_records($min_id, $max_id) + { + $sql = 'SELECT msg_id AS id, enable_bbcode, enable_smilies, enable_magic_url, message_text AS text, bbcode_uid + FROM ' . PRIVMSGS_TABLE . ' + WHERE msg_id BETWEEN ' . $min_id . ' AND ' . $max_id; + $result = $this->db->sql_query($sql); + $records = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $records; + } + + /** + * {@inheritdoc} + */ + protected function save_record(array $record) + { + $sql = 'UPDATE ' . PRIVMSGS_TABLE . " + SET message_text = '" . $this->db->sql_escape($record['text']) . "' + WHERE msg_id = " . $record['id']; + $this->db->sql_query($sql); + } +} diff --git a/phpBB/phpbb/textreparser/posttext.php b/phpBB/phpbb/textreparser/posttext.php new file mode 100644 index 0000000000..916fc94bfa --- /dev/null +++ b/phpBB/phpbb/textreparser/posttext.php @@ -0,0 +1,56 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser; + +class posttext extends base +{ + /** + * {@inheritdoc} + */ + public function get_max_id() + { + $sql = 'SELECT MAX(post_id) AS max_id FROM ' . POSTS_TABLE; + $result = $this->db->sql_query($sql); + $max_id = (int) $this->db->sql_fetchfield('max_id'); + $this->db->sql_freeresult($result); + + return $max_id; + } + + /** + * {@inheritdoc} + */ + protected function get_records($min_id, $max_id) + { + $sql = 'SELECT post_id AS id, enable_bbcode, enable_smilies, enable_magic_url, post_text AS text, bbcode_uid + FROM ' . POSTS_TABLE . ' + WHERE post_id BETWEEN ' . $min_id . ' AND ' . $max_id; + $result = $this->db->sql_query($sql); + $records = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $records; + } + + /** + * {@inheritdoc} + */ + protected function save_record(array $record) + { + $sql = 'UPDATE ' . POSTS_TABLE . " + SET post_text = '" . $this->db->sql_escape($record['text']) . "' + WHERE post_id = " . $record['id']; + $this->db->sql_query($sql); + } +} diff --git a/phpBB/phpbb/textreparser/reparser_interface.php b/phpBB/phpbb/textreparser/reparser_interface.php new file mode 100644 index 0000000000..20f8d92b1a --- /dev/null +++ b/phpBB/phpbb/textreparser/reparser_interface.php @@ -0,0 +1,32 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser; + +interface reparser_interface +{ + /** + * Return the highest ID for all existing records + * + * @return integer + */ + public function get_max_id(); + + /** + * Reparse all records in given range + * + * @param integer $min_id Lower bound + * @param integer $max_id Upper bound + */ + public function reparse_range($min_id, $max_id); +} diff --git a/tests/text_reparser/fixtures/posts.xml b/tests/text_reparser/fixtures/posts.xml new file mode 100644 index 0000000000..6485293361 --- /dev/null +++ b/tests/text_reparser/fixtures/posts.xml @@ -0,0 +1,19 @@ + + + + post_id + enable_bbcode + enable_smilies + enable_magic_url + post_text + bbcode_uid + + 1 + 1 + 1 + 1 + Plain text + abcd1234 + +
+
diff --git a/tests/text_reparser/posttext_test.php b/tests/text_reparser/posttext_test.php new file mode 100644 index 0000000000..4dec53dc63 --- /dev/null +++ b/tests/text_reparser/posttext_test.php @@ -0,0 +1,67 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; + +class phpbb_textreparser_posttext_test extends phpbb_database_test_case +{ + public function setUp() + { + global $config; + if (!isset($config)) + { + $config = new \phpbb\config\config(array()); + } + $this->get_test_case_helpers()->set_s9e_services(); + parent::setUp(); + } + + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/posts.xml'); + } + + /** + * @dataProvider getReparseTests + */ + public function testReparse($min_id, $max_id, $expected) + { + $db = $this->new_dbal(); + $reparser = new \phpbb\textreparser\posttext($db); + $reparser->reparse_range($min_id, $max_id); + $sql = 'SELECT post_id, post_text + FROM ' . POSTS_TABLE . " + WHERE post_id BETWEEN $min_id AND $max_id"; + $result = $db->sql_query($sql); + $rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + $this->assertEquals($expected, $rows); + } + + public function getReparseTests() + { + return array( + array( + 1, + 1, + array( + array( + 'post_id' => 1, + 'post_text' => 'Plain text' + ) + ) + ), + ); + } +} From e11ae7e9cd5573658b763b1ef72cb889f547f2dd Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 1 May 2015 05:32:48 +0200 Subject: [PATCH 02/27] [ticket/13803] Hyphenated class names PHPBB3-13803 --- .../container/services_text_reparser.yml | 18 +++++++++--------- ...umdescription.php => forum_description.php} | 2 +- .../{forumrules.php => forum_rules.php} | 2 +- ...updescription.php => group_description.php} | 2 +- .../textreparser/{pmtext.php => pm_text.php} | 2 +- .../{posttext.php => post_text.php} | 2 +- .../{posttext_test.php => post_text_test.php} | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) rename phpBB/phpbb/textreparser/{forumdescription.php => forum_description.php} (97%) rename phpBB/phpbb/textreparser/{forumrules.php => forum_rules.php} (98%) rename phpBB/phpbb/textreparser/{groupdescription.php => group_description.php} (97%) rename phpBB/phpbb/textreparser/{pmtext.php => pm_text.php} (97%) rename phpBB/phpbb/textreparser/{posttext.php => post_text.php} (97%) rename tests/text_reparser/{posttext_test.php => post_text_test.php} (91%) diff --git a/phpBB/config/default/container/services_text_reparser.yml b/phpBB/config/default/container/services_text_reparser.yml index 3113c02f6d..c458be12ac 100644 --- a/phpBB/config/default/container/services_text_reparser.yml +++ b/phpBB/config/default/container/services_text_reparser.yml @@ -1,62 +1,62 @@ services: text_reparser.admin_contact_info: - class: phpbb\textreparser\admincontactinfo + class: phpbb\textreparser\admin_contact_info arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.forum_description: - class: phpbb\textreparser\forumdescription + class: phpbb\textreparser\forum_description arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.forum_rules: - class: phpbb\textreparser\forumrules + class: phpbb\textreparser\forum_rules arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.group_description: - class: phpbb\textreparser\groupdescription + class: phpbb\textreparser\group_description arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.pm_text: - class: phpbb\textreparser\pmtext + class: phpbb\textreparser\pm_text arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.poll_option: - class: phpbb\textreparser\polloption + class: phpbb\textreparser\poll_option arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.poll_title: - class: phpbb\textreparser\polltitle + class: phpbb\textreparser\poll_title arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.post_text: - class: phpbb\textreparser\posttext + class: phpbb\textreparser\post_text arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.user_signature: - class: phpbb\textreparser\usersignature + class: phpbb\textreparser\user_signature arguments: - @dbal.conn tags: diff --git a/phpBB/phpbb/textreparser/forumdescription.php b/phpBB/phpbb/textreparser/forum_description.php similarity index 97% rename from phpBB/phpbb/textreparser/forumdescription.php rename to phpBB/phpbb/textreparser/forum_description.php index b715abd825..493f8d6c94 100644 --- a/phpBB/phpbb/textreparser/forumdescription.php +++ b/phpBB/phpbb/textreparser/forum_description.php @@ -13,7 +13,7 @@ namespace phpbb\textreparser; -class forumdescription extends base +class forum_description extends base { /** * {@inheritdoc} diff --git a/phpBB/phpbb/textreparser/forumrules.php b/phpBB/phpbb/textreparser/forum_rules.php similarity index 98% rename from phpBB/phpbb/textreparser/forumrules.php rename to phpBB/phpbb/textreparser/forum_rules.php index c0538f6cce..5a3cc7b405 100644 --- a/phpBB/phpbb/textreparser/forumrules.php +++ b/phpBB/phpbb/textreparser/forum_rules.php @@ -13,7 +13,7 @@ namespace phpbb\textreparser; -class forumrules extends base +class forum_rules extends base { /** * {@inheritdoc} diff --git a/phpBB/phpbb/textreparser/groupdescription.php b/phpBB/phpbb/textreparser/group_description.php similarity index 97% rename from phpBB/phpbb/textreparser/groupdescription.php rename to phpBB/phpbb/textreparser/group_description.php index 608cc806b6..61354c832b 100644 --- a/phpBB/phpbb/textreparser/groupdescription.php +++ b/phpBB/phpbb/textreparser/group_description.php @@ -13,7 +13,7 @@ namespace phpbb\textreparser; -class groupdescription extends base +class group_description extends base { /** * {@inheritdoc} diff --git a/phpBB/phpbb/textreparser/pmtext.php b/phpBB/phpbb/textreparser/pm_text.php similarity index 97% rename from phpBB/phpbb/textreparser/pmtext.php rename to phpBB/phpbb/textreparser/pm_text.php index e1b27e60fe..b02cb0083f 100644 --- a/phpBB/phpbb/textreparser/pmtext.php +++ b/phpBB/phpbb/textreparser/pm_text.php @@ -13,7 +13,7 @@ namespace phpbb\textreparser; -class pmtext extends base +class pm_text extends base { /** * {@inheritdoc} diff --git a/phpBB/phpbb/textreparser/posttext.php b/phpBB/phpbb/textreparser/post_text.php similarity index 97% rename from phpBB/phpbb/textreparser/posttext.php rename to phpBB/phpbb/textreparser/post_text.php index 916fc94bfa..288bb0966b 100644 --- a/phpBB/phpbb/textreparser/posttext.php +++ b/phpBB/phpbb/textreparser/post_text.php @@ -13,7 +13,7 @@ namespace phpbb\textreparser; -class posttext extends base +class post_text extends base { /** * {@inheritdoc} diff --git a/tests/text_reparser/posttext_test.php b/tests/text_reparser/post_text_test.php similarity index 91% rename from tests/text_reparser/posttext_test.php rename to tests/text_reparser/post_text_test.php index 4dec53dc63..dc13cebf44 100644 --- a/tests/text_reparser/posttext_test.php +++ b/tests/text_reparser/post_text_test.php @@ -14,7 +14,7 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; -class phpbb_textreparser_posttext_test extends phpbb_database_test_case +class phpbb_textreparser_post_text_test extends phpbb_database_test_case { public function setUp() { @@ -38,7 +38,7 @@ class phpbb_textreparser_posttext_test extends phpbb_database_test_case public function testReparse($min_id, $max_id, $expected) { $db = $this->new_dbal(); - $reparser = new \phpbb\textreparser\posttext($db); + $reparser = new \phpbb\textreparser\post_text($db); $reparser->reparse_range($min_id, $max_id); $sql = 'SELECT post_id, post_text FROM ' . POSTS_TABLE . " From 986af43f37342953bff548630aa33904c21234f4 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 1 May 2015 08:47:01 +0200 Subject: [PATCH 03/27] [ticket/13803] Added plugins PHPBB3-13803 --- .../container/services_text_reparser.yml | 20 +-- phpBB/phpbb/textreparser/base.php | 15 -- .../phpbb/textreparser/forum_description.php | 63 --------- phpBB/phpbb/textreparser/forum_rules.php | 63 --------- .../phpbb/textreparser/group_description.php | 63 --------- .../plugins/admin_contact_info.php | 69 ++++++++++ .../plugins/forum_description.php | 37 +++++ .../textreparser/plugins/forum_rules.php | 37 +++++ .../plugins/group_description.php | 37 +++++ phpBB/phpbb/textreparser/plugins/pm_text.php | 40 ++++++ .../textreparser/plugins/poll_option.php | 50 +++++++ .../phpbb/textreparser/plugins/poll_title.php | 50 +++++++ .../phpbb/textreparser/plugins/post_text.php | 40 ++++++ .../textreparser/plugins/user_signature.php | 37 +++++ phpBB/phpbb/textreparser/pm_text.php | 56 -------- phpBB/phpbb/textreparser/post_text.php | 56 -------- phpBB/phpbb/textreparser/row_based_plugin.php | 128 ++++++++++++++++++ tests/text_reparser/post_text_test.php | 2 +- 18 files changed, 536 insertions(+), 327 deletions(-) delete mode 100644 phpBB/phpbb/textreparser/forum_description.php delete mode 100644 phpBB/phpbb/textreparser/forum_rules.php delete mode 100644 phpBB/phpbb/textreparser/group_description.php create mode 100644 phpBB/phpbb/textreparser/plugins/admin_contact_info.php create mode 100644 phpBB/phpbb/textreparser/plugins/forum_description.php create mode 100644 phpBB/phpbb/textreparser/plugins/forum_rules.php create mode 100644 phpBB/phpbb/textreparser/plugins/group_description.php create mode 100644 phpBB/phpbb/textreparser/plugins/pm_text.php create mode 100644 phpBB/phpbb/textreparser/plugins/poll_option.php create mode 100644 phpBB/phpbb/textreparser/plugins/poll_title.php create mode 100644 phpBB/phpbb/textreparser/plugins/post_text.php create mode 100644 phpBB/phpbb/textreparser/plugins/user_signature.php delete mode 100644 phpBB/phpbb/textreparser/pm_text.php delete mode 100644 phpBB/phpbb/textreparser/post_text.php create mode 100644 phpBB/phpbb/textreparser/row_based_plugin.php diff --git a/phpBB/config/default/container/services_text_reparser.yml b/phpBB/config/default/container/services_text_reparser.yml index c458be12ac..c10a8c600a 100644 --- a/phpBB/config/default/container/services_text_reparser.yml +++ b/phpBB/config/default/container/services_text_reparser.yml @@ -1,62 +1,62 @@ services: text_reparser.admin_contact_info: - class: phpbb\textreparser\admin_contact_info + class: phpbb\textreparser\plugins\admin_contact_info arguments: - - @dbal.conn + - @config_text tags: - { name: text_reparser.plugin } text_reparser.forum_description: - class: phpbb\textreparser\forum_description + class: phpbb\textreparser\plugins\forum_description arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.forum_rules: - class: phpbb\textreparser\forum_rules + class: phpbb\textreparser\plugins\forum_rules arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.group_description: - class: phpbb\textreparser\group_description + class: phpbb\textreparser\plugins\group_description arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.pm_text: - class: phpbb\textreparser\pm_text + class: phpbb\textreparser\plugins\pm_text arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.poll_option: - class: phpbb\textreparser\poll_option + class: phpbb\textreparser\plugins\poll_option arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.poll_title: - class: phpbb\textreparser\poll_title + class: phpbb\textreparser\plugins\poll_title arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.post_text: - class: phpbb\textreparser\post_text + class: phpbb\textreparser\plugins\post_text arguments: - @dbal.conn tags: - { name: text_reparser.plugin } text_reparser.user_signature: - class: phpbb\textreparser\user_signature + class: phpbb\textreparser\plugins\user_signature arguments: - @dbal.conn tags: diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 6aa20d0015..7d1e12c52d 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -15,21 +15,6 @@ namespace phpbb\textreparser; abstract class base implements reparser_interface { - /** - * @var \phpbb\db\driver\driver_interface - */ - protected $db; - - /** - * Constructor - * - * @param \phpbb\db\driver\driver_interface $db Database connection - */ - public function __construct(\phpbb\db\driver\driver_interface $db) - { - $this->db = $db; - } - /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/textreparser/forum_description.php b/phpBB/phpbb/textreparser/forum_description.php deleted file mode 100644 index 493f8d6c94..0000000000 --- a/phpBB/phpbb/textreparser/forum_description.php +++ /dev/null @@ -1,63 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textreparser; - -class forum_description extends base -{ - /** - * {@inheritdoc} - */ - public function get_max_id() - { - $sql = 'SELECT MAX(forum_id) AS max_id FROM ' . FORUMS_TABLE; - $result = $this->db->sql_query($sql); - $max_id = (int) $this->db->sql_fetchfield('max_id'); - $this->db->sql_freeresult($result); - - return $max_id; - } - - /** - * {@inheritdoc} - */ - protected function get_records($min_id, $max_id) - { - $sql = 'SELECT forum_id AS id, forum_desc AS text, forum_desc_uid AS bbcode_uid - FROM ' . FORUMS_TABLE . ' - WHERE forum_id BETWEEN ' . $min_id . ' AND ' . $max_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - // Those fields are not saved to the database, we need to guess their original value - $row['enable_bbcode'] = !empty($row['bbcode_uid']); - $row['enable_smilies'] = (strpos($row['text'], '') !== false); - } - $records = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - - return $records; - } - - /** - * {@inheritdoc} - */ - protected function save_record(array $record) - { - $sql = 'UPDATE ' . FORUMS_TABLE . " - SET forum_desc = '" . $this->db->sql_escape($record['text']) . "' - WHERE forum_id = " . $record['id']; - $this->db->sql_query($sql); - } -} diff --git a/phpBB/phpbb/textreparser/forum_rules.php b/phpBB/phpbb/textreparser/forum_rules.php deleted file mode 100644 index 5a3cc7b405..0000000000 --- a/phpBB/phpbb/textreparser/forum_rules.php +++ /dev/null @@ -1,63 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textreparser; - -class forum_rules extends base -{ - /** - * {@inheritdoc} - */ - public function get_max_id() - { - $sql = 'SELECT MAX(forum_id) AS max_id FROM ' . FORUMS_TABLE; - $result = $this->db->sql_query($sql); - $max_id = (int) $this->db->sql_fetchfield('max_id'); - $this->db->sql_freeresult($result); - - return $max_id; - } - - /** - * {@inheritdoc} - */ - protected function get_records($min_id, $max_id) - { - $sql = 'SELECT forum_id AS id, forum_rules AS text, forum_rules_uid AS bbcode_uid - FROM ' . FORUMS_TABLE . ' - WHERE forum_id BETWEEN ' . $min_id . ' AND ' . $max_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - // Those fields are not saved to the database, we need to guess their original value - $row['enable_bbcode'] = !empty($row['bbcode_uid']); - $row['enable_smilies'] = (strpos($row['text'], '') !== false); - } - $records = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - - return $records; - } - - /** - * {@inheritdoc} - */ - protected function save_record(array $record) - { - $sql = 'UPDATE ' . FORUMS_TABLE . " - SET forum_rules = '" . $this->db->sql_escape($record['text']) . "' - WHERE forum_id = " . $record['id']; - $this->db->sql_query($sql); - } -} diff --git a/phpBB/phpbb/textreparser/group_description.php b/phpBB/phpbb/textreparser/group_description.php deleted file mode 100644 index 61354c832b..0000000000 --- a/phpBB/phpbb/textreparser/group_description.php +++ /dev/null @@ -1,63 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textreparser; - -class group_description extends base -{ - /** - * {@inheritdoc} - */ - public function get_max_id() - { - $sql = 'SELECT MAX(group_id) AS max_id FROM ' . GROUPS_TABLE; - $result = $this->db->sql_query($sql); - $max_id = (int) $this->db->sql_fetchfield('max_id'); - $this->db->sql_freeresult($result); - - return $max_id; - } - - /** - * {@inheritdoc} - */ - protected function get_records($min_id, $max_id) - { - $sql = 'SELECT group_id AS id, group_desc AS text, group_desc_uid AS bbcode_uid - FROM ' . GROUPS_TABLE . ' - WHERE group_id BETWEEN ' . $min_id . ' AND ' . $max_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - // Those fields are not saved to the database, we need to guess their original value - $row['enable_bbcode'] = !empty($row['bbcode_uid']); - $row['enable_smilies'] = (strpos($row['text'], '') !== false); - } - $records = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - - return $records; - } - - /** - * {@inheritdoc} - */ - protected function save_record(array $record) - { - $sql = 'UPDATE ' . GROUPS_TABLE . " - SET group_desc = '" . $this->db->sql_escape($record['text']) . "' - WHERE group_id = " . $record['id']; - $this->db->sql_query($sql); - } -} diff --git a/phpBB/phpbb/textreparser/plugins/admin_contact_info.php b/phpBB/phpbb/textreparser/plugins/admin_contact_info.php new file mode 100644 index 0000000000..e432ddea81 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/admin_contact_info.php @@ -0,0 +1,69 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser\plugins; + +class admin_contact_info extends \phpbb\textreparser\base +{ + /** + * @var \phpbb\config\db_text + */ + protected $config_text; + + /** + * Constructor + * + * @param \phpbb\config\db_text $config_text + */ + public function __construct(\phpbb\config\db_text $config_text) + { + $this->config_text = $config_text; + } + + /** + * {@inheritdoc} + */ + public function get_max_id() + { + return 1; + } + + /** + * {@inheritdoc} + */ + protected function get_records($min_id, $max_id) + { + $values = $this->config_text->get_array(array( + 'contact_admin_info', + 'contact_admin_info_uid', + 'contact_admin_info_flags', + )); + + return array(array( + 'id' => 1, + 'text' => $values['contact_admin_info'], + 'bbcode_uid' => $values['contact_admin_info_uid'], + 'enable_bbcode' => $values['contact_admin_info_flags'] & OPTION_FLAG_BBCODE, + 'enable_magic_url' => $values['contact_admin_info_flags'] & OPTION_FLAG_LINKS, + 'enable_smilies' => $values['contact_admin_info_flags'] & OPTION_FLAG_SMILIES, + )); + } + + /** + * {@inheritdoc} + */ + protected function save_record(array $record) + { + $this->config_text->set('admin_contact_info', $record['text']); + } +} diff --git a/phpBB/phpbb/textreparser/plugins/forum_description.php b/phpBB/phpbb/textreparser/plugins/forum_description.php new file mode 100644 index 0000000000..d6e95c9638 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/forum_description.php @@ -0,0 +1,37 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser\plugins; + +class forum_description extends \phpbb\textreparser\row_based_plugin +{ + /** + * {@inheritdoc} + */ + protected function get_columns() + { + return array( + 'id' => 'forum_id', + 'text' => 'forum_desc', + 'bbcode_uid' => 'forum_desc_uid', + ); + } + + /** + * {@inheritdoc} + */ + protected function get_table_name() + { + return FORUMS_TABLE; + } +} diff --git a/phpBB/phpbb/textreparser/plugins/forum_rules.php b/phpBB/phpbb/textreparser/plugins/forum_rules.php new file mode 100644 index 0000000000..36bb595cb9 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/forum_rules.php @@ -0,0 +1,37 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser\plugins; + +class forum_rules extends \phpbb\textreparser\row_based_plugin +{ + /** + * {@inheritdoc} + */ + protected function get_columns() + { + return array( + 'id' => 'forum_id', + 'text' => 'forum_rules', + 'bbcode_uid' => 'forum_rules_uid', + ); + } + + /** + * {@inheritdoc} + */ + protected function get_table_name() + { + return FORUMS_TABLE; + } +} diff --git a/phpBB/phpbb/textreparser/plugins/group_description.php b/phpBB/phpbb/textreparser/plugins/group_description.php new file mode 100644 index 0000000000..c83079827c --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/group_description.php @@ -0,0 +1,37 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser\plugins; + +class group_description extends \phpbb\textreparser\row_based_plugin +{ + /** + * {@inheritdoc} + */ + protected function get_columns() + { + return array( + 'id' => 'group_id', + 'text' => 'group_desc', + 'bbcode_uid' => 'group_desc_uid', + ); + } + + /** + * {@inheritdoc} + */ + protected function get_table_name() + { + return GROUPS_TABLE; + } +} diff --git a/phpBB/phpbb/textreparser/plugins/pm_text.php b/phpBB/phpbb/textreparser/plugins/pm_text.php new file mode 100644 index 0000000000..f4d87525df --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/pm_text.php @@ -0,0 +1,40 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser\plugins; + +class pm_text extends \phpbb\textreparser\row_based_plugin +{ + /** + * {@inheritdoc} + */ + protected function get_columns() + { + return array( + 'id' => 'msg_id', + 'enable_bbcode' => 'enable_bbcode', + 'enable_smilies' => 'enable_smilies', + 'enable_magic_url' => 'enable_magic_url', + 'text' => 'message_text', + 'bbcode_uid' => 'bbcode_uid', + ); + } + + /** + * {@inheritdoc} + */ + protected function get_table_name() + { + return PRIVMSGS_TABLE; + } +} diff --git a/phpBB/phpbb/textreparser/plugins/poll_option.php b/phpBB/phpbb/textreparser/plugins/poll_option.php new file mode 100644 index 0000000000..f074f1866d --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/poll_option.php @@ -0,0 +1,50 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser\plugins; + +class poll_option extends \phpbb\textreparser\row_based_plugin +{ + /** + * {@inheritdoc} + */ + protected function get_columns() + { + return array( + 'id' => 'poll_option_id', + 'text' => 'poll_option_text', + ); + } + + /** + * {@inheritdoc} + */ + protected function get_records_query($min_id, $max_id) + { + $sql = 'SELECT o.poll_option_id AS id, o.poll_option_text AS text, p.bbcode_uid + FROM ' . POLL_OPTIONS_TABLE . ' o, ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p + WHERE o.poll_option_id BETWEEN ' . $min_id . ' AND ' . $max_id .' + AND t.topic_id = o.topic_id + AND p.post_id = t.topic_first_post_id'; + + return $sql; + } + + /** + * {@inheritdoc} + */ + protected function get_table_name() + { + return POLL_OPTIONS_TABLE; + } +} diff --git a/phpBB/phpbb/textreparser/plugins/poll_title.php b/phpBB/phpbb/textreparser/plugins/poll_title.php new file mode 100644 index 0000000000..e794780eba --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/poll_title.php @@ -0,0 +1,50 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser\plugins; + +class poll_title extends \phpbb\textreparser\row_based_plugin +{ + /** + * {@inheritdoc} + */ + protected function get_columns() + { + return array( + 'id' => 'topic_id', + 'text' => 'poll_title', + ); + } + + /** + * {@inheritdoc} + */ + protected function get_records_query($min_id, $max_id) + { + $sql = 'SELECT t.topic_id AS id, t.poll_title AS text, 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 + AND p.post_id = t.topic_first_post_id'; + + return $sql; + } + + /** + * {@inheritdoc} + */ + protected function get_table_name() + { + return TOPICS_TABLE; + } +} diff --git a/phpBB/phpbb/textreparser/plugins/post_text.php b/phpBB/phpbb/textreparser/plugins/post_text.php new file mode 100644 index 0000000000..2b16518b03 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/post_text.php @@ -0,0 +1,40 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser\plugins; + +class post_text extends \phpbb\textreparser\row_based_plugin +{ + /** + * {@inheritdoc} + */ + protected function get_columns() + { + return array( + 'id' => 'post_id', + 'enable_bbcode' => 'enable_bbcode', + 'enable_smilies' => 'enable_smilies', + 'enable_magic_url' => 'enable_magic_url', + 'text' => 'post_text', + 'bbcode_uid' => 'bbcode_uid', + ); + } + + /** + * {@inheritdoc} + */ + protected function get_table_name() + { + return POSTS_TABLE; + } +} diff --git a/phpBB/phpbb/textreparser/plugins/user_signature.php b/phpBB/phpbb/textreparser/plugins/user_signature.php new file mode 100644 index 0000000000..2beaaf98e5 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/user_signature.php @@ -0,0 +1,37 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser\plugins; + +class user_signature extends \phpbb\textreparser\row_based_plugin +{ + /** + * {@inheritdoc} + */ + protected function get_columns() + { + return array( + 'id' => 'user_id', + 'text' => 'user_sig', + 'bbcode_uid' => 'user_sig_bbcode_uid', + ); + } + + /** + * {@inheritdoc} + */ + protected function get_table_name() + { + return USERS_TABLE; + } +} diff --git a/phpBB/phpbb/textreparser/pm_text.php b/phpBB/phpbb/textreparser/pm_text.php deleted file mode 100644 index b02cb0083f..0000000000 --- a/phpBB/phpbb/textreparser/pm_text.php +++ /dev/null @@ -1,56 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textreparser; - -class pm_text extends base -{ - /** - * {@inheritdoc} - */ - public function get_max_id() - { - $sql = 'SELECT MAX(msg_id) AS max_id FROM ' . PRIVMSGS_TABLE; - $result = $this->db->sql_query($sql); - $max_id = (int) $this->db->sql_fetchfield('max_id'); - $this->db->sql_freeresult($result); - - return $max_id; - } - - /** - * {@inheritdoc} - */ - protected function get_records($min_id, $max_id) - { - $sql = 'SELECT msg_id AS id, enable_bbcode, enable_smilies, enable_magic_url, message_text AS text, bbcode_uid - FROM ' . PRIVMSGS_TABLE . ' - WHERE msg_id BETWEEN ' . $min_id . ' AND ' . $max_id; - $result = $this->db->sql_query($sql); - $records = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - - return $records; - } - - /** - * {@inheritdoc} - */ - protected function save_record(array $record) - { - $sql = 'UPDATE ' . PRIVMSGS_TABLE . " - SET message_text = '" . $this->db->sql_escape($record['text']) . "' - WHERE msg_id = " . $record['id']; - $this->db->sql_query($sql); - } -} diff --git a/phpBB/phpbb/textreparser/post_text.php b/phpBB/phpbb/textreparser/post_text.php deleted file mode 100644 index 288bb0966b..0000000000 --- a/phpBB/phpbb/textreparser/post_text.php +++ /dev/null @@ -1,56 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\textreparser; - -class post_text extends base -{ - /** - * {@inheritdoc} - */ - public function get_max_id() - { - $sql = 'SELECT MAX(post_id) AS max_id FROM ' . POSTS_TABLE; - $result = $this->db->sql_query($sql); - $max_id = (int) $this->db->sql_fetchfield('max_id'); - $this->db->sql_freeresult($result); - - return $max_id; - } - - /** - * {@inheritdoc} - */ - protected function get_records($min_id, $max_id) - { - $sql = 'SELECT post_id AS id, enable_bbcode, enable_smilies, enable_magic_url, post_text AS text, bbcode_uid - FROM ' . POSTS_TABLE . ' - WHERE post_id BETWEEN ' . $min_id . ' AND ' . $max_id; - $result = $this->db->sql_query($sql); - $records = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - - return $records; - } - - /** - * {@inheritdoc} - */ - protected function save_record(array $record) - { - $sql = 'UPDATE ' . POSTS_TABLE . " - SET post_text = '" . $this->db->sql_escape($record['text']) . "' - WHERE post_id = " . $record['id']; - $this->db->sql_query($sql); - } -} diff --git a/phpBB/phpbb/textreparser/row_based_plugin.php b/phpBB/phpbb/textreparser/row_based_plugin.php new file mode 100644 index 0000000000..2317c79e4f --- /dev/null +++ b/phpBB/phpbb/textreparser/row_based_plugin.php @@ -0,0 +1,128 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textreparser; + +abstract class row_based_plugin extends base +{ + /** + * @var \phpbb\db\driver\driver_interface + */ + protected $db; + + /** + * Constructor + * + * @param \phpbb\db\driver\driver_interface $db Database connection + */ + public function __construct(\phpbb\db\driver\driver_interface $db) + { + $this->db = $db; + } + + /** + * Return the name of the column that correspond to each field + * + * @return array + */ + abstract protected function get_columns(); + + /** + * Return the name of the table used by this plugin + * + * @return string + */ + abstract protected function get_table_name(); + + /** + * {@inheritdoc} + */ + public function get_max_id() + { + $columns = $this->get_columns(); + + $sql = 'SELECT MAX(' . $columns['id'] . ' AS max_id FROM ' . $this->get_table_name(); + $result = $this->db->sql_query($sql); + $max_id = (int) $this->db->sql_fetchfield('max_id'); + $this->db->sql_freeresult($result); + + return $max_id; + } + + /** + * {@inheritdoc} + */ + protected function get_records($min_id, $max_id) + { + $result = $this->db->sql_query($this->get_records_query($min_id, $max_id)); + while ($row = $this->db->sql_fetchrow($result)) + { + if (!isset($row['enable_bbcode'], $row['enable_smilies'], $row['enable_magic_url'])) + { + // Those fields are not saved to the database, we need to guess their original value + $row += array( + 'enable_bbcode' => !empty($row['bbcode_uid']), + 'enable_smilies' => (strpos($row['text'], '') !== false) + ); + } + $records[] = $row; + } + $this->db->sql_freeresult($result); + + return $records; + } + + /** + * Generate the query that retrieves all records for given range + * + * @param integer $min_id Lower bound + * @param integer $max_id Upper bound + * @return string SQL query + */ + protected function get_records_query($min_id, $max_id) + { + $columns = $this->get_columns(); + $fields = array(); + foreach ($columns as $field_name => $column_name) + { + if ($column_name === $field_name) + { + $fields[] = $column_name; + } + else + { + $fields[] = $column_name . ' AS ' . $field_name; + } + } + + $sql = 'SELECT ' . implode(', ', $fields) . ' + FROM ' . $this->get_table_name() . ' + WHERE ' . $columns['id'] . ' BETWEEN ' . $min_id . ' AND ' . $max_id; + + return $sql; + } + + /** + * {@inheritdoc} + */ + protected function save_record(array $record) + { + $columns = $this->get_columns(); + + $sql = 'UPDATE ' . $this->get_table_name() . ' + SET ' . $columns['text'] . " = '" . $this->db->sql_escape($record['text']) . "' + WHERE " . $columns['id'] . ' = ' . $record['id']; + $this->db->sql_query($sql); + } +} diff --git a/tests/text_reparser/post_text_test.php b/tests/text_reparser/post_text_test.php index dc13cebf44..9d9d689db9 100644 --- a/tests/text_reparser/post_text_test.php +++ b/tests/text_reparser/post_text_test.php @@ -38,7 +38,7 @@ class phpbb_textreparser_post_text_test extends phpbb_database_test_case public function testReparse($min_id, $max_id, $expected) { $db = $this->new_dbal(); - $reparser = new \phpbb\textreparser\post_text($db); + $reparser = new \phpbb\textreparser\plugins\post_text($db); $reparser->reparse_range($min_id, $max_id); $sql = 'SELECT post_id, post_text FROM ' . POSTS_TABLE . " From b5911281ae175340817345e63ddbfaf43abb3cec Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 1 May 2015 19:21:01 +0200 Subject: [PATCH 04/27] [ticket/13803] Added tests, fixed param order in generate_text_for_storage() PHPBB3-13803 --- phpBB/phpbb/textreparser/base.php | 4 +- .../textreparser/plugins/user_signature.php | 39 +++++++++++++++-- phpBB/phpbb/textreparser/row_based_plugin.php | 34 ++++++++++----- tests/text_reparser/fixtures/posts.xml | 42 ++++++++++++++++++- tests/text_reparser/post_text_test.php | 38 ++++++++++++++--- 5 files changed, 135 insertions(+), 22 deletions(-) diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 7d1e12c52d..f65745f6ab 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -63,8 +63,8 @@ abstract class base implements reparser_interface $bitfield, $flags, $unparsed['enable_bbcode'], - $unparsed['enable_smilies'], - $unparsed['enable_magic_url'] + $unparsed['enable_magic_url'], + $unparsed['enable_smilies'] ); // Save the new text if it has changed diff --git a/phpBB/phpbb/textreparser/plugins/user_signature.php b/phpBB/phpbb/textreparser/plugins/user_signature.php index 2beaaf98e5..7a66f39ab6 100644 --- a/phpBB/phpbb/textreparser/plugins/user_signature.php +++ b/phpBB/phpbb/textreparser/plugins/user_signature.php @@ -15,15 +15,48 @@ namespace phpbb\textreparser\plugins; class user_signature extends \phpbb\textreparser\row_based_plugin { + /** + * @var array Bit numbers used for user options + * @see \phpbb\user + */ + protected $keyoptions; + + /** + * Constructor + * + * Retrieves and saves the bit numbers used for user options + */ + public function __construct() + { + $class_vars = get_class_vars('phpbb\\user'); + $this->keyoptions = $class_vars['keyoptions']; + } + + /** + * {@inheritdoc} + */ + protected function add_missing_fields(array $row) + { + $options = $row['user_options']; + $row += array( + 'enable_bbcode' => phpbb_optionget($this->keyoptions['sig_bbcode'], $options), + 'enable_smilies' => phpbb_optionget($this->keyoptions['sig_smilies'], $options), + 'enable_magic_url' => phpbb_optionget($this->keyoptions['sig_links'], $options), + ); + + return $row; + } + /** * {@inheritdoc} */ protected function get_columns() { return array( - 'id' => 'user_id', - 'text' => 'user_sig', - 'bbcode_uid' => 'user_sig_bbcode_uid', + 'id' => 'user_id', + 'text' => 'user_sig', + 'bbcode_uid' => 'user_sig_bbcode_uid', + 'user_options' => 'user_options', ); } diff --git a/phpBB/phpbb/textreparser/row_based_plugin.php b/phpBB/phpbb/textreparser/row_based_plugin.php index 2317c79e4f..b946d6532b 100644 --- a/phpBB/phpbb/textreparser/row_based_plugin.php +++ b/phpBB/phpbb/textreparser/row_based_plugin.php @@ -44,6 +44,29 @@ abstract class row_based_plugin extends base */ abstract protected function get_table_name(); + /** + * Add fields to given row, if applicable + * + * The enable_* fields are not always saved to the database. Sometimes we need to guess their + * original value based on the text content or possibly other fields + * + * @param array $row Original row + * @return array Complete row + */ + protected function add_missing_fields(array $row) + { + if (!isset($row['enable_bbcode'], $row['enable_smilies'], $row['enable_magic_url'])) + { + $row += array( + 'enable_bbcode' => !empty($row['bbcode_uid']), + 'enable_smilies' => (strpos($row['text'], '') !== false), + ); + } + + return $row; + } + /** * {@inheritdoc} */ @@ -67,16 +90,7 @@ abstract class row_based_plugin extends base $result = $this->db->sql_query($this->get_records_query($min_id, $max_id)); while ($row = $this->db->sql_fetchrow($result)) { - if (!isset($row['enable_bbcode'], $row['enable_smilies'], $row['enable_magic_url'])) - { - // Those fields are not saved to the database, we need to guess their original value - $row += array( - 'enable_bbcode' => !empty($row['bbcode_uid']), - 'enable_smilies' => (strpos($row['text'], '') !== false) - ); - } - $records[] = $row; + $records[] = $this->add_missing_fields($row); } $this->db->sql_freeresult($result); diff --git a/tests/text_reparser/fixtures/posts.xml b/tests/text_reparser/fixtures/posts.xml index 6485293361..3cfbfd2e95 100644 --- a/tests/text_reparser/fixtures/posts.xml +++ b/tests/text_reparser/fixtures/posts.xml @@ -12,7 +12,47 @@ 1 1 1 - Plain text + This post should be [b]ignored[/b] + abcd1234 + + + 2 + 0 + 0 + 0 + [b]Not bold[/b] :) http://example.org + abcd1234 + + + 3 + 1 + 0 + 0 + [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + abcd1234 + + + 4 + 0 + 1 + 0 + :) http://example.org]]> + abcd1234 + + + 5 + 0 + 0 + 1 + http://example.org]]> + abcd1234 + + + 1000 + 1 + 1 + 1 + This post should be [b]ignored[/b] abcd1234 diff --git a/tests/text_reparser/post_text_test.php b/tests/text_reparser/post_text_test.php index 9d9d689db9..19e9c37ecc 100644 --- a/tests/text_reparser/post_text_test.php +++ b/tests/text_reparser/post_text_test.php @@ -40,9 +40,15 @@ class phpbb_textreparser_post_text_test extends phpbb_database_test_case $db = $this->new_dbal(); $reparser = new \phpbb\textreparser\plugins\post_text($db); $reparser->reparse_range($min_id, $max_id); + + $post_ids = array(); + foreach ($expected as $row) + { + $post_ids[] = $row['post_id']; + } $sql = 'SELECT post_id, post_text - FROM ' . POSTS_TABLE . " - WHERE post_id BETWEEN $min_id AND $max_id"; + FROM ' . POSTS_TABLE . ' + WHERE ' . $db->sql_in_set('post_id', $post_ids); $result = $db->sql_query($sql); $rows = $db->sql_fetchrowset($result); $db->sql_freeresult($result); @@ -53,13 +59,33 @@ class phpbb_textreparser_post_text_test extends phpbb_database_test_case { return array( array( - 1, - 1, + 2, + 5, array( array( 'post_id' => 1, - 'post_text' => 'Plain text' - ) + 'post_text' => 'This post should be [b]ignored[/b]', + ), + array( + 'post_id' => 2, + 'post_text' => '[b]Not bold[/b] :) http://example.org', + ), + array( + 'post_id' => 3, + 'post_text' => '[b]Bold[/b] :) http://example.org', + ), + array( + 'post_id' => 4, + 'post_text' => '[b]Not bold[/b] :) http://example.org', + ), + array( + 'post_id' => 5, + 'post_text' => '[b]Not bold[/b] :) http://example.org', + ), + array( + 'post_id' => 1000, + 'post_text' => 'This post should be [b]ignored[/b]', + ), ) ), ); From 459f1d4c1f26658c70d29ac7c4e3f3389a973a59 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 1 May 2015 20:05:15 +0200 Subject: [PATCH 05/27] [ticket/13803] Refactored test PHPBB3-13803 --- .../plugins/forum_description.php | 4 +- .../textreparser/plugins/forum_rules.php | 4 +- .../plugins/group_description.php | 4 +- phpBB/phpbb/textreparser/plugins/pm_text.php | 4 +- .../textreparser/plugins/poll_option.php | 4 +- .../phpbb/textreparser/plugins/poll_title.php | 4 +- .../phpbb/textreparser/plugins/post_text.php | 4 +- .../textreparser/plugins/user_signature.php | 4 +- phpBB/phpbb/textreparser/row_based_plugin.php | 4 +- tests/text_reparser/fixtures/posts.xml | 4 +- tests/text_reparser/post_text_test.php | 75 +-------------- tests/text_reparser/test_row_based_plugin.php | 92 +++++++++++++++++++ 12 files changed, 116 insertions(+), 91 deletions(-) create mode 100644 tests/text_reparser/test_row_based_plugin.php diff --git a/phpBB/phpbb/textreparser/plugins/forum_description.php b/phpBB/phpbb/textreparser/plugins/forum_description.php index d6e95c9638..7798e4b20b 100644 --- a/phpBB/phpbb/textreparser/plugins/forum_description.php +++ b/phpBB/phpbb/textreparser/plugins/forum_description.php @@ -18,7 +18,7 @@ class forum_description extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_columns() + public function get_columns() { return array( 'id' => 'forum_id', @@ -30,7 +30,7 @@ class forum_description extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_table_name() + public function get_table_name() { return FORUMS_TABLE; } diff --git a/phpBB/phpbb/textreparser/plugins/forum_rules.php b/phpBB/phpbb/textreparser/plugins/forum_rules.php index 36bb595cb9..57c666a556 100644 --- a/phpBB/phpbb/textreparser/plugins/forum_rules.php +++ b/phpBB/phpbb/textreparser/plugins/forum_rules.php @@ -18,7 +18,7 @@ class forum_rules extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_columns() + public function get_columns() { return array( 'id' => 'forum_id', @@ -30,7 +30,7 @@ class forum_rules extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_table_name() + public function get_table_name() { return FORUMS_TABLE; } diff --git a/phpBB/phpbb/textreparser/plugins/group_description.php b/phpBB/phpbb/textreparser/plugins/group_description.php index c83079827c..ddd0e1d1c5 100644 --- a/phpBB/phpbb/textreparser/plugins/group_description.php +++ b/phpBB/phpbb/textreparser/plugins/group_description.php @@ -18,7 +18,7 @@ class group_description extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_columns() + public function get_columns() { return array( 'id' => 'group_id', @@ -30,7 +30,7 @@ class group_description extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_table_name() + public function get_table_name() { return GROUPS_TABLE; } diff --git a/phpBB/phpbb/textreparser/plugins/pm_text.php b/phpBB/phpbb/textreparser/plugins/pm_text.php index f4d87525df..4d06a2878b 100644 --- a/phpBB/phpbb/textreparser/plugins/pm_text.php +++ b/phpBB/phpbb/textreparser/plugins/pm_text.php @@ -18,7 +18,7 @@ class pm_text extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_columns() + public function get_columns() { return array( 'id' => 'msg_id', @@ -33,7 +33,7 @@ class pm_text extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_table_name() + public function get_table_name() { return PRIVMSGS_TABLE; } diff --git a/phpBB/phpbb/textreparser/plugins/poll_option.php b/phpBB/phpbb/textreparser/plugins/poll_option.php index f074f1866d..cc28599737 100644 --- a/phpBB/phpbb/textreparser/plugins/poll_option.php +++ b/phpBB/phpbb/textreparser/plugins/poll_option.php @@ -18,7 +18,7 @@ class poll_option extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_columns() + public function get_columns() { return array( 'id' => 'poll_option_id', @@ -43,7 +43,7 @@ class poll_option extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_table_name() + public function get_table_name() { return POLL_OPTIONS_TABLE; } diff --git a/phpBB/phpbb/textreparser/plugins/poll_title.php b/phpBB/phpbb/textreparser/plugins/poll_title.php index e794780eba..6665d68847 100644 --- a/phpBB/phpbb/textreparser/plugins/poll_title.php +++ b/phpBB/phpbb/textreparser/plugins/poll_title.php @@ -18,7 +18,7 @@ class poll_title extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_columns() + public function get_columns() { return array( 'id' => 'topic_id', @@ -43,7 +43,7 @@ class poll_title extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_table_name() + public function get_table_name() { return TOPICS_TABLE; } diff --git a/phpBB/phpbb/textreparser/plugins/post_text.php b/phpBB/phpbb/textreparser/plugins/post_text.php index 2b16518b03..4a07c98cea 100644 --- a/phpBB/phpbb/textreparser/plugins/post_text.php +++ b/phpBB/phpbb/textreparser/plugins/post_text.php @@ -18,7 +18,7 @@ class post_text extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_columns() + public function get_columns() { return array( 'id' => 'post_id', @@ -33,7 +33,7 @@ class post_text extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_table_name() + public function get_table_name() { return POSTS_TABLE; } diff --git a/phpBB/phpbb/textreparser/plugins/user_signature.php b/phpBB/phpbb/textreparser/plugins/user_signature.php index 7a66f39ab6..db82d4089b 100644 --- a/phpBB/phpbb/textreparser/plugins/user_signature.php +++ b/phpBB/phpbb/textreparser/plugins/user_signature.php @@ -50,7 +50,7 @@ class user_signature extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_columns() + public function get_columns() { return array( 'id' => 'user_id', @@ -63,7 +63,7 @@ class user_signature extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_table_name() + public function get_table_name() { return USERS_TABLE; } diff --git a/phpBB/phpbb/textreparser/row_based_plugin.php b/phpBB/phpbb/textreparser/row_based_plugin.php index b946d6532b..2be0b68411 100644 --- a/phpBB/phpbb/textreparser/row_based_plugin.php +++ b/phpBB/phpbb/textreparser/row_based_plugin.php @@ -35,14 +35,14 @@ abstract class row_based_plugin extends base * * @return array */ - abstract protected function get_columns(); + abstract public function get_columns(); /** * Return the name of the table used by this plugin * * @return string */ - abstract protected function get_table_name(); + abstract public function get_table_name(); /** * Add fields to given row, if applicable diff --git a/tests/text_reparser/fixtures/posts.xml b/tests/text_reparser/fixtures/posts.xml index 3cfbfd2e95..5e725825d8 100644 --- a/tests/text_reparser/fixtures/posts.xml +++ b/tests/text_reparser/fixtures/posts.xml @@ -12,7 +12,7 @@ 1 1 1 - This post should be [b]ignored[/b] + This row should be [b]ignored[/b] abcd1234 @@ -52,7 +52,7 @@ 1 1 1 - This post should be [b]ignored[/b] + This row should be [b]ignored[/b] abcd1234 diff --git a/tests/text_reparser/post_text_test.php b/tests/text_reparser/post_text_test.php index 19e9c37ecc..ac540f170c 100644 --- a/tests/text_reparser/post_text_test.php +++ b/tests/text_reparser/post_text_test.php @@ -10,84 +10,17 @@ * the docs/CREDITS.txt file. * */ -require_once __DIR__ . '/../../phpBB/includes/functions.php'; -require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; -require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; +include_once __DIR__ . '/test_row_based_plugin.php'; -class phpbb_textreparser_post_text_test extends phpbb_database_test_case +class phpbb_textreparser_post_text_test extends phpbb_textreparser_test_row_based_plugin { - public function setUp() - { - global $config; - if (!isset($config)) - { - $config = new \phpbb\config\config(array()); - } - $this->get_test_case_helpers()->set_s9e_services(); - parent::setUp(); - } - public function getDataSet() { return $this->createXMLDataSet(__DIR__ . '/fixtures/posts.xml'); } - /** - * @dataProvider getReparseTests - */ - public function testReparse($min_id, $max_id, $expected) + public function get_reparser() { - $db = $this->new_dbal(); - $reparser = new \phpbb\textreparser\plugins\post_text($db); - $reparser->reparse_range($min_id, $max_id); - - $post_ids = array(); - foreach ($expected as $row) - { - $post_ids[] = $row['post_id']; - } - $sql = 'SELECT post_id, post_text - FROM ' . POSTS_TABLE . ' - WHERE ' . $db->sql_in_set('post_id', $post_ids); - $result = $db->sql_query($sql); - $rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - $this->assertEquals($expected, $rows); - } - - public function getReparseTests() - { - return array( - array( - 2, - 5, - array( - array( - 'post_id' => 1, - 'post_text' => 'This post should be [b]ignored[/b]', - ), - array( - 'post_id' => 2, - 'post_text' => '[b]Not bold[/b] :) http://example.org', - ), - array( - 'post_id' => 3, - 'post_text' => '[b]Bold[/b] :) http://example.org', - ), - array( - 'post_id' => 4, - 'post_text' => '[b]Not bold[/b] :) http://example.org', - ), - array( - 'post_id' => 5, - 'post_text' => '[b]Not bold[/b] :) http://example.org', - ), - array( - 'post_id' => 1000, - 'post_text' => 'This post should be [b]ignored[/b]', - ), - ) - ), - ); + return new \phpbb\textreparser\plugins\post_text($this->db); } } diff --git a/tests/text_reparser/test_row_based_plugin.php b/tests/text_reparser/test_row_based_plugin.php new file mode 100644 index 0000000000..7dd90f21d0 --- /dev/null +++ b/tests/text_reparser/test_row_based_plugin.php @@ -0,0 +1,92 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; + +abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_test_case +{ + protected $db; + + public function setUp() + { + global $config; + if (!isset($config)) + { + $config = new \phpbb\config\config(array()); + } + $this->get_test_case_helpers()->set_s9e_services(); + $this->db = $this->new_dbal(); + parent::setUp(); + } + + /** + * @dataProvider getReparseTests + */ + public function testReparse($min_id, $max_id, $expected) + { + $reparser = $this->get_reparser(); + $reparser->reparse_range($min_id, $max_id); + + $ids = array(); + foreach ($expected as $row) + { + $ids[] = $row['id']; + } + + $columns = $reparser->get_columns(); + $sql = 'SELECT ' . $columns['id'] . ' AS id, ' . $columns['text'] . ' AS text + FROM ' . $reparser->get_table_name() . ' + WHERE ' . $this->db->sql_in_set($columns['id'], $ids); + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + $this->assertEquals($expected, $rows); + } + + public function getReparseTests() + { + return array( + array( + 2, + 5, + array( + array( + 'id' => 1, + 'text' => 'This row should be [b]ignored[/b]', + ), + array( + 'id' => 2, + 'text' => '[b]Not bold[/b] :) http://example.org', + ), + array( + 'id' => 3, + 'text' => '[b]Bold[/b] :) http://example.org', + ), + array( + 'id' => 4, + 'text' => '[b]Not bold[/b] :) http://example.org', + ), + array( + 'id' => 5, + 'text' => '[b]Not bold[/b] :) http://example.org', + ), + array( + 'id' => 1000, + 'text' => 'This row should be [b]ignored[/b]', + ), + ) + ), + ); + } +} From ea445ffa4776b7ce0b1d13485f113c7e1ec28af0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 2 May 2015 01:08:32 +0200 Subject: [PATCH 06/27] [ticket/13803] Added methods to detect whether a given feature is in use They test whether a given BBCode was enabled and has been used in a text, or smilies, or magic URLs. PHPBB3-13803 --- phpBB/phpbb/textreparser/base.php | 56 +++++++++++++++++++ phpBB/phpbb/textreparser/row_based_plugin.php | 13 ++++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index f65745f6ab..f3f31ca320 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -29,6 +29,62 @@ abstract class base implements reparser_interface */ abstract protected function get_records($min_id, $max_id); + /** + * Guess whether given BBCode is in use in given record + * + * @param array $record + * @param string $bbcode + * @return bool + */ + protected function guess_bbcode(array $record, $bbcode) + { + if (!empty($record['bbcode_uid'])) + { + // Look for the closing tag, e.g. [/url] + $match = '[/' . $bbcode . ':' . $record['bbcode_uid']; + if (stripos($record['text'], $match) !== false) + { + return true; + } + } + + if (substr($record['text'], 0, 2) == '[/url] + $match = '[/' . $bbcode . ']'; + if (stripos($record['text'], $match) !== false) + { + return true; + } + } + + return false; + } + + /** + * Guess whether magic URLs are in use in given record + * + * @param array $record + * @return bool + */ + protected function guess_magic_url(array $record) + { + // Look for or for a URL tag that's not immediately followed by + return (strpos($record['text'], '') !== false || preg_match('(]++>(?!))', strpos($row['text']))); + } + + /** + * Guess whether smilies are in use in given record + * + * @param array $record + * @return bool + */ + protected function guess_smilies(array $record) + { + return (strpos($row['text'], '') !== false), + 'enable_smilies' => $this->guess_smilies($row), + 'enable_magic_url' => $this->guess_magic_url($row), ); } + // Those BBCodes are disabled based on context and user permissions and that value is never + // stored in the database. Here we test whether they were used in the original text. + $bbcodes = array('flash', 'img', 'quote', 'url'); + foreach ($bbcodes as $bbcode) + { + $field_name = 'enable_' . $bbcode; + $row[$field_name] = $this->guess_bbcode($row, $bbcode); + } + return $row; } From 9bf0f794b5876b10491c91548f1a92bc0dff7400 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 2 May 2015 02:55:45 +0200 Subject: [PATCH 07/27] [ticket/13803] Added pm_text tests PHPBB3-13803 --- phpBB/phpbb/textreparser/base.php | 38 +++++++++- phpBB/phpbb/textreparser/row_based_plugin.php | 32 -------- tests/text_reparser/fixtures/privmsgs.xml | 73 +++++++++++++++++++ tests/text_reparser/pm_text_test.php | 26 +++++++ 4 files changed, 136 insertions(+), 33 deletions(-) create mode 100644 tests/text_reparser/fixtures/privmsgs.xml create mode 100644 tests/text_reparser/pm_text_test.php diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index f3f31ca320..2d4a4171af 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -29,6 +29,38 @@ abstract class base implements reparser_interface */ abstract protected function get_records($min_id, $max_id); + /** + * Add fields to given record, if applicable + * + * The enable_* fields are not always saved to the database. Sometimes we need to guess their + * original value based on the text content or possibly other fields + * + * @param array $record Original record + * @return array Complete record + */ + protected function add_missing_fields(array $record) + { + if (!isset($record['enable_bbcode'], $record['enable_smilies'], $record['enable_magic_url'])) + { + $record += array( + 'enable_bbcode' => !empty($record['bbcode_uid']), + '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 + // stored in the database. Here we test whether they were used in the original text. + $bbcodes = array('flash', 'img', 'quote', 'url'); + foreach ($bbcodes as $bbcode) + { + $field_name = 'enable_' . $bbcode . '_bbcode'; + $record[$field_name] = $this->guess_bbcode($record, $bbcode); + } + + return $record; + } + /** * Guess whether given BBCode is in use in given record * @@ -120,7 +152,11 @@ abstract class base implements reparser_interface $flags, $unparsed['enable_bbcode'], $unparsed['enable_magic_url'], - $unparsed['enable_smilies'] + $unparsed['enable_smilies'], + $unparsed['enable_img_bbcode'], + $unparsed['enable_flash_bbcode'], + $unparsed['enable_quote_bbcode'], + $unparsed['enable_url_bbcode'] ); // Save the new text if it has changed diff --git a/phpBB/phpbb/textreparser/row_based_plugin.php b/phpBB/phpbb/textreparser/row_based_plugin.php index 80525a404e..e39ec4d5d3 100644 --- a/phpBB/phpbb/textreparser/row_based_plugin.php +++ b/phpBB/phpbb/textreparser/row_based_plugin.php @@ -44,38 +44,6 @@ abstract class row_based_plugin extends base */ abstract public function get_table_name(); - /** - * Add fields to given row, if applicable - * - * The enable_* fields are not always saved to the database. Sometimes we need to guess their - * original value based on the text content or possibly other fields - * - * @param array $row Original row - * @return array Complete row - */ - protected function add_missing_fields(array $row) - { - if (!isset($row['enable_bbcode'], $row['enable_smilies'], $row['enable_magic_url'])) - { - $row += array( - 'enable_bbcode' => !empty($row['bbcode_uid']), - 'enable_smilies' => $this->guess_smilies($row), - 'enable_magic_url' => $this->guess_magic_url($row), - ); - } - - // Those BBCodes are disabled based on context and user permissions and that value is never - // stored in the database. Here we test whether they were used in the original text. - $bbcodes = array('flash', 'img', 'quote', 'url'); - foreach ($bbcodes as $bbcode) - { - $field_name = 'enable_' . $bbcode; - $row[$field_name] = $this->guess_bbcode($row, $bbcode); - } - - return $row; - } - /** * {@inheritdoc} */ diff --git a/tests/text_reparser/fixtures/privmsgs.xml b/tests/text_reparser/fixtures/privmsgs.xml new file mode 100644 index 0000000000..9ca49a2af8 --- /dev/null +++ b/tests/text_reparser/fixtures/privmsgs.xml @@ -0,0 +1,73 @@ + + + + msg_id + enable_bbcode + enable_smilies + enable_magic_url + message_text + bbcode_uid + to_address + bcc_address + + 1 + 1 + 1 + 1 + This row should be [b]ignored[/b] + abcd1234 + + + + + 2 + 0 + 0 + 0 + [b]Not bold[/b] :) http://example.org + abcd1234 + + + + + 3 + 1 + 0 + 0 + [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + abcd1234 + + + + + 4 + 0 + 1 + 0 + :) http://example.org]]> + abcd1234 + + + + + 5 + 0 + 0 + 1 + http://example.org]]> + abcd1234 + + + + + 1000 + 1 + 1 + 1 + This row should be [b]ignored[/b] + abcd1234 + + + +
+
diff --git a/tests/text_reparser/pm_text_test.php b/tests/text_reparser/pm_text_test.php new file mode 100644 index 0000000000..6b409d27e3 --- /dev/null +++ b/tests/text_reparser/pm_text_test.php @@ -0,0 +1,26 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_pm_text_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/privmsgs.xml'); + } + + public function get_reparser() + { + return new \phpbb\textreparser\plugins\pm_text($this->db); + } +} From 70cd911281056ecb4eefc23e678126e1747debc8 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 2 May 2015 08:51:56 +0200 Subject: [PATCH 08/27] [ticket/13803] Added tests PHPBB3-13803 --- phpBB/phpbb/textreparser/base.php | 50 ++++++++++++++++--- tests/text_reparser/fixtures/posts.xml | 32 ++++++++++++ tests/text_reparser/fixtures/privmsgs.xml | 40 +++++++++++++++ tests/text_reparser/test_row_based_plugin.php | 40 ++++++++++++--- 4 files changed, 149 insertions(+), 13 deletions(-) diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 2d4a4171af..865b0662f9 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -43,7 +43,7 @@ abstract class base implements reparser_interface if (!isset($record['enable_bbcode'], $record['enable_smilies'], $record['enable_magic_url'])) { $record += array( - 'enable_bbcode' => !empty($record['bbcode_uid']), + 'enable_bbcode' => $this->guess_bbcodes($record), 'enable_smilies' => $this->guess_smilies($record), 'enable_magic_url' => $this->guess_magic_url($record), ); @@ -58,6 +58,13 @@ abstract class base implements reparser_interface $record[$field_name] = $this->guess_bbcode($record, $bbcode); } + // Magic URLs are tied to the URL BBCode, that's why if magic URLs are enabled we make sure + // that the URL BBCode is also enabled + if ($record['enable_magic_url']) + { + $record['enable_url_bbcode'] = true; + } + return $record; } @@ -74,7 +81,7 @@ abstract class base implements reparser_interface { // Look for the closing tag, e.g. [/url] $match = '[/' . $bbcode . ':' . $record['bbcode_uid']; - if (stripos($record['text'], $match) !== false) + if (strpos($record['text'], $match) !== false) { return true; } @@ -84,8 +91,8 @@ abstract class base implements reparser_interface { // Look for the closing tag inside of a e element, in an element of the same name, e.g. // [/url]
- $match = '[/' . $bbcode . ']'; - if (stripos($record['text'], $match) !== false) + $match = '[/' . $bbcode . ']'; + if (strpos($record['text'], $match) !== false) { return true; } @@ -94,6 +101,33 @@ abstract class base implements reparser_interface return false; } + /** + * Guess whether any BBCode is in use in given record + * + * @param array $record + * @return bool + */ + protected function guess_bbcodes(array $record) + { + if (!empty($record['bbcode_uid'])) + { + // Test whether the bbcode_uid is in use + $match = ':' . $record['bbcode_uid']; + if (strpos($record['text'], $match) !== false) + { + return true; + } + } + + if (substr($record['text'], 0, 2) == '\\[/\\w+\\])', $match); + } + + return false; + } + /** * Guess whether magic URLs are in use in given record * @@ -103,7 +137,7 @@ abstract class base implements reparser_interface protected function guess_magic_url(array $record) { // Look for or for a URL tag that's not immediately followed by - return (strpos($record['text'], '') !== false || preg_match('(]++>(?!))', strpos($row['text']))); + return (strpos($record['text'], '') !== false || preg_match('(]++>(?!))', $record['text'])); } /** @@ -114,7 +148,7 @@ abstract class base implements reparser_interface */ protected function guess_smilies(array $record) { - return (strpos($row['text'], 'http://example.org]]> abcd1234 + + 6 + 1 + 1 + 0 + + abcd1234 + + + 7 + 1 + 1 + 0 + + abcd1234 + + + 8 + 1 + 1 + 0 + + abcd1234 + + + 9 + 1 + 1 + 0 + + abcd1234 + 1000 1 diff --git a/tests/text_reparser/fixtures/privmsgs.xml b/tests/text_reparser/fixtures/privmsgs.xml index 9ca49a2af8..4049b9890a 100644 --- a/tests/text_reparser/fixtures/privmsgs.xml +++ b/tests/text_reparser/fixtures/privmsgs.xml @@ -59,6 +59,46 @@ + + 6 + 1 + 1 + 0 + + abcd1234 + + + + + 7 + 1 + 1 + 0 + + abcd1234 + + + + + 8 + 1 + 1 + 0 + + abcd1234 + + + + + 9 + 1 + 1 + 0 + + abcd1234 + + + 1000 1 diff --git a/tests/text_reparser/test_row_based_plugin.php b/tests/text_reparser/test_row_based_plugin.php index 7dd90f21d0..405341e2fc 100644 --- a/tests/text_reparser/test_row_based_plugin.php +++ b/tests/text_reparser/test_row_based_plugin.php @@ -62,31 +62,59 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t 5, array( array( - 'id' => 1, + 'id' => '1', 'text' => 'This row should be [b]ignored[/b]', ), array( - 'id' => 2, + 'id' => '2', 'text' => '[b]Not bold[/b] :) http://example.org', ), array( - 'id' => 3, + 'id' => '3', 'text' => '[b]Bold[/b] :) http://example.org', ), array( - 'id' => 4, + 'id' => '4', 'text' => '[b]Not bold[/b] :) http://example.org', ), array( - 'id' => 5, + 'id' => '5', 'text' => '[b]Not bold[/b] :) http://example.org', ), array( - 'id' => 1000, + 'id' => '1000', 'text' => 'This row should be [b]ignored[/b]', ), ) ), + array( + 6, + 7, + array( + array( + 'id' => '6', + 'text' => '[flash=123,345]http://example.org/flash.swf[/flash]', + ), + array( + 'id' => '7', + 'text' => '[flash=123,345]http://example.org/flash.swf[/flash]', + ), + ) + ), + array( + 8, + 9, + array( + array( + 'id' => '8', + 'text' => '[img]http://example.org/img.png[/img]', + ), + array( + 'id' => '9', + 'text' => '[img]http://example.org/img.png[/img]', + ), + ) + ), ); } } From 6ab524f8dcf8f918159ba584a659dd88dc9ca3b9 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 3 May 2015 01:39:56 +0200 Subject: [PATCH 09/27] [ticket/13803] Added tests PHPBB3-13803 --- tests/text_reparser/fixtures/forums.xml | 91 +++++++++++++++++++ .../text_reparser/forum_description_test.php | 26 ++++++ tests/text_reparser/forum_rules_test.php | 26 ++++++ 3 files changed, 143 insertions(+) create mode 100644 tests/text_reparser/fixtures/forums.xml create mode 100644 tests/text_reparser/forum_description_test.php create mode 100644 tests/text_reparser/forum_rules_test.php diff --git a/tests/text_reparser/fixtures/forums.xml b/tests/text_reparser/fixtures/forums.xml new file mode 100644 index 0000000000..39c172c969 --- /dev/null +++ b/tests/text_reparser/fixtures/forums.xml @@ -0,0 +1,91 @@ + + + + forum_id + forum_parents + forum_desc + forum_desc_uid + forum_rules + forum_rules_uid + + 1 + + This row should be [b]ignored[/b] + abcd1234 + This row should be [b]ignored[/b] + abcd1234 + + + 2 + + [b]Not bold[/b] :) http://example.org + abcd1234 + [b]Not bold[/b] :) http://example.org + abcd1234 + + + 3 + + [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + abcd1234 + [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + abcd1234 + + + 4 + + :) http://example.org]]> + abcd1234 + :) http://example.org]]> + abcd1234 + + + 5 + + http://example.org]]> + abcd1234 + http://example.org]]> + abcd1234 + + + 6 + + + abcd1234 + + abcd1234 + + + 7 + + + abcd1234 + + abcd1234 + + + 8 + + + abcd1234 + + abcd1234 + + + 9 + + + abcd1234 + + abcd1234 + + + 1000 + + This row should be [b]ignored[/b] + abcd1234 + This row should be [b]ignored[/b] + abcd1234 + +
+
diff --git a/tests/text_reparser/forum_description_test.php b/tests/text_reparser/forum_description_test.php new file mode 100644 index 0000000000..66ed261a6f --- /dev/null +++ b/tests/text_reparser/forum_description_test.php @@ -0,0 +1,26 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_forum_description_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/forums.xml'); + } + + public function get_reparser() + { + return new \phpbb\textreparser\plugins\forum_description($this->db); + } +} diff --git a/tests/text_reparser/forum_rules_test.php b/tests/text_reparser/forum_rules_test.php new file mode 100644 index 0000000000..c89f47cf8e --- /dev/null +++ b/tests/text_reparser/forum_rules_test.php @@ -0,0 +1,26 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_forum_rules_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/forums.xml'); + } + + public function get_reparser() + { + return new \phpbb\textreparser\plugins\forum_rules($this->db); + } +} From d42b2fe795de913894c0cc9f1df084f8ef0c58f9 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 3 May 2015 02:05:20 +0200 Subject: [PATCH 10/27] [ticket/13803] Sort test rows in SQL to match the expected result PHPBB3-13803 --- tests/text_reparser/test_row_based_plugin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/text_reparser/test_row_based_plugin.php b/tests/text_reparser/test_row_based_plugin.php index 405341e2fc..0258745bf2 100644 --- a/tests/text_reparser/test_row_based_plugin.php +++ b/tests/text_reparser/test_row_based_plugin.php @@ -47,7 +47,8 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t $columns = $reparser->get_columns(); $sql = 'SELECT ' . $columns['id'] . ' AS id, ' . $columns['text'] . ' AS text FROM ' . $reparser->get_table_name() . ' - WHERE ' . $this->db->sql_in_set($columns['id'], $ids); + WHERE ' . $this->db->sql_in_set($columns['id'], $ids) . ' + ORDER BY id'; $result = $this->db->sql_query($sql); $rows = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); From 212fc277b481440a99ff0483e5fbc40c790e8dda Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 6 May 2015 13:01:09 +0200 Subject: [PATCH 11/27] [ticket/13803] Reordered methods [ci skip] PHPBB3-13803 --- phpBB/phpbb/textreparser/base.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 865b0662f9..85327cdfce 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -29,6 +29,11 @@ abstract class base implements reparser_interface */ abstract protected function get_records($min_id, $max_id); + /** + * {@inheritdoc} + */ + abstract protected function save_record(array $record); + /** * Add fields to given record, if applicable * @@ -202,9 +207,4 @@ abstract class base implements reparser_interface $this->save_record($record); } } - - /** - * {@inheritdoc} - */ - abstract protected function save_record(array $record); } From a870f8f8603993a2d6a2443c8ad746212071f392 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 6 May 2015 21:32:39 +0200 Subject: [PATCH 12/27] [ticket/13803] Added user_signature tests PHPBB3-13803 --- .../textreparser/plugins/user_signature.php | 27 +++--- tests/text_reparser/fixtures/users.xml | 91 +++++++++++++++++++ .../text_reparser/forum_description_test.php | 2 +- tests/text_reparser/forum_rules_test.php | 2 +- tests/text_reparser/pm_text_test.php | 2 +- tests/text_reparser/post_text_test.php | 2 +- tests/text_reparser/test_row_based_plugin.php | 2 + tests/text_reparser/user_signature_test.php | 26 ++++++ 8 files changed, 138 insertions(+), 16 deletions(-) create mode 100644 tests/text_reparser/fixtures/users.xml create mode 100644 tests/text_reparser/user_signature_test.php diff --git a/phpBB/phpbb/textreparser/plugins/user_signature.php b/phpBB/phpbb/textreparser/plugins/user_signature.php index db82d4089b..f657a45d38 100644 --- a/phpBB/phpbb/textreparser/plugins/user_signature.php +++ b/phpBB/phpbb/textreparser/plugins/user_signature.php @@ -21,22 +21,16 @@ class user_signature extends \phpbb\textreparser\row_based_plugin */ protected $keyoptions; - /** - * Constructor - * - * Retrieves and saves the bit numbers used for user options - */ - public function __construct() - { - $class_vars = get_class_vars('phpbb\\user'); - $this->keyoptions = $class_vars['keyoptions']; - } - /** * {@inheritdoc} */ protected function add_missing_fields(array $row) { + if (!isset($this->keyoptions)) + { + $this->save_keyoptions(); + } + $options = $row['user_options']; $row += array( 'enable_bbcode' => phpbb_optionget($this->keyoptions['sig_bbcode'], $options), @@ -44,7 +38,7 @@ class user_signature extends \phpbb\textreparser\row_based_plugin 'enable_magic_url' => phpbb_optionget($this->keyoptions['sig_links'], $options), ); - return $row; + return parent::add_missing_fields($row); } /** @@ -67,4 +61,13 @@ class user_signature extends \phpbb\textreparser\row_based_plugin { return USERS_TABLE; } + + /** + * Save the keyoptions var from \phpbb\user + */ + protected function save_keyoptions() + { + $class_vars = get_class_vars('phpbb\\user'); + $this->keyoptions = $class_vars['keyoptions']; + } } diff --git a/tests/text_reparser/fixtures/users.xml b/tests/text_reparser/fixtures/users.xml new file mode 100644 index 0000000000..60c623b6b1 --- /dev/null +++ b/tests/text_reparser/fixtures/users.xml @@ -0,0 +1,91 @@ + + + + user_id + user_permissions + username_clean + user_options + user_sig + user_sig_bbcode_uid + + 1 + + user1 + 230271 + This row should be [b]ignored[/b] + abcd1234 + + + 2 + + user2 + 895 + [b]Not bold[/b] :) http://example.org + abcd1234 + + + 3 + + user3 + 33663 + [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + abcd1234 + + + 4 + + user4 + 66431 + :) http://example.org]]> + abcd1234 + + + 5 + + user5 + 131967 + http://example.org]]> + abcd1234 + + + 6 + + user6 + 99199 + + abcd1234 + + + 7 + + user7 + 99199 + + abcd1234 + + + 8 + + user8 + 99199 + + abcd1234 + + + 9 + + user9 + 99199 + + abcd1234 + + + 1000 + + user1000 + 230271 + This row should be [b]ignored[/b] + abcd1234 + +
+
diff --git a/tests/text_reparser/forum_description_test.php b/tests/text_reparser/forum_description_test.php index 66ed261a6f..3b739353cd 100644 --- a/tests/text_reparser/forum_description_test.php +++ b/tests/text_reparser/forum_description_test.php @@ -19,7 +19,7 @@ class phpbb_textreparser_forum_description_test extends phpbb_textreparser_test_ return $this->createXMLDataSet(__DIR__ . '/fixtures/forums.xml'); } - public function get_reparser() + protected function get_reparser() { return new \phpbb\textreparser\plugins\forum_description($this->db); } diff --git a/tests/text_reparser/forum_rules_test.php b/tests/text_reparser/forum_rules_test.php index c89f47cf8e..4c267c9014 100644 --- a/tests/text_reparser/forum_rules_test.php +++ b/tests/text_reparser/forum_rules_test.php @@ -19,7 +19,7 @@ class phpbb_textreparser_forum_rules_test extends phpbb_textreparser_test_row_ba return $this->createXMLDataSet(__DIR__ . '/fixtures/forums.xml'); } - public function get_reparser() + protected function get_reparser() { return new \phpbb\textreparser\plugins\forum_rules($this->db); } diff --git a/tests/text_reparser/pm_text_test.php b/tests/text_reparser/pm_text_test.php index 6b409d27e3..3896a57e98 100644 --- a/tests/text_reparser/pm_text_test.php +++ b/tests/text_reparser/pm_text_test.php @@ -19,7 +19,7 @@ class phpbb_textreparser_pm_text_test extends phpbb_textreparser_test_row_based_ return $this->createXMLDataSet(__DIR__ . '/fixtures/privmsgs.xml'); } - public function get_reparser() + protected function get_reparser() { return new \phpbb\textreparser\plugins\pm_text($this->db); } diff --git a/tests/text_reparser/post_text_test.php b/tests/text_reparser/post_text_test.php index ac540f170c..0f934a06ee 100644 --- a/tests/text_reparser/post_text_test.php +++ b/tests/text_reparser/post_text_test.php @@ -19,7 +19,7 @@ class phpbb_textreparser_post_text_test extends phpbb_textreparser_test_row_base return $this->createXMLDataSet(__DIR__ . '/fixtures/posts.xml'); } - public function get_reparser() + protected function get_reparser() { return new \phpbb\textreparser\plugins\post_text($this->db); } diff --git a/tests/text_reparser/test_row_based_plugin.php b/tests/text_reparser/test_row_based_plugin.php index 0258745bf2..4d4d64a56d 100644 --- a/tests/text_reparser/test_row_based_plugin.php +++ b/tests/text_reparser/test_row_based_plugin.php @@ -18,6 +18,8 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t { protected $db; + abstract protected function get_reparser(); + public function setUp() { global $config; diff --git a/tests/text_reparser/user_signature_test.php b/tests/text_reparser/user_signature_test.php new file mode 100644 index 0000000000..ab830a303d --- /dev/null +++ b/tests/text_reparser/user_signature_test.php @@ -0,0 +1,26 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_user_signature_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/users.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\user_signature($this->db); + } +} From b0eb63e5b9315e8a6f96ea308a835cb7fd712753 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 7 May 2015 11:40:54 +0200 Subject: [PATCH 13/27] [ticket/13803] Added group_description tests PHPBB3-13803 --- tests/text_reparser/fixtures/groups.xml | 69 +++++++++++++++++++ .../text_reparser/group_description_test.php | 26 +++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/text_reparser/fixtures/groups.xml create mode 100644 tests/text_reparser/group_description_test.php diff --git a/tests/text_reparser/fixtures/groups.xml b/tests/text_reparser/fixtures/groups.xml new file mode 100644 index 0000000000..d3df0131a3 --- /dev/null +++ b/tests/text_reparser/fixtures/groups.xml @@ -0,0 +1,69 @@ + + + + group_id + group_desc + group_desc_options + group_desc_uid + + 1 + This row should be [b]ignored[/b] + 7 + abcd1234 + + + 2 + [b]Not bold[/b] :) http://example.org + 0 + abcd1234 + + + 3 + [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + 1 + abcd1234 + + + 4 + :) http://example.org]]> + 2 + abcd1234 + + + 5 + http://example.org]]> + 4 + abcd1234 + + + 6 + + 7 + abcd1234 + + + 7 + + 7 + abcd1234 + + + 8 + + 7 + abcd1234 + + + 9 + + 7 + abcd1234 + + + 1000 + This row should be [b]ignored[/b] + 7 + abcd1234 + +
+
diff --git a/tests/text_reparser/group_description_test.php b/tests/text_reparser/group_description_test.php new file mode 100644 index 0000000000..51035903e1 --- /dev/null +++ b/tests/text_reparser/group_description_test.php @@ -0,0 +1,26 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_group_description_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/groups.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\group_description($this->db); + } +} From 8ef15d10e6295eb26fd292a411a8f1edd3853287 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 9 May 2015 18:07:19 +0200 Subject: [PATCH 14/27] [ticket/13803] Added poll_title tests PHPBB3-13803 --- tests/text_reparser/fixtures/polls.xml | 68 +++++++++++++++++++++++++ tests/text_reparser/poll_title_test.php | 26 ++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/text_reparser/fixtures/polls.xml create mode 100644 tests/text_reparser/poll_title_test.php diff --git a/tests/text_reparser/fixtures/polls.xml b/tests/text_reparser/fixtures/polls.xml new file mode 100644 index 0000000000..9baf813c97 --- /dev/null +++ b/tests/text_reparser/fixtures/polls.xml @@ -0,0 +1,68 @@ + + + + post_id + post_text + bbcode_uid + + 1 + + abcd1234 + +
+ + topic_id + topic_first_post_id + poll_title + + 1 + 1 + This row should be [b]ignored[/b] + + + 2 + 1 + [b]Not bold[/b] :) http://example.org + + + 3 + 1 + [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + + + 4 + 1 + :) http://example.org]]> + + + 5 + 1 + http://example.org]]> + + + 6 + 1 + + + + 7 + 1 + + + + 8 + 1 + + + + 9 + 1 + + + + 1000 + 1 + This row should be [b]ignored[/b] + +
+
diff --git a/tests/text_reparser/poll_title_test.php b/tests/text_reparser/poll_title_test.php new file mode 100644 index 0000000000..76ca2ee228 --- /dev/null +++ b/tests/text_reparser/poll_title_test.php @@ -0,0 +1,26 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_poll_title_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/polls.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\poll_title($this->db); + } +} From 2dc19cec9d3cb0c1e9ab8ef0afd7515f4bb7cee1 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 9 May 2015 18:14:03 +0200 Subject: [PATCH 15/27] [ticket/13803] Added poll_option tests PHPBB3-13803 --- tests/text_reparser/fixtures/poll_options.xml | 78 +++++++++++++++++++ tests/text_reparser/poll_option_test.php | 26 +++++++ 2 files changed, 104 insertions(+) create mode 100644 tests/text_reparser/fixtures/poll_options.xml create mode 100644 tests/text_reparser/poll_option_test.php diff --git a/tests/text_reparser/fixtures/poll_options.xml b/tests/text_reparser/fixtures/poll_options.xml new file mode 100644 index 0000000000..f0ed54aafb --- /dev/null +++ b/tests/text_reparser/fixtures/poll_options.xml @@ -0,0 +1,78 @@ + + + + poll_option_id + topic_id + poll_option_text + + 1 + 1 + This row should be [b]ignored[/b] + + + 2 + 1 + [b]Not bold[/b] :) http://example.org + + + 3 + 1 + [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + + + 4 + 1 + :) http://example.org]]> + + + 5 + 1 + http://example.org]]> + + + 6 + 1 + + + + 7 + 1 + + + + 8 + 1 + + + + 9 + 1 + + + + 1000 + 1 + This row should be [b]ignored[/b] + +
+ + post_id + post_text + bbcode_uid + + 1 + + abcd1234 + +
+ + topic_id + topic_first_post_id + poll_title + + 1 + 1 + This row should be [b]ignored[/b] + +
+
diff --git a/tests/text_reparser/poll_option_test.php b/tests/text_reparser/poll_option_test.php new file mode 100644 index 0000000000..0f08f720ff --- /dev/null +++ b/tests/text_reparser/poll_option_test.php @@ -0,0 +1,26 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +include_once __DIR__ . '/test_row_based_plugin.php'; + +class phpbb_textreparser_poll_option_test extends phpbb_textreparser_test_row_based_plugin +{ + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/poll_options.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\poll_option($this->db); + } +} From ae6ad754a430309796e1963684b59c01739ba4dd Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 9 May 2015 18:54:57 +0200 Subject: [PATCH 16/27] [ticket/13803] Moved the add_missing_fields() call to the base class PHPBB3-13803 --- phpBB/phpbb/textreparser/base.php | 1 + phpBB/phpbb/textreparser/row_based_plugin.php | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 85327cdfce..47ac177e05 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -174,6 +174,7 @@ abstract class base implements reparser_interface */ protected function reparse_record(array $record) { + $record = $this->add_missing_fields($record); $unparsed = array_merge( $record, generate_text_for_edit( diff --git a/phpBB/phpbb/textreparser/row_based_plugin.php b/phpBB/phpbb/textreparser/row_based_plugin.php index e39ec4d5d3..6b63ffeeaf 100644 --- a/phpBB/phpbb/textreparser/row_based_plugin.php +++ b/phpBB/phpbb/textreparser/row_based_plugin.php @@ -65,10 +65,7 @@ abstract class row_based_plugin extends base protected function get_records($min_id, $max_id) { $result = $this->db->sql_query($this->get_records_query($min_id, $max_id)); - while ($row = $this->db->sql_fetchrow($result)) - { - $records[] = $this->add_missing_fields($row); - } + $records = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); return $records; From 7a8ac4bb714299d2544ec215c24018fe07caa0ec Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 9 May 2015 19:06:48 +0200 Subject: [PATCH 17/27] [ticket/13803] Added get_max_id() tests PHPBB3-13803 --- phpBB/phpbb/textreparser/row_based_plugin.php | 2 +- tests/text_reparser/test_row_based_plugin.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/textreparser/row_based_plugin.php b/phpBB/phpbb/textreparser/row_based_plugin.php index 6b63ffeeaf..05a6e19553 100644 --- a/phpBB/phpbb/textreparser/row_based_plugin.php +++ b/phpBB/phpbb/textreparser/row_based_plugin.php @@ -51,7 +51,7 @@ abstract class row_based_plugin extends base { $columns = $this->get_columns(); - $sql = 'SELECT MAX(' . $columns['id'] . ' AS max_id FROM ' . $this->get_table_name(); + $sql = 'SELECT MAX(' . $columns['id'] . ') AS max_id FROM ' . $this->get_table_name(); $result = $this->db->sql_query($sql); $max_id = (int) $this->db->sql_fetchfield('max_id'); $this->db->sql_freeresult($result); diff --git a/tests/text_reparser/test_row_based_plugin.php b/tests/text_reparser/test_row_based_plugin.php index 4d4d64a56d..489dff280b 100644 --- a/tests/text_reparser/test_row_based_plugin.php +++ b/tests/text_reparser/test_row_based_plugin.php @@ -32,6 +32,12 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t parent::setUp(); } + public function test_get_max_id() + { + $reparser = $this->get_reparser(); + $this->assertEquals(1000, $reparser->get_max_id()); + } + /** * @dataProvider getReparseTests */ From 3827a131ae11dcd3adf852f80ff4d85e7a7d470b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sat, 9 May 2015 20:12:30 +0200 Subject: [PATCH 18/27] [ticket/13803] Rewrote the poll_option plugin As it turns out, poll_option_id is not a primary key. PHPBB3-13803 --- .../textreparser/plugins/poll_option.php | 50 ++++++++---- tests/text_reparser/fixtures/poll_options.xml | 63 +++++++-------- tests/text_reparser/poll_option_test.php | 78 ++++++++++++++++++- 3 files changed, 142 insertions(+), 49 deletions(-) diff --git a/phpBB/phpbb/textreparser/plugins/poll_option.php b/phpBB/phpbb/textreparser/plugins/poll_option.php index cc28599737..3249e21694 100644 --- a/phpBB/phpbb/textreparser/plugins/poll_option.php +++ b/phpBB/phpbb/textreparser/plugins/poll_option.php @@ -13,38 +13,62 @@ namespace phpbb\textreparser\plugins; -class poll_option extends \phpbb\textreparser\row_based_plugin +class poll_option extends \phpbb\textreparser\base { /** - * {@inheritdoc} + * @var \phpbb\db\driver\driver_interface */ - public function get_columns() + protected $db; + + /** + * Constructor + * + * @param \phpbb\db\driver\driver_interface $db Database connection + */ + public function __construct(\phpbb\db\driver\driver_interface $db) { - return array( - 'id' => 'poll_option_id', - 'text' => 'poll_option_text', - ); + $this->db = $db; } /** * {@inheritdoc} */ - protected function get_records_query($min_id, $max_id) + public function get_max_id() { - $sql = 'SELECT o.poll_option_id AS id, o.poll_option_text AS text, p.bbcode_uid + $sql = 'SELECT MAX(topic_id) AS max_id FROM ' . POLL_OPTIONS_TABLE; + $result = $this->db->sql_query($sql); + $max_id = (int) $this->db->sql_fetchfield('max_id'); + $this->db->sql_freeresult($result); + + return $max_id; + } + + /** + * {@inheritdoc} + */ + protected function get_records($min_id, $max_id) + { + $sql = 'SELECT o.topic_id, o.poll_option_id, o.poll_option_text AS text, p.bbcode_uid FROM ' . POLL_OPTIONS_TABLE . ' o, ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p - WHERE o.poll_option_id BETWEEN ' . $min_id . ' AND ' . $max_id .' + WHERE o.topic_id BETWEEN ' . $min_id . ' AND ' . $max_id .' AND t.topic_id = o.topic_id AND p.post_id = t.topic_first_post_id'; + $result = $this->db->sql_query($sql); + $records = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); - return $sql; + return $records; } /** * {@inheritdoc} */ - public function get_table_name() + protected function save_record(array $record) { - return POLL_OPTIONS_TABLE; + $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " + SET poll_option_text = '" . $this->db->sql_escape($record['text']) . "' + WHERE topic_id = " . $record['topic_id'] . ' + AND poll_option_id = ' . $record['poll_option_id']; + $this->db->sql_query($sql); } } diff --git a/tests/text_reparser/fixtures/poll_options.xml b/tests/text_reparser/fixtures/poll_options.xml index f0ed54aafb..c2fad9f764 100644 --- a/tests/text_reparser/fixtures/poll_options.xml +++ b/tests/text_reparser/fixtures/poll_options.xml @@ -12,48 +12,33 @@ 2 1 - [b]Not bold[/b] :) http://example.org + This row should be [b:abcd1234]ignored[/b:abcd1234] + + + 1 + 2 + [b:abcd1234]Bold[/b:abcd1234] + + + 2 + 2 + :)]]> 3 - 1 - [b:abcd1234]Bold[/b:abcd1234] :) http://example.org + 2 + http://example.org]]> - 4 - 1 - :) http://example.org]]> - - - 5 - 1 - http://example.org]]> - - - 6 - 1 - - - - 7 - 1 - - - - 8 - 1 - - - - 9 - 1 - - - - 1000 1 + 123 This row should be [b]ignored[/b] + + 2 + 123 + This row should be [b:abcd1234]ignored[/b:abcd1234] + post_id @@ -74,5 +59,15 @@ 1This row should be [b]ignored[/b] + + 2 + 1 + This row should be [b]ignored[/b] + + + 123 + 1 + This row should be [b]ignored[/b] +
diff --git a/tests/text_reparser/poll_option_test.php b/tests/text_reparser/poll_option_test.php index 0f08f720ff..669d859f9a 100644 --- a/tests/text_reparser/poll_option_test.php +++ b/tests/text_reparser/poll_option_test.php @@ -10,10 +10,14 @@ * the docs/CREDITS.txt file. * */ -include_once __DIR__ . '/test_row_based_plugin.php'; +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; -class phpbb_textreparser_poll_option_test extends phpbb_textreparser_test_row_based_plugin +class phpbb_textreparser_poll_option_test extends phpbb_database_test_case { + protected $db; + public function getDataSet() { return $this->createXMLDataSet(__DIR__ . '/fixtures/poll_options.xml'); @@ -23,4 +27,74 @@ class phpbb_textreparser_poll_option_test extends phpbb_textreparser_test_row_ba { return new \phpbb\textreparser\plugins\poll_option($this->db); } + + public function setUp() + { + global $config; + if (!isset($config)) + { + $config = new \phpbb\config\config(array()); + } + $this->get_test_case_helpers()->set_s9e_services(); + $this->db = $this->new_dbal(); + parent::setUp(); + } + + public function test_get_max_id() + { + $reparser = $this->get_reparser(); + $this->assertEquals(123, $reparser->get_max_id()); + } + + public function testReparse() + { + $reparser = $this->get_reparser(); + $reparser->reparse_range(2, 3); + + $sql = 'SELECT topic_id, poll_option_id, poll_option_text + FROM ' . POLL_OPTIONS_TABLE . ' + ORDER BY topic_id, poll_option_id'; + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + $expected = array( + array( + 'topic_id' => 1, + 'poll_option_id' => 1, + 'poll_option_text' => 'This row should be [b]ignored[/b]', + ), + array( + 'topic_id' => 1, + 'poll_option_id' => 2, + 'poll_option_text' => 'This row should be [b:abcd1234]ignored[/b:abcd1234]', + ), + array( + 'topic_id' => 2, + 'poll_option_id' => 1, + 'poll_option_text' => '[b]Bold[/b]', + ), + array( + 'topic_id' => 2, + 'poll_option_id' => 2, + 'poll_option_text' => ':)', + ), + array( + 'topic_id' => 2, + 'poll_option_id' => 3, + 'poll_option_text' => 'http://example.org', + ), + array( + 'topic_id' => 123, + 'poll_option_id' => 1, + 'poll_option_text' => 'This row should be [b]ignored[/b]', + ), + array( + 'topic_id' => 123, + 'poll_option_id' => 2, + 'poll_option_text' => 'This row should be [b:abcd1234]ignored[/b:abcd1234]', + ), + ); + $this->assertEquals($expected, $rows); + } } From 54b18df084b845c058426b38e7ccfeb534d04ce0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Sun, 10 May 2015 01:54:54 +0200 Subject: [PATCH 19/27] [ticket/13803] Added contact_admin_info tests PHPBB3-13803 --- .../container/services_text_reparser.yml | 4 +- ...ontact_info.php => contact_admin_info.php} | 4 +- .../text_reparser/contact_admin_info_test.php | 81 +++++++++++++++++++ .../fixtures/contact_admin_info.xml | 23 ++++++ 4 files changed, 108 insertions(+), 4 deletions(-) rename phpBB/phpbb/textreparser/plugins/{admin_contact_info.php => contact_admin_info.php} (91%) create mode 100644 tests/text_reparser/contact_admin_info_test.php create mode 100644 tests/text_reparser/fixtures/contact_admin_info.xml diff --git a/phpBB/config/default/container/services_text_reparser.yml b/phpBB/config/default/container/services_text_reparser.yml index c10a8c600a..f25728d9c8 100644 --- a/phpBB/config/default/container/services_text_reparser.yml +++ b/phpBB/config/default/container/services_text_reparser.yml @@ -1,6 +1,6 @@ services: - text_reparser.admin_contact_info: - class: phpbb\textreparser\plugins\admin_contact_info + text_reparser.contact_admin_info: + class: phpbb\textreparser\plugins\contact_admin_info arguments: - @config_text tags: diff --git a/phpBB/phpbb/textreparser/plugins/admin_contact_info.php b/phpBB/phpbb/textreparser/plugins/contact_admin_info.php similarity index 91% rename from phpBB/phpbb/textreparser/plugins/admin_contact_info.php rename to phpBB/phpbb/textreparser/plugins/contact_admin_info.php index e432ddea81..d21ef89445 100644 --- a/phpBB/phpbb/textreparser/plugins/admin_contact_info.php +++ b/phpBB/phpbb/textreparser/plugins/contact_admin_info.php @@ -13,7 +13,7 @@ namespace phpbb\textreparser\plugins; -class admin_contact_info extends \phpbb\textreparser\base +class contact_admin_info extends \phpbb\textreparser\base { /** * @var \phpbb\config\db_text @@ -64,6 +64,6 @@ class admin_contact_info extends \phpbb\textreparser\base */ protected function save_record(array $record) { - $this->config_text->set('admin_contact_info', $record['text']); + $this->config_text->set('contact_admin_info', $record['text']); } } diff --git a/tests/text_reparser/contact_admin_info_test.php b/tests/text_reparser/contact_admin_info_test.php new file mode 100644 index 0000000000..5cccdfa4d5 --- /dev/null +++ b/tests/text_reparser/contact_admin_info_test.php @@ -0,0 +1,81 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; + +class phpbb_textreparser_contact_admin_info_test extends phpbb_database_test_case +{ + protected $db; + + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__ . '/fixtures/contact_admin_info.xml'); + } + + protected function get_reparser() + { + return new \phpbb\textreparser\plugins\contact_admin_info(new \phpbb\config\db_text($this->db, CONFIG_TEXT_TABLE)); + } + + public function setUp() + { + global $config; + if (!isset($config)) + { + $config = new \phpbb\config\config(array()); + } + $this->get_test_case_helpers()->set_s9e_services(); + $this->db = $this->new_dbal(); + parent::setUp(); + } + + public function test_get_max_id() + { + $reparser = $this->get_reparser(); + $this->assertEquals(1, $reparser->get_max_id()); + } + + public function testReparse() + { + $reparser = $this->get_reparser(); + $reparser->reparse_range(1, 1); + + $sql = 'SELECT config_name, config_value + FROM ' . CONFIG_TEXT_TABLE . ' + ORDER BY config_name'; + $result = $this->db->sql_query($sql); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + $expected = array( + array( + 'config_name' => 'contact_admin_info', + 'config_value' => '[email]admin@example.org[/email]', + ), + array( + 'config_name' => 'contact_admin_info_bitfield', + 'config_value' => 'ACA=', + ), + array( + 'config_name' => 'contact_admin_info_flags', + 'config_value' => '7', + ), + array( + 'config_name' => 'contact_admin_info_uid', + 'config_value' => '1a2hbwf5', + ), + ); + $this->assertEquals($expected, $rows); + } +} diff --git a/tests/text_reparser/fixtures/contact_admin_info.xml b/tests/text_reparser/fixtures/contact_admin_info.xml new file mode 100644 index 0000000000..13cd82b1a4 --- /dev/null +++ b/tests/text_reparser/fixtures/contact_admin_info.xml @@ -0,0 +1,23 @@ + + + + config_name + config_value + + contact_admin_info + [email:1a2hbwf5]admin@example.org[/email:1a2hbwf5] + + + contact_admin_info_uid + 1a2hbwf5 + + + contact_admin_info_bitfield + ACA= + + + contact_admin_info_flags + 7 + +
+
From 75eb283f8d7a7afcd3945d0d28bd0f58aa4f0cd6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 19 May 2015 09:48:29 +0200 Subject: [PATCH 20/27] [ticket/13803] Renamed methods PHPBB3-13803 --- phpBB/phpbb/textreparser/base.php | 6 +++--- phpBB/phpbb/textreparser/plugins/contact_admin_info.php | 2 +- phpBB/phpbb/textreparser/plugins/poll_option.php | 2 +- phpBB/phpbb/textreparser/reparser_interface.php | 4 ++-- phpBB/phpbb/textreparser/row_based_plugin.php | 7 ++++--- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 47ac177e05..2b8cacb092 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -25,9 +25,9 @@ abstract class base implements reparser_interface * * @param integer $min_id Lower bound * @param integer $max_id Upper bound - * @return array Array of record + * @return array Array of records */ - abstract protected function get_records($min_id, $max_id); + abstract protected function get_records_by_range($min_id, $max_id); /** * {@inheritdoc} @@ -161,7 +161,7 @@ abstract class base implements reparser_interface */ public function reparse_range($min_id, $max_id) { - foreach ($this->get_records($min_id, $max_id) as $record) + foreach ($this->get_records_by_range($min_id, $max_id) as $record) { $this->reparse_record($record); } diff --git a/phpBB/phpbb/textreparser/plugins/contact_admin_info.php b/phpBB/phpbb/textreparser/plugins/contact_admin_info.php index d21ef89445..8910f2256b 100644 --- a/phpBB/phpbb/textreparser/plugins/contact_admin_info.php +++ b/phpBB/phpbb/textreparser/plugins/contact_admin_info.php @@ -41,7 +41,7 @@ class contact_admin_info extends \phpbb\textreparser\base /** * {@inheritdoc} */ - protected function get_records($min_id, $max_id) + protected function get_records_by_range($min_id, $max_id) { $values = $this->config_text->get_array(array( 'contact_admin_info', diff --git a/phpBB/phpbb/textreparser/plugins/poll_option.php b/phpBB/phpbb/textreparser/plugins/poll_option.php index 3249e21694..7b803146c4 100644 --- a/phpBB/phpbb/textreparser/plugins/poll_option.php +++ b/phpBB/phpbb/textreparser/plugins/poll_option.php @@ -46,7 +46,7 @@ class poll_option extends \phpbb\textreparser\base /** * {@inheritdoc} */ - protected function get_records($min_id, $max_id) + 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 FROM ' . POLL_OPTIONS_TABLE . ' o, ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p diff --git a/phpBB/phpbb/textreparser/reparser_interface.php b/phpBB/phpbb/textreparser/reparser_interface.php index 20f8d92b1a..9ea1732870 100644 --- a/phpBB/phpbb/textreparser/reparser_interface.php +++ b/phpBB/phpbb/textreparser/reparser_interface.php @@ -25,8 +25,8 @@ interface reparser_interface /** * Reparse all records in given range * - * @param integer $min_id Lower bound - * @param integer $max_id Upper bound + * @param integer $min_id Lower bound + * @param integer $max_id Upper bound */ public function reparse_range($min_id, $max_id); } diff --git a/phpBB/phpbb/textreparser/row_based_plugin.php b/phpBB/phpbb/textreparser/row_based_plugin.php index 05a6e19553..d3ca334591 100644 --- a/phpBB/phpbb/textreparser/row_based_plugin.php +++ b/phpBB/phpbb/textreparser/row_based_plugin.php @@ -62,9 +62,10 @@ abstract class row_based_plugin extends base /** * {@inheritdoc} */ - protected function get_records($min_id, $max_id) + protected function get_records_by_range($min_id, $max_id) { - $result = $this->db->sql_query($this->get_records_query($min_id, $max_id)); + $sql = $this->get_records_by_range_query($min_id, $max_id); + $result = $this->db->sql_query($sql); $records = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); @@ -78,7 +79,7 @@ abstract class row_based_plugin extends base * @param integer $max_id Upper bound * @return string SQL query */ - protected function get_records_query($min_id, $max_id) + protected function get_records_by_range_query($min_id, $max_id) { $columns = $this->get_columns(); $fields = array(); From 1bff7d1175cb92f10d9fc872c2bae05b1f955174 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 19 May 2015 11:29:52 +0200 Subject: [PATCH 21/27] [ticket/13803] Fixed method name PHPBB3-13803 --- phpBB/phpbb/textreparser/plugins/poll_title.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/textreparser/plugins/poll_title.php b/phpBB/phpbb/textreparser/plugins/poll_title.php index 6665d68847..b447004527 100644 --- a/phpBB/phpbb/textreparser/plugins/poll_title.php +++ b/phpBB/phpbb/textreparser/plugins/poll_title.php @@ -29,7 +29,7 @@ class poll_title extends \phpbb\textreparser\row_based_plugin /** * {@inheritdoc} */ - protected function get_records_query($min_id, $max_id) + 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 FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p From f463b99ad0e6592567ed5a7fa5d2e765089b80ae Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 20 May 2015 04:03:40 +0200 Subject: [PATCH 22/27] [ticket/13803] Updated services.yml [ci skip] PHPBB3-13803 --- phpBB/config/default/container/services.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index 6577a44195..a6b133853a 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -17,6 +17,7 @@ imports: - { resource: services_report.yml } - { resource: services_routing.yml } - { resource: services_text_formatter.yml } + - { resource: services_text_reparser.yml } - { resource: services_twig.yml } - { resource: services_user.yml } From 1275f77da5e1522d530bee55a5aa493817f58e71 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 20 May 2015 10:34:49 +0200 Subject: [PATCH 23/27] [ticket/13803] Renamed var PHPBB3-13803 --- phpBB/phpbb/textreparser/base.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 2b8cacb092..4afcecff6a 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -185,10 +185,10 @@ abstract class base implements reparser_interface ); // generate_text_for_edit() and decode_message() actually return the text as HTML. It has to // be decoded to plain text before it can be reparsed - $parsed_text = html_entity_decode($unparsed['text'], ENT_QUOTES, 'UTF-8'); + $text = html_entity_decode($unparsed['text'], ENT_QUOTES, 'UTF-8'); $bitfield = $flags = null; generate_text_for_storage( - $parsed_text, + $text, $unparsed['bbcode_uid'], $bitfield, $flags, @@ -202,9 +202,9 @@ abstract class base implements reparser_interface ); // Save the new text if it has changed - if ($parsed_text !== $record['text']) + if ($text !== $record['text']) { - $record['text'] = $parsed_text; + $record['text'] = $text; $this->save_record($record); } } From c8052ea8230cf7bb70c979dfc87b04527635f4b0 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 29 May 2015 17:35:26 +0200 Subject: [PATCH 24/27] [ticket/13803] Set up a global $user for tests PHPBB3-13803 --- tests/test_framework/phpbb_test_case_helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 210cda9a94..cf530cc5be 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -315,7 +315,7 @@ class phpbb_test_case_helpers public function set_s9e_services(ContainerInterface $container = null, $fixture = null, $styles_path = null) { static $first_run; - global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx; + global $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx, $user; $cache_dir = __DIR__ . '/../tmp/'; From 132282634ff746c6c4627b87e307df3748f7bbd9 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 29 May 2015 17:36:06 +0200 Subject: [PATCH 25/27] [ticket/13803] Moved tests to a subdir PHPBB3-13803 --- .../text_reparser/{ => plugins}/contact_admin_info_test.php | 6 +++--- .../{ => plugins}/fixtures/contact_admin_info.xml | 0 tests/text_reparser/{ => plugins}/fixtures/forums.xml | 0 tests/text_reparser/{ => plugins}/fixtures/groups.xml | 0 tests/text_reparser/{ => plugins}/fixtures/poll_options.xml | 0 tests/text_reparser/{ => plugins}/fixtures/polls.xml | 0 tests/text_reparser/{ => plugins}/fixtures/posts.xml | 0 tests/text_reparser/{ => plugins}/fixtures/privmsgs.xml | 0 tests/text_reparser/{ => plugins}/fixtures/users.xml | 0 .../text_reparser/{ => plugins}/forum_description_test.php | 0 tests/text_reparser/{ => plugins}/forum_rules_test.php | 0 .../text_reparser/{ => plugins}/group_description_test.php | 0 tests/text_reparser/{ => plugins}/pm_text_test.php | 0 tests/text_reparser/{ => plugins}/poll_option_test.php | 6 +++--- tests/text_reparser/{ => plugins}/poll_title_test.php | 0 tests/text_reparser/{ => plugins}/post_text_test.php | 0 tests/text_reparser/{ => plugins}/test_row_based_plugin.php | 6 +++--- tests/text_reparser/{ => plugins}/user_signature_test.php | 0 18 files changed, 9 insertions(+), 9 deletions(-) rename tests/text_reparser/{ => plugins}/contact_admin_info_test.php (89%) rename tests/text_reparser/{ => plugins}/fixtures/contact_admin_info.xml (100%) rename tests/text_reparser/{ => plugins}/fixtures/forums.xml (100%) rename tests/text_reparser/{ => plugins}/fixtures/groups.xml (100%) rename tests/text_reparser/{ => plugins}/fixtures/poll_options.xml (100%) rename tests/text_reparser/{ => plugins}/fixtures/polls.xml (100%) rename tests/text_reparser/{ => plugins}/fixtures/posts.xml (100%) rename tests/text_reparser/{ => plugins}/fixtures/privmsgs.xml (100%) rename tests/text_reparser/{ => plugins}/fixtures/users.xml (100%) rename tests/text_reparser/{ => plugins}/forum_description_test.php (100%) rename tests/text_reparser/{ => plugins}/forum_rules_test.php (100%) rename tests/text_reparser/{ => plugins}/group_description_test.php (100%) rename tests/text_reparser/{ => plugins}/pm_text_test.php (100%) rename tests/text_reparser/{ => plugins}/poll_option_test.php (91%) rename tests/text_reparser/{ => plugins}/poll_title_test.php (100%) rename tests/text_reparser/{ => plugins}/post_text_test.php (100%) rename tests/text_reparser/{ => plugins}/test_row_based_plugin.php (93%) rename tests/text_reparser/{ => plugins}/user_signature_test.php (100%) diff --git a/tests/text_reparser/contact_admin_info_test.php b/tests/text_reparser/plugins/contact_admin_info_test.php similarity index 89% rename from tests/text_reparser/contact_admin_info_test.php rename to tests/text_reparser/plugins/contact_admin_info_test.php index 5cccdfa4d5..e577d2fd3d 100644 --- a/tests/text_reparser/contact_admin_info_test.php +++ b/tests/text_reparser/plugins/contact_admin_info_test.php @@ -10,9 +10,9 @@ * the docs/CREDITS.txt file. * */ -require_once __DIR__ . '/../../phpBB/includes/functions.php'; -require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; -require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php'; class phpbb_textreparser_contact_admin_info_test extends phpbb_database_test_case { diff --git a/tests/text_reparser/fixtures/contact_admin_info.xml b/tests/text_reparser/plugins/fixtures/contact_admin_info.xml similarity index 100% rename from tests/text_reparser/fixtures/contact_admin_info.xml rename to tests/text_reparser/plugins/fixtures/contact_admin_info.xml diff --git a/tests/text_reparser/fixtures/forums.xml b/tests/text_reparser/plugins/fixtures/forums.xml similarity index 100% rename from tests/text_reparser/fixtures/forums.xml rename to tests/text_reparser/plugins/fixtures/forums.xml diff --git a/tests/text_reparser/fixtures/groups.xml b/tests/text_reparser/plugins/fixtures/groups.xml similarity index 100% rename from tests/text_reparser/fixtures/groups.xml rename to tests/text_reparser/plugins/fixtures/groups.xml diff --git a/tests/text_reparser/fixtures/poll_options.xml b/tests/text_reparser/plugins/fixtures/poll_options.xml similarity index 100% rename from tests/text_reparser/fixtures/poll_options.xml rename to tests/text_reparser/plugins/fixtures/poll_options.xml diff --git a/tests/text_reparser/fixtures/polls.xml b/tests/text_reparser/plugins/fixtures/polls.xml similarity index 100% rename from tests/text_reparser/fixtures/polls.xml rename to tests/text_reparser/plugins/fixtures/polls.xml diff --git a/tests/text_reparser/fixtures/posts.xml b/tests/text_reparser/plugins/fixtures/posts.xml similarity index 100% rename from tests/text_reparser/fixtures/posts.xml rename to tests/text_reparser/plugins/fixtures/posts.xml diff --git a/tests/text_reparser/fixtures/privmsgs.xml b/tests/text_reparser/plugins/fixtures/privmsgs.xml similarity index 100% rename from tests/text_reparser/fixtures/privmsgs.xml rename to tests/text_reparser/plugins/fixtures/privmsgs.xml diff --git a/tests/text_reparser/fixtures/users.xml b/tests/text_reparser/plugins/fixtures/users.xml similarity index 100% rename from tests/text_reparser/fixtures/users.xml rename to tests/text_reparser/plugins/fixtures/users.xml diff --git a/tests/text_reparser/forum_description_test.php b/tests/text_reparser/plugins/forum_description_test.php similarity index 100% rename from tests/text_reparser/forum_description_test.php rename to tests/text_reparser/plugins/forum_description_test.php diff --git a/tests/text_reparser/forum_rules_test.php b/tests/text_reparser/plugins/forum_rules_test.php similarity index 100% rename from tests/text_reparser/forum_rules_test.php rename to tests/text_reparser/plugins/forum_rules_test.php diff --git a/tests/text_reparser/group_description_test.php b/tests/text_reparser/plugins/group_description_test.php similarity index 100% rename from tests/text_reparser/group_description_test.php rename to tests/text_reparser/plugins/group_description_test.php diff --git a/tests/text_reparser/pm_text_test.php b/tests/text_reparser/plugins/pm_text_test.php similarity index 100% rename from tests/text_reparser/pm_text_test.php rename to tests/text_reparser/plugins/pm_text_test.php diff --git a/tests/text_reparser/poll_option_test.php b/tests/text_reparser/plugins/poll_option_test.php similarity index 91% rename from tests/text_reparser/poll_option_test.php rename to tests/text_reparser/plugins/poll_option_test.php index 669d859f9a..e043858597 100644 --- a/tests/text_reparser/poll_option_test.php +++ b/tests/text_reparser/plugins/poll_option_test.php @@ -10,9 +10,9 @@ * the docs/CREDITS.txt file. * */ -require_once __DIR__ . '/../../phpBB/includes/functions.php'; -require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; -require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php'; class phpbb_textreparser_poll_option_test extends phpbb_database_test_case { diff --git a/tests/text_reparser/poll_title_test.php b/tests/text_reparser/plugins/poll_title_test.php similarity index 100% rename from tests/text_reparser/poll_title_test.php rename to tests/text_reparser/plugins/poll_title_test.php diff --git a/tests/text_reparser/post_text_test.php b/tests/text_reparser/plugins/post_text_test.php similarity index 100% rename from tests/text_reparser/post_text_test.php rename to tests/text_reparser/plugins/post_text_test.php diff --git a/tests/text_reparser/test_row_based_plugin.php b/tests/text_reparser/plugins/test_row_based_plugin.php similarity index 93% rename from tests/text_reparser/test_row_based_plugin.php rename to tests/text_reparser/plugins/test_row_based_plugin.php index 489dff280b..befcb48bda 100644 --- a/tests/text_reparser/test_row_based_plugin.php +++ b/tests/text_reparser/plugins/test_row_based_plugin.php @@ -10,9 +10,9 @@ * the docs/CREDITS.txt file. * */ -require_once __DIR__ . '/../../phpBB/includes/functions.php'; -require_once __DIR__ . '/../../phpBB/includes/functions_content.php'; -require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../../phpBB/includes/functions_content.php'; +require_once __DIR__ . '/../../test_framework/phpbb_database_test_case.php'; abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_test_case { diff --git a/tests/text_reparser/user_signature_test.php b/tests/text_reparser/plugins/user_signature_test.php similarity index 100% rename from tests/text_reparser/user_signature_test.php rename to tests/text_reparser/plugins/user_signature_test.php From 25ce302a605952e0a38605c6255c5ad212c2b4c6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 29 May 2015 23:05:11 +0200 Subject: [PATCH 26/27] [ticket/13803] Added text_reparser_collection service PHPBB3-13803 --- phpBB/config/default/container/services_text_reparser.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpBB/config/default/container/services_text_reparser.yml b/phpBB/config/default/container/services_text_reparser.yml index f25728d9c8..5d54e8dc82 100644 --- a/phpBB/config/default/container/services_text_reparser.yml +++ b/phpBB/config/default/container/services_text_reparser.yml @@ -1,4 +1,11 @@ services: + text_reparser_collection: + class: phpbb\di\service_collection + arguments: + - @service_container + tags: + - { name: service_collection, tag: text_reparser.plugin } + text_reparser.contact_admin_info: class: phpbb\textreparser\plugins\contact_admin_info arguments: From 2a7d26d3debdce7ca82f3044de45b651286c6034 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 29 May 2015 23:38:01 +0200 Subject: [PATCH 27/27] [ticket/13803] Use accurate flags for generate_text_for_edit() PHPBB3-13803 --- phpBB/phpbb/textreparser/base.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index 4afcecff6a..87a4268d0d 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -175,14 +175,14 @@ abstract class base implements reparser_interface protected function reparse_record(array $record) { $record = $this->add_missing_fields($record); + $flags = ($record['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0; + $flags |= ($record['enable_smilies']) ? OPTION_FLAG_SMILIES : 0; + $flags |= ($record['enable_magic_url']) ? OPTION_FLAG_LINKS : 0; $unparsed = array_merge( $record, - generate_text_for_edit( - $record['text'], - $record['bbcode_uid'], - OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES | OPTION_FLAG_LINKS - ) + generate_text_for_edit($record['text'], $record['bbcode_uid'], $flags) ); + // generate_text_for_edit() and decode_message() actually return the text as HTML. It has to // be decoded to plain text before it can be reparsed $text = html_entity_decode($unparsed['text'], ENT_QUOTES, 'UTF-8');