diff options
-rw-r--r-- | phpBB/phpbb/textreparser/base.php | 50 | ||||
-rw-r--r-- | tests/text_reparser/fixtures/posts.xml | 32 | ||||
-rw-r--r-- | tests/text_reparser/fixtures/privmsgs.xml | 40 | ||||
-rw-r--r-- | tests/text_reparser/test_row_based_plugin.php | 40 |
4 files changed, 149 insertions, 13 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'], diff --git a/tests/text_reparser/fixtures/posts.xml b/tests/text_reparser/fixtures/posts.xml index 5e725825d8..ec31747ed9 100644 --- a/tests/text_reparser/fixtures/posts.xml +++ b/tests/text_reparser/fixtures/posts.xml @@ -48,6 +48,38 @@ <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> diff --git a/tests/text_reparser/fixtures/privmsgs.xml b/tests/text_reparser/fixtures/privmsgs.xml index 9ca49a2af8..4049b9890a 100644 --- a/tests/text_reparser/fixtures/privmsgs.xml +++ b/tests/text_reparser/fixtures/privmsgs.xml @@ -60,6 +60,46 @@ <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> diff --git a/tests/text_reparser/test_row_based_plugin.php b/tests/text_reparser/test_row_based_plugin.php index 7dd90f21d0..405341e2fc 100644 --- a/tests/text_reparser/test_row_based_plugin.php +++ b/tests/text_reparser/test_row_based_plugin.php @@ -62,31 +62,59 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t 5, array( array( - 'id' => 1, + 'id' => '1', 'text' => 'This row should be [b]ignored[/b]', ), array( - 'id' => 2, + 'id' => '2', 'text' => '<t>[b]Not bold[/b] :) http://example.org</t>', ), array( - 'id' => 3, + 'id' => '3', 'text' => '<r><B><s>[b]</s>Bold<e>[/b]</e></B> :) http://example.org</r>', ), array( - 'id' => 4, + 'id' => '4', 'text' => '<r>[b]Not bold[/b] <E>:)</E> http://example.org</r>', ), array( - 'id' => 5, + 'id' => '5', 'text' => '<r>[b]Not bold[/b] :) <URL url="http://example.org">http://example.org</URL></r>', ), array( - 'id' => 1000, + '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>', + ), + ) + ), ); } } |