diff options
33 files changed, 2000 insertions, 1 deletions
diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index cab82a5d9c..aec61e0272 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -19,6 +19,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 } 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..5d54e8dc82 --- /dev/null +++ b/phpBB/config/default/container/services_text_reparser.yml @@ -0,0 +1,70 @@ +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: +            - @config_text +        tags: +            - { name: text_reparser.plugin } + +    text_reparser.forum_description: +        class: phpbb\textreparser\plugins\forum_description +        arguments: +            - @dbal.conn +        tags: +            - { name: text_reparser.plugin } + +    text_reparser.forum_rules: +        class: phpbb\textreparser\plugins\forum_rules +        arguments: +            - @dbal.conn +        tags: +            - { name: text_reparser.plugin } + +    text_reparser.group_description: +        class: phpbb\textreparser\plugins\group_description +        arguments: +            - @dbal.conn +        tags: +            - { name: text_reparser.plugin } + +    text_reparser.pm_text: +        class: phpbb\textreparser\plugins\pm_text +        arguments: +            - @dbal.conn +        tags: +            - { name: text_reparser.plugin } + +    text_reparser.poll_option: +        class: phpbb\textreparser\plugins\poll_option +        arguments: +            - @dbal.conn +        tags: +            - { name: text_reparser.plugin } + +    text_reparser.poll_title: +        class: phpbb\textreparser\plugins\poll_title +        arguments: +            - @dbal.conn +        tags: +            - { name: text_reparser.plugin } + +    text_reparser.post_text: +        class: phpbb\textreparser\plugins\post_text +        arguments: +            - @dbal.conn +        tags: +            - { name: text_reparser.plugin } + +    text_reparser.user_signature: +        class: phpbb\textreparser\plugins\user_signature +        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..87a4268d0d --- /dev/null +++ b/phpBB/phpbb/textreparser/base.php @@ -0,0 +1,211 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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 +{ +	/** +	* {@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 records +	*/ +	abstract protected function get_records_by_range($min_id, $max_id); + +	/** +	* {@inheritdoc} +	*/ +	abstract protected function save_record(array $record); + +	/** +	* 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'    => $this->guess_bbcodes($record), +				'enable_smilies'   => $this->guess_smilies($record), +				'enable_magic_url' => $this->guess_magic_url($record), +			); +		} + +		// Those BBCodes are disabled based on context and user permissions and that value is never +		// 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); +		} + +		// 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; +	} + +	/** +	* 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 (strpos($record['text'], $match) !== false) +			{ +				return true; +			} +		} + +		if (substr($record['text'], 0, 2) == '<r') +		{ +			// Look for the closing tag inside of a e element, in an element of the same name, e.g. +			// <e>[/url]</e></URL> +			$match = '<e>[/' . $bbcode . ']</e></' . strtoupper($bbcode) . '>'; +			if (strpos($record['text'], $match) !== false) +			{ +				return true; +			} +		} + +		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) == '<r') +		{ +			// Look for a closing tag inside of an e element +			return (bool) preg_match('(<e>\\[/\\w+\\]</e>)', $match); +		} + +		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 <!-- m --> or for a URL tag that's not immediately followed by <s> +		return (strpos($record['text'], '<!-- m -->') !== false || preg_match('(<URL [^>]++>(?!<s>))', $record['text'])); +	} + +	/** +	* Guess whether smilies are in use in given record +	* +	* @param  array $record +	* @return bool +	*/ +	protected function guess_smilies(array $record) +	{ +		return (strpos($record['text'], '<!-- s') !== false || strpos($record['text'], '<E>') !== false); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function reparse_range($min_id, $max_id) +	{ +		foreach ($this->get_records_by_range($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) +	{ +		$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'], $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'); +		$bitfield = $flags = null; +		generate_text_for_storage( +			$text, +			$unparsed['bbcode_uid'], +			$bitfield, +			$flags, +			$unparsed['enable_bbcode'], +			$unparsed['enable_magic_url'], +			$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 +		if ($text !== $record['text']) +		{ +			$record['text'] = $text; +			$this->save_record($record); +		} +	} +} diff --git a/phpBB/phpbb/textreparser/plugins/contact_admin_info.php b/phpBB/phpbb/textreparser/plugins/contact_admin_info.php new file mode 100644 index 0000000000..8910f2256b --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/contact_admin_info.php @@ -0,0 +1,69 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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 contact_admin_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_by_range($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('contact_admin_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..7798e4b20b --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/forum_description.php @@ -0,0 +1,37 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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} +	*/ +	public function get_columns() +	{ +		return array( +			'id'         => 'forum_id', +			'text'       => 'forum_desc', +			'bbcode_uid' => 'forum_desc_uid', +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	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 new file mode 100644 index 0000000000..57c666a556 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/forum_rules.php @@ -0,0 +1,37 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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} +	*/ +	public function get_columns() +	{ +		return array( +			'id'         => 'forum_id', +			'text'       => 'forum_rules', +			'bbcode_uid' => 'forum_rules_uid', +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	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 new file mode 100644 index 0000000000..ddd0e1d1c5 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/group_description.php @@ -0,0 +1,37 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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} +	*/ +	public function get_columns() +	{ +		return array( +			'id'         => 'group_id', +			'text'       => 'group_desc', +			'bbcode_uid' => 'group_desc_uid', +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	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 new file mode 100644 index 0000000000..4d06a2878b --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/pm_text.php @@ -0,0 +1,40 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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} +	*/ +	public 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} +	*/ +	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 new file mode 100644 index 0000000000..7b803146c4 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/poll_option.php @@ -0,0 +1,74 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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\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; +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_max_id() +	{ +		$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_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 +			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 $records; +	} + +	/** +	* {@inheritdoc} +	*/ +	protected function save_record(array $record) +	{ +		$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/phpBB/phpbb/textreparser/plugins/poll_title.php b/phpBB/phpbb/textreparser/plugins/poll_title.php new file mode 100644 index 0000000000..b447004527 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/poll_title.php @@ -0,0 +1,50 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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} +	*/ +	public function get_columns() +	{ +		return array( +			'id'   => 'topic_id', +			'text' => 'poll_title', +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	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 +			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} +	*/ +	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 new file mode 100644 index 0000000000..4a07c98cea --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/post_text.php @@ -0,0 +1,40 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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} +	*/ +	public 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} +	*/ +	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 new file mode 100644 index 0000000000..f657a45d38 --- /dev/null +++ b/phpBB/phpbb/textreparser/plugins/user_signature.php @@ -0,0 +1,73 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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 +{ +	/** +	* @var array Bit numbers used for user options +	* @see \phpbb\user +	*/ +	protected $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), +			'enable_smilies'   => phpbb_optionget($this->keyoptions['sig_smilies'], $options), +			'enable_magic_url' => phpbb_optionget($this->keyoptions['sig_links'], $options), +		); + +		return parent::add_missing_fields($row); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_columns() +	{ +		return array( +			'id'           => 'user_id', +			'text'         => 'user_sig', +			'bbcode_uid'   => 'user_sig_bbcode_uid', +			'user_options' => 'user_options', +		); +	} + +	/** +	* {@inheritdoc} +	*/ +	public function get_table_name() +	{ +		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/phpBB/phpbb/textreparser/reparser_interface.php b/phpBB/phpbb/textreparser/reparser_interface.php new file mode 100644 index 0000000000..9ea1732870 --- /dev/null +++ b/phpBB/phpbb/textreparser/reparser_interface.php @@ -0,0 +1,32 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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/phpBB/phpbb/textreparser/row_based_plugin.php b/phpBB/phpbb/textreparser/row_based_plugin.php new file mode 100644 index 0000000000..d3ca334591 --- /dev/null +++ b/phpBB/phpbb/textreparser/row_based_plugin.php @@ -0,0 +1,117 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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 public function get_columns(); + +	/** +	* Return the name of the table used by this plugin +	* +	* @return string +	*/ +	abstract public 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_by_range($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); + +		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_by_range_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/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/'; diff --git a/tests/text_reparser/plugins/contact_admin_info_test.php b/tests/text_reparser/plugins/contact_admin_info_test.php new file mode 100644 index 0000000000..e577d2fd3d --- /dev/null +++ b/tests/text_reparser/plugins/contact_admin_info_test.php @@ -0,0 +1,81 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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' => '<r><EMAIL email="admin@example.org"><s>[email]</s>admin@example.org<e>[/email]</e></EMAIL></r>', +			), +			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/plugins/fixtures/contact_admin_info.xml b/tests/text_reparser/plugins/fixtures/contact_admin_info.xml new file mode 100644 index 0000000000..13cd82b1a4 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/contact_admin_info.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_config_text"> +		<column>config_name</column> +		<column>config_value</column> +		<row> +			<value>contact_admin_info</value> +			<value>[email:1a2hbwf5]admin@example.org[/email:1a2hbwf5]</value> +		</row> +		<row> +			<value>contact_admin_info_uid</value> +			<value>1a2hbwf5</value> +		</row> +		<row> +			<value>contact_admin_info_bitfield</value> +			<value>ACA=</value> +		</row> +		<row> +			<value>contact_admin_info_flags</value> +			<value>7</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/forums.xml b/tests/text_reparser/plugins/fixtures/forums.xml new file mode 100644 index 0000000000..39c172c969 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/forums.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_forums"> +		<column>forum_id</column> +		<column>forum_parents</column> +		<column>forum_desc</column> +		<column>forum_desc_uid</column> +		<column>forum_rules</column> +		<column>forum_rules_uid</column> +		<row> +			<value>1</value> +			<value></value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>2</value> +			<value></value> +			<value>[b]Not bold[/b] :) http://example.org</value> +			<value>abcd1234</value> +			<value>[b]Not bold[/b] :) http://example.org</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>3</value> +			<value></value> +			<value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> +			<value>abcd1234</value> +			<value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>4</value> +			<value></value> +			<value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> +			<value>abcd1234</value> +			<value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>5</value> +			<value></value> +			<value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> +			<value>abcd1234</value> +			<value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>6</value> +			<value></value> +			<value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> +			<value>abcd1234</value> +			<value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>7</value> +			<value></value> +			<value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> +			<value>abcd1234</value> +			<value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>8</value> +			<value></value> +			<value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> +			<value>abcd1234</value> +			<value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>9</value> +			<value></value> +			<value><![CDATA[[img]http://example.org/img.png[/img]]]></value> +			<value>abcd1234</value> +			<value><![CDATA[[img]http://example.org/img.png[/img]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>1000</value> +			<value></value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/groups.xml b/tests/text_reparser/plugins/fixtures/groups.xml new file mode 100644 index 0000000000..d3df0131a3 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/groups.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_groups"> +		<column>group_id</column> +		<column>group_desc</column> +		<column>group_desc_options</column> +		<column>group_desc_uid</column> +		<row> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>7</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>2</value> +			<value>[b]Not bold[/b] :) http://example.org</value> +			<value>0</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>3</value> +			<value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> +			<value>1</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>4</value> +			<value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> +			<value>2</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>5</value> +			<value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> +			<value>4</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>6</value> +			<value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> +			<value>7</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>7</value> +			<value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> +			<value>7</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>8</value> +			<value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> +			<value>7</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>9</value> +			<value><![CDATA[[img]http://example.org/img.png[/img]]]></value> +			<value>7</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>1000</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>7</value> +			<value>abcd1234</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/poll_options.xml b/tests/text_reparser/plugins/fixtures/poll_options.xml new file mode 100644 index 0000000000..c2fad9f764 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/poll_options.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_poll_options"> +		<column>poll_option_id</column> +		<column>topic_id</column> +		<column>poll_option_text</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>This row should be [b:abcd1234]ignored[/b:abcd1234]</value> +		</row> +		<row> +			<value>1</value> +			<value>2</value> +			<value>[b:abcd1234]Bold[/b:abcd1234]</value> +		</row> +		<row> +			<value>2</value> +			<value>2</value> +			<value><![CDATA[<!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) -->]]></value> +		</row> +		<row> +			<value>3</value> +			<value>2</value> +			<value><![CDATA[<!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> +		</row> +		<row> +			<value>1</value> +			<value>123</value> +			<value>This row should be [b]ignored[/b]</value> +		</row> +		<row> +			<value>2</value> +			<value>123</value> +			<value>This row should be [b:abcd1234]ignored[/b:abcd1234]</value> +		</row> +	</table> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>post_text</column> +		<column>bbcode_uid</column> +		<row> +			<value>1</value> +			<value></value> +			<value>abcd1234</value> +		</row> +	</table> +	<table name="phpbb_topics"> +		<column>topic_id</column> +		<column>topic_first_post_id</column> +		<column>poll_title</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +		</row> +		<row> +			<value>123</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/polls.xml b/tests/text_reparser/plugins/fixtures/polls.xml new file mode 100644 index 0000000000..9baf813c97 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/polls.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>post_text</column> +		<column>bbcode_uid</column> +		<row> +			<value>1</value> +			<value></value> +			<value>abcd1234</value> +		</row> +	</table> +	<table name="phpbb_topics"> +		<column>topic_id</column> +		<column>topic_first_post_id</column> +		<column>poll_title</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +		</row> +		<row> +			<value>2</value> +			<value>1</value> +			<value>[b]Not bold[/b] :) http://example.org</value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +			<value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> +		</row> +		<row> +			<value>4</value> +			<value>1</value> +			<value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> +		</row> +		<row> +			<value>5</value> +			<value>1</value> +			<value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> +		</row> +		<row> +			<value>6</value> +			<value>1</value> +			<value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> +		</row> +		<row> +			<value>7</value> +			<value>1</value> +			<value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> +		</row> +		<row> +			<value>8</value> +			<value>1</value> +			<value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> +		</row> +		<row> +			<value>9</value> +			<value>1</value> +			<value><![CDATA[[img]http://example.org/img.png[/img]]]></value> +		</row> +		<row> +			<value>1000</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/posts.xml b/tests/text_reparser/plugins/fixtures/posts.xml new file mode 100644 index 0000000000..ec31747ed9 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/posts.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_posts"> +		<column>post_id</column> +		<column>enable_bbcode</column> +		<column>enable_smilies</column> +		<column>enable_magic_url</column> +		<column>post_text</column> +		<column>bbcode_uid</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>0</value> +			<value>[b]Not bold[/b] :) http://example.org</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +			<value>0</value> +			<value>0</value> +			<value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>4</value> +			<value>0</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>5</value> +			<value>0</value> +			<value>0</value> +			<value>1</value> +			<value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>6</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>7</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>8</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>9</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[img]http://example.org/img.png[/img]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>1000</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/privmsgs.xml b/tests/text_reparser/plugins/fixtures/privmsgs.xml new file mode 100644 index 0000000000..4049b9890a --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/privmsgs.xml @@ -0,0 +1,113 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_privmsgs"> +		<column>msg_id</column> +		<column>enable_bbcode</column> +		<column>enable_smilies</column> +		<column>enable_magic_url</column> +		<column>message_text</column> +		<column>bbcode_uid</column> +		<column>to_address</column> +		<column>bcc_address</column> +		<row> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>2</value> +			<value>0</value> +			<value>0</value> +			<value>0</value> +			<value>[b]Not bold[/b] :) http://example.org</value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>3</value> +			<value>1</value> +			<value>0</value> +			<value>0</value> +			<value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>4</value> +			<value>0</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>5</value> +			<value>0</value> +			<value>0</value> +			<value>1</value> +			<value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>6</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>7</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>8</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>9</value> +			<value>1</value> +			<value>1</value> +			<value>0</value> +			<value><![CDATA[[img]http://example.org/img.png[/img]]]></value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +		<row> +			<value>1000</value> +			<value>1</value> +			<value>1</value> +			<value>1</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +			<value></value> +			<value></value> +		</row> +	</table> +</dataset> diff --git a/tests/text_reparser/plugins/fixtures/users.xml b/tests/text_reparser/plugins/fixtures/users.xml new file mode 100644 index 0000000000..60c623b6b1 --- /dev/null +++ b/tests/text_reparser/plugins/fixtures/users.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> +	<table name="phpbb_users"> +		<column>user_id</column> +		<column>user_permissions</column> +		<column>username_clean</column> +		<column>user_options</column> +		<column>user_sig</column> +		<column>user_sig_bbcode_uid</column> +		<row> +			<value>1</value> +			<value></value> +			<value>user1</value> +			<value>230271</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>2</value> +			<value></value> +			<value>user2</value> +			<value>895</value> +			<value>[b]Not bold[/b] :) http://example.org</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>3</value> +			<value></value> +			<value>user3</value> +			<value>33663</value> +			<value>[b:abcd1234]Bold[/b:abcd1234] :) http://example.org</value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>4</value> +			<value></value> +			<value>user4</value> +			<value>66431</value> +			<value><![CDATA[[b]Not bold[/b] <!-- s:) --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!-- s:) --> http://example.org]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>5</value> +			<value></value> +			<value>user5</value> +			<value>131967</value> +			<value><![CDATA[[b]Not bold[/b] :) <!-- m --><a class="postlink" href="http://example.org">http://example.org</a><!-- m -->]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>6</value> +			<value></value> +			<value>user6</value> +			<value>99199</value> +			<value><![CDATA[[flash=123,345:abcd1234]http://example.org/flash.swf[/flash:abcd1234]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>7</value> +			<value></value> +			<value>user7</value> +			<value>99199</value> +			<value><![CDATA[[flash=123,345]http://example.org/flash.swf[/flash]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>8</value> +			<value></value> +			<value>user8</value> +			<value>99199</value> +			<value><![CDATA[[img:abcd1234]http://example.org/img.png[/img:abcd1234]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>9</value> +			<value></value> +			<value>user9</value> +			<value>99199</value> +			<value><![CDATA[[img]http://example.org/img.png[/img]]]></value> +			<value>abcd1234</value> +		</row> +		<row> +			<value>1000</value> +			<value></value> +			<value>user1000</value> +			<value>230271</value> +			<value>This row should be [b]ignored[/b]</value> +			<value>abcd1234</value> +		</row> +	</table> +</dataset> diff --git a/tests/text_reparser/plugins/forum_description_test.php b/tests/text_reparser/plugins/forum_description_test.php new file mode 100644 index 0000000000..3b739353cd --- /dev/null +++ b/tests/text_reparser/plugins/forum_description_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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'); +	} + +	protected function get_reparser() +	{ +		return new \phpbb\textreparser\plugins\forum_description($this->db); +	} +} diff --git a/tests/text_reparser/plugins/forum_rules_test.php b/tests/text_reparser/plugins/forum_rules_test.php new file mode 100644 index 0000000000..4c267c9014 --- /dev/null +++ b/tests/text_reparser/plugins/forum_rules_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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'); +	} + +	protected function get_reparser() +	{ +		return new \phpbb\textreparser\plugins\forum_rules($this->db); +	} +} diff --git a/tests/text_reparser/plugins/group_description_test.php b/tests/text_reparser/plugins/group_description_test.php new file mode 100644 index 0000000000..51035903e1 --- /dev/null +++ b/tests/text_reparser/plugins/group_description_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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); +	} +} diff --git a/tests/text_reparser/plugins/pm_text_test.php b/tests/text_reparser/plugins/pm_text_test.php new file mode 100644 index 0000000000..3896a57e98 --- /dev/null +++ b/tests/text_reparser/plugins/pm_text_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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'); +	} + +	protected function get_reparser() +	{ +		return new \phpbb\textreparser\plugins\pm_text($this->db); +	} +} diff --git a/tests/text_reparser/plugins/poll_option_test.php b/tests/text_reparser/plugins/poll_option_test.php new file mode 100644 index 0000000000..e043858597 --- /dev/null +++ b/tests/text_reparser/plugins/poll_option_test.php @@ -0,0 +1,100 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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_poll_option_test extends phpbb_database_test_case +{ +	protected $db; + +	public function getDataSet() +	{ +		return $this->createXMLDataSet(__DIR__ . '/fixtures/poll_options.xml'); +	} + +	protected function get_reparser() +	{ +		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' => '<r><B><s>[b]</s>Bold<e>[/b]</e></B></r>', +			), +			array( +				'topic_id'         => 2, +				'poll_option_id'   => 2, +				'poll_option_text' => '<r><E>:)</E></r>', +			), +			array( +				'topic_id'         => 2, +				'poll_option_id'   => 3, +				'poll_option_text' => '<r><URL url="http://example.org">http://example.org</URL></r>', +			), +			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); +	} +} diff --git a/tests/text_reparser/plugins/poll_title_test.php b/tests/text_reparser/plugins/poll_title_test.php new file mode 100644 index 0000000000..76ca2ee228 --- /dev/null +++ b/tests/text_reparser/plugins/poll_title_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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); +	} +} diff --git a/tests/text_reparser/plugins/post_text_test.php b/tests/text_reparser/plugins/post_text_test.php new file mode 100644 index 0000000000..0f934a06ee --- /dev/null +++ b/tests/text_reparser/plugins/post_text_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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_post_text_test extends phpbb_textreparser_test_row_based_plugin +{ +	public function getDataSet() +	{ +		return $this->createXMLDataSet(__DIR__ . '/fixtures/posts.xml'); +	} + +	protected function get_reparser() +	{ +		return new \phpbb\textreparser\plugins\post_text($this->db); +	} +} diff --git a/tests/text_reparser/plugins/test_row_based_plugin.php b/tests/text_reparser/plugins/test_row_based_plugin.php new file mode 100644 index 0000000000..befcb48bda --- /dev/null +++ b/tests/text_reparser/plugins/test_row_based_plugin.php @@ -0,0 +1,129 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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; + +	abstract protected function get_reparser(); + +	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(1000, $reparser->get_max_id()); +	} + +	/** +	* @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) . ' +			ORDER BY id'; +		$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' => '<t>[b]Not bold[/b] :) http://example.org</t>', +					), +					array( +						'id'   => '3', +						'text' => '<r><B><s>[b]</s>Bold<e>[/b]</e></B> :) http://example.org</r>', +					), +					array( +						'id'   => '4', +						'text' => '<r>[b]Not bold[/b] <E>:)</E> http://example.org</r>', +					), +					array( +						'id'   => '5', +						'text' => '<r>[b]Not bold[/b] :) <URL url="http://example.org">http://example.org</URL></r>', +					), +					array( +						'id'   => '1000', +						'text' => 'This row should be [b]ignored[/b]', +					), +				) +			), +			array( +				6, +				7, +				array( +					array( +						'id'   => '6', +						'text' => '<r><FLASH height="345" url="http://example.org/flash.swf" width="123"><s>[flash=123,345]</s>http://example.org/flash.swf<e>[/flash]</e></FLASH></r>', +					), +					array( +						'id'   => '7', +						'text' => '<t>[flash=123,345]http://example.org/flash.swf[/flash]</t>', +					), +				) +			), +			array( +				8, +				9, +				array( +					array( +						'id'   => '8', +						'text' => '<r><IMG src="http://example.org/img.png"><s>[img]</s>http://example.org/img.png<e>[/img]</e></IMG></r>', +					), +					array( +						'id'   => '9', +						'text' => '<t>[img]http://example.org/img.png[/img]</t>', +					), +				) +			), +		); +	} +} diff --git a/tests/text_reparser/plugins/user_signature_test.php b/tests/text_reparser/plugins/user_signature_test.php new file mode 100644 index 0000000000..ab830a303d --- /dev/null +++ b/tests/text_reparser/plugins/user_signature_test.php @@ -0,0 +1,26 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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); +	} +}  | 
