diff options
author | JoshyPHP <s9e.dev@gmail.com> | 2015-05-02 08:51:56 +0200 |
---|---|---|
committer | JoshyPHP <s9e.dev@gmail.com> | 2015-05-30 17:26:00 +0200 |
commit | 70cd911281056ecb4eefc23e678126e1747debc8 (patch) | |
tree | 33bcf76ca6f8653c94edcd0d0f7f567b372c79f9 /phpBB/phpbb/textreparser | |
parent | 9bf0f794b5876b10491c91548f1a92bc0dff7400 (diff) | |
download | forums-70cd911281056ecb4eefc23e678126e1747debc8.tar forums-70cd911281056ecb4eefc23e678126e1747debc8.tar.gz forums-70cd911281056ecb4eefc23e678126e1747debc8.tar.bz2 forums-70cd911281056ecb4eefc23e678126e1747debc8.tar.xz forums-70cd911281056ecb4eefc23e678126e1747debc8.zip |
[ticket/13803] Added tests
PHPBB3-13803
Diffstat (limited to 'phpBB/phpbb/textreparser')
-rw-r--r-- | phpBB/phpbb/textreparser/base.php | 50 |
1 files changed, 43 insertions, 7 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. // <e>[/url]</e></URL> - $match = '<e>[/' . $bbcode . ']</e></' . $bbcode . '>'; - if (stripos($record['text'], $match) !== false) + $match = '<e>[/' . $bbcode . ']</e></' . strtoupper($bbcode) . '>'; + if (strpos($record['text'], $match) !== false) { return true; } @@ -95,6 +102,33 @@ abstract class base implements reparser_interface } /** + * 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 @@ -103,7 +137,7 @@ abstract class base implements reparser_interface 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']))); + return (strpos($record['text'], '<!-- m -->') !== false || preg_match('(<URL [^>]++>(?!<s>))', $record['text'])); } /** @@ -114,7 +148,7 @@ abstract class base implements reparser_interface */ protected function guess_smilies(array $record) { - return (strpos($row['text'], '<!-- s') !== false || strpos($row['text'], '<E>') !== false); + return (strpos($record['text'], '<!-- s') !== false || strpos($record['text'], '<E>') !== false); } /** @@ -143,8 +177,10 @@ abstract class base implements reparser_interface OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES | OPTION_FLAG_LINKS ) ); + // 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'); $bitfield = $flags = null; - $parsed_text = $unparsed['text']; generate_text_for_storage( $parsed_text, $unparsed['bbcode_uid'], |