From 5107ee52d3e9c743e977b2e651c8846dfa4ada38 Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Sun, 12 Feb 2012 06:13:49 -0800 Subject: [PATCH 1/9] Regexp fix for [LIST=i], [list=i], [LIST=I] and [LIST=i] bbcodes --- include/bbcode.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 6b733c8f43..7825914b55 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -124,10 +124,14 @@ function bbcode($Text,$preserve_nl = false) { $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '' ,$Text); $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '' ,$Text); $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '' ,$Text); - $Text = preg_replace("/\[list=i\](.*?)\[\/list\]/sm",'' ,$Text); - $Text = preg_replace("/\[list=I\](.*?)\[\/list\]/sm", '' ,$Text); - $Text = preg_replace("/\[list=a\](.*?)\[\/list\]/sm", '' ,$Text); - $Text = preg_replace("/\[list=A\](.*?)\[\/list\]/sm", '' ,$Text); + $Text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'' ,$Text); + $Text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '' ,$Text); + $Text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '' ,$Text); + $Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '' ,$Text); $Text = preg_replace("/\[li\](.*?)\[\/li\]/sm", '
  • $1
  • ' ,$Text); $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1' ,$Text); From 5479142efca1fff08f2d60dc5a723b5d0842548b Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Sun, 12 Feb 2012 06:21:01 -0800 Subject: [PATCH 2/9] Added support for [ul] standard unordered list bbcode. --- include/bbcode.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/bbcode.php b/include/bbcode.php index 7825914b55..5d9665be56 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -115,13 +115,15 @@ function bbcode($Text,$preserve_nl = false) { // Check for list text - if(stristr($Text,'[/list]')) + if(stristr($Text,'[/(list|ul|ol)]')) $Text = str_replace("[*]", "
  • ", $Text); if(stristr($Text,'[/list]')) $Text = str_replace("[*]", "
  • ", $Text); $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '
      $1
    ' ,$Text); + $Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '
      $1
    ' +,$Text); $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '
      $1
    ' ,$Text); $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '
      $1
    ' ,$Text); $Text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'
      Date: Sun, 12 Feb 2012 12:00:23 -0800 Subject: [PATCH 3/9] Added support for [ol] standard ordered list bbcode. --- include/bbcode.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/bbcode.php b/include/bbcode.php index 5d9665be56..7133a1a34d 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -126,6 +126,8 @@ function bbcode($Text,$preserve_nl = false) { ,$Text); $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '
        $1
      ' ,$Text); $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '
        $1
      ' ,$Text); + $Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '
        $1
      ' +,$Text); $Text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'
        $2
      ' ,$Text); $Text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '
        Date: Sun, 12 Feb 2012 14:35:29 -0800 Subject: [PATCH 4/9] Added support to [noparse], [nobb] and [pre] as bbcode escape tags. --- include/bbcode.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/bbcode.php b/include/bbcode.php index 7133a1a34d..3534a7315f 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -24,13 +24,40 @@ function tryoembed($match){ } +// [noparse][i]italic[/i][/noparse] turns into +// [noparse][ i ]italic[ /i ][/noparse], +// to hide them from parser. +function bb_spacefy($st) { + $whole_match = $st[0]; + $captured = $st[1]; + $spacefied = preg_replace("/\[(.*?)\]/", "[ $1 ]", $captured); + $new_str = str_replace($captured, $spacefied, $whole_match); + return $new_str; +} + +// The previously spacefied [noparse][ i ]italic[ /i ][/noparse], +// now turns back and the [noparse] tags are trimed +// returning [i]italic[/i] + +function bb_unspacefy_and_trim($st) { + $whole_match = $st[0]; + $captured = $st[1]; + $unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured); + return $unspacefied; +} // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendica - Mike Macgirvin function bbcode($Text,$preserve_nl = false) { + // Hide all [noparse] contained bbtags 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); + // Extract a single private image which uses data url's since preg has issues with // large data sizes. Stash it away while we do bbcode conversion, and then put it back @@ -227,6 +254,13 @@ upper-alpha;">$2
      ' ,$Text); $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text); } + // 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); + // fix any escaped ampersands that may have been converted into links $Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text); if(strlen($saved_image)) From 74b529bda2fb024815299db094ac8313a9d9d809 Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Sun, 12 Feb 2012 14:59:07 -0800 Subject: [PATCH 5/9] BBCode [size=50] --> font-size: 50px (with the unit px). This [size=number] without unit is kind of a standard. It was being rendered like "font-size: 50" and that's not valid CSS style. --- include/bbcode.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/bbcode.php b/include/bbcode.php index 3534a7315f..fa5b7e0806 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -138,6 +138,8 @@ function bbcode($Text,$preserve_nl = 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); // Check for list text From 3a07973ffae4e0f9c576d343eafee30401d92449 Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Sun, 12 Feb 2012 15:51:17 -0800 Subject: [PATCH 6/9] Added [center] bbcode support. --- include/bbcode.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/bbcode.php b/include/bbcode.php index fa5b7e0806..20418f9407 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -142,6 +142,9 @@ function bbcode($Text,$preserve_nl = false) { $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","$2",$Text); $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","$2",$Text); + // Check for centered text + $Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
      $1
      ",$Text); + // Check for list text if(stristr($Text,'[/(list|ul|ol)]')) From 10e66d293df695e37be05200ab130f1fc988880b Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Sun, 12 Feb 2012 16:18:58 -0800 Subject: [PATCH 7/9] Added [quote=Name] bbcode support. --- include/bbcode.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/bbcode.php b/include/bbcode.php index 20418f9407..5eacb256b2 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -197,7 +197,13 @@ upper-alpha;">$2
    ' ,$Text); $QuoteLayout = '
    $1
    '; // Check for [quote] text $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/ism","$QuoteLayout", $Text); - + + // Check for [quote=Author] text + $t_wrote = t("wrote"); + $Text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism", + "
    $1 wrote: $2
    ", + $Text); + // [img=widthxheight]image source[/img] $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); From e575a3a02c324d65e6849ffd3f8cf68e7318f748 Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Sun, 12 Feb 2012 17:10:06 -0800 Subject: [PATCH 8/9] Fixed bbcode [li] and [*] handling. --- include/bbcode.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 5eacb256b2..1d11f687de 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -146,12 +146,8 @@ function bbcode($Text,$preserve_nl = false) { $Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
    $1
    ",$Text); // Check for list text - - if(stristr($Text,'[/(list|ul|ol)]')) - $Text = str_replace("[*]", "
  • ", $Text); - - if(stristr($Text,'[/list]')) - $Text = str_replace("[*]", "
  • ", $Text); + $Text = str_replace("[*]", "
  • ", $Text); + $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '
  • $1
  • ' ,$Text); $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '' ,$Text); $Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '' @@ -168,7 +164,6 @@ upper-roman;">$2' ,$Text); lower-alpha;">$2' ,$Text); $Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '' ,$Text); - $Text = preg_replace("/\[li\](.*?)\[\/li\]/sm", '
  • $1
  • ' ,$Text); $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1' ,$Text); $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1' ,$Text); From 135005571f4cfe3170b2f2ce0ea94b39a75c111a Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Sun, 12 Feb 2012 17:27:08 -0800 Subject: [PATCH 9/9] Added [th] bbcode tag support. --- include/bbcode.php | 1 + 1 file changed, 1 insertion(+) diff --git a/include/bbcode.php b/include/bbcode.php index 1d11f687de..9c70cb494a 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -165,6 +165,7 @@ lower-alpha;">$2' ,$Text); $Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '
      $2
    ' ,$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", '$1
    ' ,$Text);