diff --git a/include/bbcode.php b/include/bbcode.php
index 862570348..a0a53a310 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -219,10 +219,15 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text);
// Hide all [noparse] contained bbtags by spacefying them
-
- $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text);
- $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text);
- $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text);
+ if (strpos($Text,'[noparse]') !== false) {
+ $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text);
+ }
+ if (strpos($Text,'[nobb]') !== false) {
+ $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text);
+ }
+ if (strpos($Text,'[pre]') !== false) {
+ $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text);
+ }
@@ -265,61 +270,75 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]';
-
- $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text);
-
-
- $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text);
-
- if($tryoembed)
- $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text);
-
- $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text);
- $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text);
-
-
- $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text);
- $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text);
-
+ if (strpos($Text,'http') !== false) {
+ $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/$urlchars+)/ism", '$1$2', $Text);
+ }
+ if (strpos($Text,'[/share]') !== false) {
+ $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text);
+ }
+ if($tryoembed) {
+ if (strpos($Text,'[/url]') !== false) {
+ $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text);
+ }
+ }
+ if (strpos($Text,'[/url]') !== false) {
+ $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text);
+ $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text);
+ }
+ if (strpos($Text,'[/zrl]') !== false) {
+ $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text);
+ $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text);
+ }
// Perform MAIL Search
- $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text);
- $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text);
-
+ if (strpos($Text,'[/mail]') !== false) {
+ $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text);
+ $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text);
+ }
// Check for bold text
- $Text = preg_replace("(\[b\](.*?)\[\/b\])ism",'$1',$Text);
-
+ if (strpos($Text,'[b]') !== false) {
+ $Text = preg_replace("(\[b\](.*?)\[\/b\])ism",'$1',$Text);
+ }
// Check for Italics text
- $Text = preg_replace("(\[i\](.*?)\[\/i\])ism",'$1',$Text);
-
+ if (strpos($Text,'[i]') !== false) {
+ $Text = preg_replace("(\[i\](.*?)\[\/i\])ism",'$1',$Text);
+ }
// Check for Underline text
- $Text = preg_replace("(\[u\](.*?)\[\/u\])ism",'$1',$Text);
-
+ if (strpos($Text,'[u]') !== false) {
+ $Text = preg_replace("(\[u\](.*?)\[\/u\])ism",'$1',$Text);
+ }
// Check for strike-through text
- $Text = preg_replace("(\[s\](.*?)\[\/s\])ism",'$1',$Text);
-
+ if (strpos($Text,'[s]') !== false) {
+ $Text = preg_replace("(\[s\](.*?)\[\/s\])ism",'$1',$Text);
+ }
// Check for over-line text
- $Text = preg_replace("(\[o\](.*?)\[\/o\])ism",'$1',$Text);
-
+ if (strpos($Text,'[o]') !== false) {
+ $Text = preg_replace("(\[o\](.*?)\[\/o\])ism",'$1',$Text);
+ }
// Check for colored text
- $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])ism","$2",$Text);
-
+ if (strpos($Text,'[/color]') !== false) {
+ $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])ism","$2",$Text);
+ }
// Check for sized text
// [size=50] --> font-size: 50px (with the unit).
- $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","$2",$Text);
- $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","$2",$Text);
-
+ if (strpos($Text,'[/size]') !== false) {
+ $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","$2",$Text);
+ $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","$2",$Text);
+ }
// Check for centered text
+ if (strpos($Text,'[/center]') !== false) {
$Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
$1
",$Text);
-
+ }
// Check for list text
$Text = str_replace("[*]", "", $Text);
// Check for style sheet commands
- $Text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism","$2",$Text);
-
+ if (strpos($Text,'[/style]') !== false) {
+ $Text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism","$2",$Text);
+ }
// Check for CSS classes
- $Text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism","$2",$Text);
-
+ if (strpos($Text,'[/class]') !== false) {
+ $Text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism","$2",$Text);
+ }
// handle nested lists
$endlessloop = 0;
@@ -338,15 +357,20 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '' ,$Text);
$Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '$1' ,$Text);
}
-
- $Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1 | ' ,$Text);
- $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1 | ' ,$Text);
- $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1
' ,$Text);
- $Text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '' ,$Text);
-
- $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '' ,$Text);
- $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '' ,$Text);
-
+ if (strpos($Text,'[th]') !== false) {
+ $Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1 | ' ,$Text);
+ }
+ if (strpos($Text,'[td]') !== false) {
+ $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1 | ' ,$Text);
+ }
+ if (strpos($Text,'[tr]') !== false) {
+ $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1
' ,$Text);
+ }
+ if (strpos($Text,'[table]') !== false) {
+ $Text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '' ,$Text);
+ $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '' ,$Text);
+ $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '' ,$Text);
+ }
$Text = str_replace('[hr]','
', $Text);
// This is actually executed in prepare_body()
@@ -354,14 +378,16 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = str_replace('[nosmile]','',$Text);
// Check for font change text
- $Text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm","$2",$Text);
-
+ if (strpos($Text,'[/font]') !== false) {
+ $Text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm","$2",$Text);
+ }
// Declare the format for [code] layout
$CodeLayout = '$1
';
// Check for [code] text
- $Text = preg_replace("/\[code\](.*?)\[\/code\]/ism","$CodeLayout", $Text);
-
+ if (strpos($Text,'[code]') !== false) {
+ $Text = preg_replace("/\[code\](.*?)\[\/code\]/ism","$CodeLayout", $Text);
+ }
// Declare the format for [spoiler] layout
$SpoilerLayout = '$1
';
@@ -404,72 +430,93 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
// [img=widthxheight]image source[/img]
//$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '
', $Text);
- $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '
', $Text);
- $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '
', $Text);
-
+ if (strpos($Text,'[/img]') !== false) {
+ $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '
', $Text);
+ }
+ if (strpos($Text,'[/zmg]') !== false) {
+ $Text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '
', $Text);
+ }
// Images
// [img]pathtoimage[/img]
- $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '
', $Text);
- $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '
', $Text);
-
-
-
- $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
 . '/images/lock_icon.gif)
', $Text);
- $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
 . '/images/lock_icon.gif)
', $Text);
+ if (strpos($Text,'[/img]') !== false) {
+ $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '
', $Text);
+ }
+ if (strpos($Text,'[/zmg]') !== false) {
+ $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '
', $Text);
+ }
+ if (strpos($Text,'[crypt]') !== false) {
+ $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
 . '/images/lock_icon.gif)
', $Text);
+ $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
 . '/images/lock_icon.gif)
', $Text);
+ }
// Try to Oembed
if ($tryoembed) {
- $Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '', $Text);
- $Text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", '', $Text);
-
- $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text);
- $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text);
+ if (strpos($Text,'[/video]') !== false) {
+ $Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '', $Text);
+ }
+ if (strpos($Text,'[/audio]') !== false) {
+ $Text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", '', $Text);
+ }
+ if (strpos($Text,'[/video]') !== false) {
+ $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text);
+ }
+ if (strpos($Text,'[/audio]') !== false) {
+ $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text);
+ }
}
// if video couldn't be embedded, link to it instead.
-
- $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text);
- $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text);
+ if (strpos($Text,'[/video]') !== false) {
+ $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text);
+ }
+ if (strpos($Text,'[/audio]') !== false) {
+ $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text);
+ }
// html5 video and audio
- if ($tryoembed)
- $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '', $Text);
- else
- $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text);
-
+ if ($tryoembed){
+ if (strpos($Text,'[/iframe]') !== false) {
+ $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '', $Text);
+ }
+ }
+ else {
+ if (strpos($Text,'[/iframe]') !== false) {
+ $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text);
+ }
+ }
// Youtube extensions
- if ($tryoembed) {
- $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
- $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
- $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text);
+ if (strpos($Text,'[youtube]') !== false) {
+ if ($tryoembed) {
+ $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
+ $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
+ $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text);
+ }
+ $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
+ $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
+ $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
+
+ if ($tryoembed)
+ $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text);
+ else
+ $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text);
}
+ if (strpos($Text,'[vimeo]') !== false) {
+ if ($tryoembed) {
+ $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
+ $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
+ }
- $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
- $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
- $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
+ $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
+ $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
- if ($tryoembed)
- $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text);
- else
- $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text);
-
-
- if ($tryoembed) {
- $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
- $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
+ if ($tryoembed)
+ $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text);
+ else
+ $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $Text);
}
-
- $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
- $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
-
- if ($tryoembed)
- $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text);
- else
- $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $Text);
-
// $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text);
@@ -497,11 +544,15 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
// Unhide all [noparse] contained bbtags unspacefying them
// and triming the [noparse] tag.
-
- $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_unspacefy_and_trim',$Text);
- $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_unspacefy_and_trim',$Text);
- $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim',$Text);
-
+ if (strpos($Text,'[noparse]') !== false) {
+ $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_unspacefy_and_trim',$Text);
+ }
+ if (strpos($Text,'[nobb]') !== false) {
+ $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_unspacefy_and_trim',$Text);
+ }
+ if (strpos($Text,'[pre]') !== false) {
+ $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim',$Text);
+ }
$Text = preg_replace('/\[\&\;([#a-z0-9]+)\;\]/','&$1;',$Text);