mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
[ticket/13803] WIP implementation
PHPBB3-13803
This commit is contained in:
97
phpBB/phpbb/textreparser/base.php
Normal file
97
phpBB/phpbb/textreparser/base.php
Normal file
@@ -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);
|
||||
}
|
63
phpBB/phpbb/textreparser/forumdescription.php
Normal file
63
phpBB/phpbb/textreparser/forumdescription.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
63
phpBB/phpbb/textreparser/forumrules.php
Normal file
63
phpBB/phpbb/textreparser/forumrules.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
63
phpBB/phpbb/textreparser/groupdescription.php
Normal file
63
phpBB/phpbb/textreparser/groupdescription.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
56
phpBB/phpbb/textreparser/pmtext.php
Normal file
56
phpBB/phpbb/textreparser/pmtext.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
56
phpBB/phpbb/textreparser/posttext.php
Normal file
56
phpBB/phpbb/textreparser/posttext.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
32
phpBB/phpbb/textreparser/reparser_interface.php
Normal file
32
phpBB/phpbb/textreparser/reparser_interface.php
Normal file
@@ -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);
|
||||
}
|
Reference in New Issue
Block a user