diff options
-rw-r--r-- | phpBB/phpbb/textreparser/base.php | 56 | ||||
-rw-r--r-- | 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 @@ -30,6 +30,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) == '<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></' . $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 <!-- m --> or for a URL tag that's not immediately followed by <s> + return (strpos($record['text'], '<!-- m -->') !== false || preg_match('(<URL [^>]++>(?!<s>))', 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'], '<!-- s') !== false || strpos($row['text'], '<E>') !== false); + } + + /** * {@inheritdoc} */ 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 2be0b68411..80525a404e 100644 --- a/phpBB/phpbb/textreparser/row_based_plugin.php +++ b/phpBB/phpbb/textreparser/row_based_plugin.php @@ -59,11 +59,20 @@ abstract class row_based_plugin extends base { $row += array( 'enable_bbcode' => !empty($row['bbcode_uid']), - 'enable_smilies' => (strpos($row['text'], '<!-- s') !== false), - 'enable_magic_url' => (strpos($row['text'], '<!-- m -->') !== 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; } |