66
77 class BBCodePlusPlugin extends MantisFormattingPlugin {
88 # placeholders for MantisCoreFormatting values.
9- private $ t_MantisCoreFormatting = OFF ;
9+ private $ t_MantisCoreFormatting = OFF ;
1010 private $ t_MantisCoreFormatting_process_text = OFF ;
1111 private $ t_MantisCoreFormatting_process_urls = OFF ;
1212 private $ t_MantisCoreFormatting_process_markdown = OFF ;
@@ -305,7 +305,7 @@ function string_process_bbcode( $p_string, $p_multiline = TRUE ) {
305305 }
306306 # convert all remaining major html items to bbcode for uniform processing.
307307 $ p_string = $ this ->t_HTML ->except ('linebreak ' )->parse ($ p_string );
308- #escape all html code inside <code> tags.
308+ # escape all html code inside <code> tags.
309309 $ p_string = $ this ->string_escape_code ( $ p_string );
310310 # parse the BBCode.
311311 $ p_string = $ this ->t_bbCode ->parse ($ p_string );
@@ -316,8 +316,6 @@ function string_process_bbcode( $p_string, $p_multiline = TRUE ) {
316316 $ p_string = string_nl2br ($ p_string );
317317 }
318318
319- # escape all html code inside <code> tags.
320- #$p_string = $this->string_escape_code( $p_string );
321319 # remove extra breaks added by use of string_nl2br.
322320 $ p_string = preg_replace ( '/(<ul.*?>)<br \/>/is ' , '$1 ' , $ p_string );
323321 $ p_string = preg_replace ( '/(<ol.*?>)<br \/>/is ' , '$1 ' , $ p_string );
@@ -350,10 +348,14 @@ function string_process_bbcode( $p_string, $p_multiline = TRUE ) {
350348 * @return string $p_string
351349 */
352350 function string_escape_code ( $ p_string ) {
353- $ p_string = preg_replace_callback ('/\[code(.*?)\](.*?)\[\/code\]/s ' , function ($ match ) {
351+ # store value in var (due to issues with $this inside callbacks.)
352+ $ mantisCoreFormatting = $ this ->t_MantisCoreFormatting ;
353+ $ p_string = preg_replace_callback ('/\[code(.*?)\](.*?)\[\/code\]/s ' , function ($ match )
354+ # use is only supported on PHP 5.3+.
355+ use ( $ mantisCoreFormatting ) {
354356 # account for <br /> in code block (when using html syntax).
355357 $ code = $ match [2 ];
356- if (ON == $ this -> t_MantisCoreFormatting ) {
358+ if ( ON == $ mantisCoreFormatting ) {
357359 # preview somehow uses \n only.
358360 $ code = preg_replace ( '/<br \/>\n/is ' , "\n" , $ code );
359361 # everywhere else uses \r\n.
0 commit comments