Skip to content

Commit b95df5b

Browse files
authored
Merge pull request #68 from bkraul/develop
Minor code corrections. Bump to 2.1.5
2 parents b089baf + 32cac23 commit b95df5b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

BBCodePlus/BBCodePlus.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ If you would like to contribute to BBCode plus, please [read this guide first](h
2626

2727
## Change Log
2828

29+
### 2.1.5
30+
31+
- Corrected use of `$this` inside code replace callback (causes issues with older versions of PHP).
32+
2933
### 2.1.4
3034

3135
- Corrected issues with bug links and mentions.

0 commit comments

Comments
 (0)