diff options
author | JoshyPHP <s9e.dev@gmail.com> | 2015-05-01 05:15:56 +0200 |
---|---|---|
committer | JoshyPHP <s9e.dev@gmail.com> | 2015-05-30 17:26:00 +0200 |
commit | de52580a78bcab47a2311f3993fd9952f963d563 (patch) | |
tree | 1d06c842d581994789109b090f54ce5f59ee2dd3 /phpBB/phpbb | |
parent | 073f3e6fdc5af190db85b6cdefd418af4312af9f (diff) | |
download | forums-de52580a78bcab47a2311f3993fd9952f963d563.tar forums-de52580a78bcab47a2311f3993fd9952f963d563.tar.gz forums-de52580a78bcab47a2311f3993fd9952f963d563.tar.bz2 forums-de52580a78bcab47a2311f3993fd9952f963d563.tar.xz forums-de52580a78bcab47a2311f3993fd9952f963d563.zip |
[ticket/13803] WIP implementation
PHPBB3-13803
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/textreparser/base.php | 97 | ||||
-rw-r--r-- | phpBB/phpbb/textreparser/forumdescription.php | 63 | ||||
-rw-r--r-- | phpBB/phpbb/textreparser/forumrules.php | 63 | ||||
-rw-r--r-- | phpBB/phpbb/textreparser/groupdescription.php | 63 | ||||
-rw-r--r-- | phpBB/phpbb/textreparser/pmtext.php | 56 | ||||
-rw-r--r-- | phpBB/phpbb/textreparser/posttext.php | 56 | ||||
-rw-r--r-- | phpBB/phpbb/textreparser/reparser_interface.php | 32 |
7 files changed, 430 insertions, 0 deletions
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 @@ +<?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 +{ + /** + * @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 @@ +<?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; + +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'], '<!-- s') !== false); + $row['enable_magic_url'] = (strpos($row['text'], '<!-- m -->') !== 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 @@ +<?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; + +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'], '<!-- s') !== false); + $row['enable_magic_url'] = (strpos($row['text'], '<!-- m -->') !== 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 @@ +<?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; + +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'], '<!-- s') !== false); + $row['enable_magic_url'] = (strpos($row['text'], '<!-- m -->') !== 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 @@ +<?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; + +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 @@ +<?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; + +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 @@ +<?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); +} |