Index: branches/5.2.x/units/helpers/post_helper.php =================================================================== diff -u -N -r16515 -r16685 --- branches/5.2.x/units/helpers/post_helper.php (.../post_helper.php) (revision 16515) +++ branches/5.2.x/units/helpers/post_helper.php (.../post_helper.php) (revision 16685) @@ -1,6 +1,6 @@ checkBBCodeAttribs("'.$tag_name.'",\'$1\',\'$2\',$tag_params);', $text); + $that = $this; + $text = preg_replace_callback( + '/\[' . $tag_name . '(.*)\](.*)\[\/' . $tag_name . ' *\]/Uis', + function ($matches) use ($that, $tag_name, $tag_params) { + return $that->checkBBCodeAttribs($tag_name, $matches[1], $matches[2], $tag_params); + }, + $text + ); } // additional processing for [url], [*], [img] bbcode @@ -290,7 +296,15 @@ $text); // bbcode [code]xxx[/code] processing - $text = preg_replace('/\[code\](.*)\[\/code\]/Uise', "\$this->replaceCodeBBCode('$1', '".$bbcode_element."')", $text); + $that = $this; + $text = preg_replace_callback( + '/\[code\](.*)\[\/code\]/Uis', + function ($matches) use ($that, $bbcode_element) { + return $that->replaceCodeBBCode($matches, $bbcode_element); + }, + $text + ); + return $text; } @@ -392,14 +406,15 @@ } /** - * Replaces [code]php code[/code] bbcode in post + * Callback function for preg_replace string processing, replaces [code]php code[/code] bbcode in post * - * @param string $input_string code line to highlight - * @param string $bbcode_element block name used for bbcode descoration + * @param array $matches Intermediate result of preg_replace operation. + * @param string $bbcode_element BBCode element replacement. + * * @return string * @see parsePostBody about why we unescape here. */ - function replaceCodeBBCode($input_string, $bbcode_element) + public function replaceCodeBBCode(array $matches, $bbcode_element) { static $bbcode_mask = null; @@ -408,7 +423,7 @@ $bbcode_mask = trim($this->Application->ParseBlock($block_params)); } - $input_string = trim(str_replace('\"', '"', kUtil::unescape($input_string, kUtil::ESCAPE_HTML))); + $input_string = trim(str_replace('\"', '"', kUtil::unescape($matches[1], kUtil::ESCAPE_HTML))); $input_string = $this->highlightCode($input_string); $input_string = preg_replace("/\r
/s", "\r", $input_string); // undo nl2br added in highlighting $input_string = str_replace('#BB_CODE#', $input_string, $bbcode_mask);