From f03a937c4ea73e47e48592a5ba0d051c535c51d3 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Tue, 7 Apr 2015 22:39:42 +0200 Subject: Renamed some functions to match other names in bbcode.php. Some documentation. Removed unused variables. Removed empty spaces at line endings. --- include/bbcode.php | 402 ++++++++++++++++++++++++++++------------------------- 1 file changed, 211 insertions(+), 191 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 5ee3d5d5e..e79e709da 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1,28 +1,33 @@ -type=="error") return $match[0]; + if ($o->type == 'error') + return $match[0]; $html = oembed_format_object($o); return $html; } function tryzrlaudio($match) { - $link = $match[1]; $zrl = is_matrix_url($link); if($zrl) $link = zid($link); - return ''; + + return ''; } function tryzrlvideo($match) { @@ -30,8 +35,8 @@ function tryzrlvideo($match) { $zrl = is_matrix_url($link); if($zrl) $link = zid($link); - return ''; + return ''; } // [noparse][i]italic[/i][/noparse] turns into @@ -39,11 +44,12 @@ function tryzrlvideo($match) { // 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; + $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], @@ -51,10 +57,11 @@ function bb_spacefy($st) { // returning [i]italic[/i] function bb_unspacefy_and_trim($st) { - $whole_match = $st[0]; - $captured = $st[1]; - $unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured); - return $unspacefied; + //$whole_match = $st[0]; + $captured = $st[1]; + $unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured); + + return $unspacefied; } @@ -103,8 +110,8 @@ function bb_extract_images($body) { function bb_replace_images($body, $images) { $newbody = $body; - $cnt = 0; + if(! $images) return $newbody; @@ -119,10 +126,15 @@ function bb_replace_images($body, $images) { return $newbody; } - - +/** + * @brief Parses crypt BBCode. + * + * @param array $match + * @return string HTML code + */ function bb_parse_crypt($match) { + $matches = array(); $attributes = $match[1]; $algorithm = ""; @@ -137,7 +149,6 @@ function bb_parse_crypt($match) { $hint = ""; - preg_match("/hint='(.*?)'/ism", $attributes, $matches); if ($matches[1] != "") $hint = $matches[1]; @@ -147,36 +158,42 @@ function bb_parse_crypt($match) { $x = random_string(); - $Text = '
' . t('Encrypted content') . '

'; + $Text = '
' . t('Encrypted content') . '

'; return $Text; - } function bb_parse_app($match) { require_once('include/apps.php'); $app = app_decode($match[1]); - if($app) + if ($app) return app_render($app); - } function bb_parse_element($match) { $j = json_decode(base64url_decode($match[1]),true); - if($j) { + if ($j) { $o = EOL . '' . t('Install design element: ') . $j['pagetitle'] . '' . EOL; } + return $o; } +/** + * @brief Returns an QR-code image from a value given in $match[1]. + * + * @param array $match + * @return string HTML img with QR-code of $match[1] + */ function bb_qr($match) { return '' . t('QR code') . ''; -} +} function bb_ShareAttributes($match) { + $matches = array(); $attributes = $match[1]; $author = ""; @@ -204,13 +221,14 @@ function bb_ShareAttributes($match) { if ($matches[1] != "") $posted = $matches[1]; + // message_id is never used, do we still need it? $message_id = ""; preg_match("/message_id='(.*?)'/ism", $attributes, $matches); if ($matches[1] != "") $message_id = $matches[1]; - // FIXME - this should really be a wall-item-ago so it will get updated on the client + /** @FIXME - this should really be a wall-item-ago so it will get updated on the client */ $reldate = (($posted) ? relative_date($posted) : ''); $headline = '
'; @@ -230,24 +248,30 @@ function bb_ShareAttributes($match) { $text = $headline . '
' . trim($match[2]) . '
'; - return($text); + return $text; } function bb_location($match) { // not yet implemented } -function bbiframe($match) { +/** + * @brief Returns an iframe from $match[1]. + * + * @param array $match + * @return string HTML iframe with content of $match[1] + */ +function bb_iframe($match) { $a = get_app(); - - $sandbox = ((strpos($match[1],get_app()->get_hostname())) ? ' sandbox="allow-scripts" ' : ''); + $sandbox = ((strpos($match[1], $a->get_hostname())) ? ' sandbox="allow-scripts" ' : ''); return ''; } function bb_ShareAttributesSimple($match) { + $matches = array(); $attributes = $match[1]; $author = ""; @@ -268,16 +292,16 @@ function bb_ShareAttributesSimple($match) { if ($matches[1] != "") $profile = $matches[1]; - $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$author.": div class=\"reshared-content\">" .$match[2]."
"; + $text = '
' . html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . ' ' . $author . ': div class="reshared-content">' . $match[2] . ''; return($text); } function rpost_callback($match) { if ($match[2]) { - return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&title=' . urlencode($match[2]) . '&body=' . urlencode($match[3]),$match[0]); + return str_replace($match[0], get_rpost_path(get_app()->get_observer()) . '&title=' . urlencode($match[2]) . '&body=' . urlencode($match[3]), $match[0]); } else { - return str_replace($match[0],get_rpost_path(get_app()->get_observer()) . '&body=' . urlencode($match[3]),$match[0]); + return str_replace($match[0], get_rpost_path(get_app()->get_observer()) . '&body=' . urlencode($match[3]), $match[0]); } } @@ -291,52 +315,59 @@ function bb_map_location($match) { return str_replace($match[0],'
' . generate_named_map($match[1]) . '
', $match[0]); } -function bbopentag($match) { - $rnd = mt_rand(); - return "
" . $match[1] . "
" . $match[2] . "
"; +function bb_opentag($match) { + $rnd = mt_rand(); + return "
" . $match[1] . "
" . $match[2] . "
"; } - - +/** + * @brief Sanitize style properties from BBCode to HTML. + * + * @param array $input + * @return string A HTML span tag with the styles. + */ function bb_sanitize_style($input) { - //whitelist property limits (0 = no limitation) - $w = array( // color properties - "color" => 0, - "background-color" => 0, + // whitelist array: property => limits (0 = no limitation) + $w = array( + // color properties + "color" => 0, + "background-color" => 0, // box properties - "padding" => array("px"=>100, "%"=>0, "em"=>2, "ex"=>2, "mm"=>0, "cm"=>0, "in"=>0, "pt"=>0, "pc"=>0), - "margin" => array("px"=>100, "%"=>0, "em"=>2, "ex"=>2, "mm"=>0, "cm"=>0, "in"=>0, "pt"=>0, "pc"=>0), - "border" => array("px"=>100, "%"=>0, "em"=>2, "ex"=>2, "mm"=>0, "cm"=>0, "in"=>0, "pt"=>0, "pc"=>0), - "float" => 0, - "clear" => 0, + "padding" => array("px"=>100, "%"=>0, "em"=>2, "ex"=>2, "mm"=>0, "cm"=>0, "in"=>0, "pt"=>0, "pc"=>0), + "margin" => array("px"=>100, "%"=>0, "em"=>2, "ex"=>2, "mm"=>0, "cm"=>0, "in"=>0, "pt"=>0, "pc"=>0), + "border" => array("px"=>100, "%"=>0, "em"=>2, "ex"=>2, "mm"=>0, "cm"=>0, "in"=>0, "pt"=>0, "pc"=>0), + "float" => 0, + "clear" => 0, // text properties - "text-decoration" => 0, - + "text-decoration" => 0, ); + $css = array(); $css_string = $input[1]; - $a = explode(';',$css_string); + $a = explode(';', $css_string); + foreach($a as $parts){ list($k, $v) = explode(':', $parts); - $css[ trim($k) ] = trim($v); + $css[ trim($k) ] = trim($v); } // sanitize properties $b = array_merge(array_diff_key($css, $w), array_diff_key($w, $css)); $css = array_diff_key($css, $b); + $css_string_san = ''; - foreach($css as $key => $value) { - if($w[$key] != null) { - foreach($w[$key] as $limit_key => $limit_value) { + foreach ($css as $key => $value) { + if ($w[$key] != null) { + foreach ($w[$key] as $limit_key => $limit_value) { //sanitize values - if(strpos($value, $limit_key)) { + if (strpos($value, $limit_key)) { $value = preg_replace_callback( "/(\S.*?)$limit_key/ism", function($match) use($limit_value, $limit_key) { - if($match[1] > $limit_value) { + if ($match[1] > $limit_value) { return $limit_value . $limit_key; } else { - return $match[1] . $limit_key; + return $match[1] . $limit_key; } }, $value @@ -346,19 +377,20 @@ function bb_sanitize_style($input) { } $css_string_san .= $key . ":" . $value ."; "; } - return "" . $input[2] . ""; + + return '' . $input[2] . ''; } // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendica/Red - Mike Macgirvin -function bbcode($Text,$preserve_nl = false, $tryoembed = true) { +function bbcode($Text, $preserve_nl = false, $tryoembed = true) { $a = get_app(); - // Move all spaces out of the tags + // Move all spaces out of the tags // ....Uhm why? - // This is basically doing a trim() on the stuff in between tags, but it messes up + // This is basically doing a trim() on the stuff in between tags, but it messes up // carefully crafted bbcode and especially other pre-formatted code. // Commenting out until we come up with a use case where it's needed. Then let's try and // special case rather than a heavy-handed approach like this. @@ -399,7 +431,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[observer\=0\](.*?)\[\/observer\]/ism", '$1', $Text); $Text = preg_replace("/\[rpost(=.*?)?\](.*?)\[\/rpost\]/ism", '', $Text); } - } + } $channel = $a->get_channel(); if (strpos($Text,'[/channel]') !== false) { @@ -410,7 +442,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[channel\=1\].*?\[\/channel\]/ism", '', $Text); $Text = preg_replace("/\[channel\=0\](.*?)\[\/channel\]/ism", '$1', $Text); } - } + } $x = bb_extract_images($Text); @@ -419,14 +451,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace(array('[baseurl]','[sitename]'),array(z_root(),get_config('system','sitename')),$Text); - + // Replace any html brackets with HTML Entities to prevent executing HTML or script // Don't use strip_tags here because it breaks [url] search by replacing & with amp $Text = str_replace("<", "<", $Text); $Text = str_replace(">", ">", $Text); - + // Convert new line chars to html
tags // nlbr seems to be hopelessly messed up @@ -434,14 +466,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // We'll emulate it. - $Text = str_replace("\r\n","\n", $Text); - $Text = str_replace(array("\r","\n"), array('
','
'), $Text); + $Text = str_replace("\r\n", "\n", $Text); + $Text = str_replace(array("\r", "\n"), array('
', '
'), $Text); - if($preserve_nl) - $Text = str_replace(array("\n","\r"), array('',''),$Text); + if ($preserve_nl) + $Text = str_replace(array("\n", "\r"), array('', ''), $Text); - $Text = str_replace(array("\t"," "),array("    ","  "),$Text); + $Text = str_replace(array("\t", " "), array("    ", "  "), $Text); // Set up the parameters for a URL search string $URLSearchString = "^\[\]"; @@ -459,20 +491,18 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace('[observer.name]',$s1 . $observer['xchan_name'] . $s2, $Text); $Text = str_replace('[observer.address]',$s1 . $observer['xchan_addr'] . $s2, $Text); $Text = str_replace('[observer.webname]',$s1 . substr($observer['xchan_addr'],0,strpos($observer['xchan_addr'],'@')) . $s2, $Text); - $Text = str_replace('[observer.photo]',$s1 . '[zmg]'.$observer['xchan_photo_l'].'[/zmg]' . $s2, $Text); + $Text = str_replace('[observer.photo]',$s1 . '[zmg]'.$observer['xchan_photo_l'].'[/zmg]' . $s2, $Text); } else { $Text = str_replace('[observer.baseurl]', '', $Text); $Text = str_replace('[observer.url]','', $Text); $Text = str_replace('[observer.name]','', $Text); $Text = str_replace('[observer.address]','', $Text); $Text = str_replace('[observer.webname]','',$Text); - $Text = str_replace('[observer.photo]','', $Text); + $Text = str_replace('[observer.photo]','', $Text); } - - // Perform URL Search $urlchars = '[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,\@]'; @@ -482,32 +512,31 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } if (strpos($Text,'[/qr]') !== false) { - $Text = preg_replace_callback("/\[qr\](.*?)\[\/qr\]/ism","bb_qr",$Text); + $Text = preg_replace_callback("/\[qr\](.*?)\[\/qr\]/ism", 'bb_qr', $Text); } - if (strpos($Text,'[/share]') !== false) { - $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); + $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); + $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", '#^$1', $Text); $Text = preg_replace("/\#\^\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '#^$2', $Text); $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); + $Text = preg_replace("/\#\^\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '#^$1', $Text); + $Text = preg_replace("/\#\^\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '#^$2', $Text); $Text = preg_replace("/\[zrl\]([$URLSearchString]*)\[\/zrl\]/ism", '$1', $Text); $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); - } + } // Perform MAIL Search - if (strpos($Text,'[/mail]') !== false) { + if (strpos($Text,'[/mail]') !== false) { $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '$1', $Text); $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '$2', $Text); } @@ -515,54 +544,52 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // leave open the posibility of [map=something] // this is replaced in prepare_body() which has knowledge of the item location - if (strpos($Text,'[/map]') !== false) { - $Text = preg_replace_callback("/\[map\](.*?)\[\/map\]/ism",'bb_map_location',$Text); + if (strpos($Text,'[/map]') !== false) { + $Text = preg_replace_callback("/\[map\](.*?)\[\/map\]/ism", 'bb_map_location', $Text); } - - if (strpos($Text,'[map=') !== false) { - $Text = preg_replace_callback("/\[map=(.*?)\]/ism",'bb_map_coords',$Text); + if (strpos($Text,'[map=') !== false) { + $Text = preg_replace_callback("/\[map=(.*?)\]/ism", 'bb_map_coords', $Text); } - - if (strpos($Text,'[map]') !== false) { + if (strpos($Text,'[map]') !== false) { $Text = preg_replace("/\[map\]/", '
', $Text); } // Check for bold text - if (strpos($Text,'[b]') !== false) { - $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 - if (strpos($Text,'[i]') !== false) { - $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 - if (strpos($Text,'[u]') !== false) { - $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 if (strpos($Text,'[s]') !== false) { - $Text = preg_replace("(\[s\](.*?)\[\/s\])ism",'$1',$Text); + $Text = preg_replace("(\[s\](.*?)\[\/s\])ism", '$1', $Text); } // Check for over-line text - if (strpos($Text,'[o]') !== false) { - $Text = preg_replace("(\[o\](.*?)\[\/o\])ism",'$1',$Text); + if (strpos($Text,'[o]') !== false) { + $Text = preg_replace("(\[o\](.*?)\[\/o\])ism", '$1', $Text); } - if (strpos($Text,'[sup]') !== false) { - $Text = preg_replace("(\[sup\](.*?)\[\/sup\])ism",'$1',$Text); + if (strpos($Text,'[sup]') !== false) { + $Text = preg_replace("(\[sup\](.*?)\[\/sup\])ism", '$1', $Text); } - if (strpos($Text,'[sub]') !== false) { - $Text = preg_replace("(\[sub\](.*?)\[\/sub\])ism",'$1',$Text); + if (strpos($Text,'[sub]') !== false) { + $Text = preg_replace("(\[sub\](.*?)\[\/sub\])ism", '$1', $Text); } - + // Check for colored text - if (strpos($Text,'[/color]') !== false) { - $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). - if (strpos($Text,'[/size]') !== false) { - $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","$2",$Text); - $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","$2",$Text); + // [size=50] --> font-size: 50px (with the unit). + if (strpos($Text,'[/size]') !== false) { + $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism", "$2", $Text); + $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism", "$2", $Text); } // Check for h1 if (strpos($Text,'[h1]') !== false) { @@ -590,16 +617,15 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } // Check for table of content without params if (strpos($Text,'[toc]') !== false) { - $Text = preg_replace("/\[toc\]/ism",'',$Text); + $Text = preg_replace("/\[toc\]/ism",'',$Text); } // Check for table of content with params if (strpos($Text,'[toc') !== false) { $Text = preg_replace("/\[toc([^\]]+?)\]/ism",'',$Text); - } // Check for centered text - if (strpos($Text,'[/center]') !== false) { - $Text = preg_replace("(\[center\](.*?)\[\/center\])ism","
$1
",$Text); + if (strpos($Text,'[/center]') !== false) { + $Text = preg_replace("(\[center\](.*?)\[\/center\])ism", "
$1
", $Text); } // Check for list text $Text = str_replace("[*]", "
  • ", $Text); @@ -608,52 +634,54 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $endlessloop = 0; while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) || - ((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) || - ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false)) || - ((strpos($Text, "[/li]") !== false) && (strpos($Text, "[li]") !== false))) && (++$endlessloop < 20)) { - $Text = preg_replace("/\[list\](.*?)\[\/list\]/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",'
      $2
    ' ,$Text); - $Text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '
      $2
    ' ,$Text); - $Text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '
      $2
    ' ,$Text); - $Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '
      $2
    ' ,$Text); - $Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '
      $1
    ' ,$Text); - $Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '
      $1
    ' ,$Text); - $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '
  • $1
  • ' ,$Text); - } - if (strpos($Text,'[th]') !== false) { - $Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1' ,$Text); + ((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) || + ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false)) || + ((strpos($Text, "[/li]") !== false) && (strpos($Text, "[li]") !== false))) && (++$endlessloop < 20)) { + $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)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("/\[ul\](.*?)\[\/ul\]/ism", '', $Text); + $Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '', $Text); + $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '
  • $1
  • ', $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); + $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1', $Text); } - if (strpos($Text,'[tr]') !== false) { - $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/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", '$1
    ' ,$Text); - $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); - $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
    ' ,$Text); + if (strpos($Text,'[/table]') !== false) { + $Text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '$1
    ', $Text); + $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
    ', $Text); + $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
    ', $Text); } - $Text = str_replace('
    ',"\n",$Text); - $Text = str_replace('[hr]','
    ', $Text); + $Text = str_replace('
    ', "\n", $Text); + $Text = str_replace('[hr]', '
    ', $Text); // This is actually executed in prepare_body() - $Text = str_replace('[nosmile]','',$Text); + $Text = str_replace('[nosmile]', '', $Text); // Check for font change text - if (strpos($Text,'[/font]') !== false) { - $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 + // Declare the format for [code] layout $CodeLayout = '$1'; + // Check for [code] text - if (strpos($Text,'[code]') !== false) { - $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
    '; @@ -661,7 +689,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // handle nested quotes $endlessloop = 0; while ((strpos($Text, "[/spoiler]") !== false) and (strpos($Text, "[spoiler]") !== false) and (++$endlessloop < 20)) - $Text = preg_replace("/\[spoiler\](.*?)\[\/spoiler\]/ism","$SpoilerLayout", $Text); + $Text = preg_replace("/\[spoiler\](.*?)\[\/spoiler\]/ism", "$SpoilerLayout", $Text); // Check for [spoiler=Author] text @@ -677,12 +705,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $endlessloop = 0; while ((strpos($Text, "[/open]")!== false) and (strpos($Text, "[open=") !== false) and (++$endlessloop < 20)) { - $rnd = mt_rand(); - $Text = preg_replace_callback("/\[open=(.*?)\](.*?)\[\/open\]/ism",'bbopentag',$Text); + $Text = preg_replace_callback("/\[open=(.*?)\](.*?)\[\/open\]/ism", 'bb_opentag', $Text); } - // Declare the format for [quote] layout $QuoteLayout = '
    $1
    '; @@ -690,7 +716,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // handle nested quotes $endlessloop = 0; while ((strpos($Text, "[/quote]") !== false) and (strpos($Text, "[quote]") !== false) and (++$endlessloop < 20)) - $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/ism","$QuoteLayout", $Text); + $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/ism", "$QuoteLayout", $Text); // Check for [quote=Author] text @@ -754,9 +780,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } // crypt - if (strpos($Text,'[/crypt]') !== false) { + if (strpos($Text,'[/crypt]') !== false) { $x = random_string(); - $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); + $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
    ' . t('Encrypted content') . '
    ', $Text); $Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text); } @@ -768,32 +794,30 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace_callback("/\[element\](.*?)\[\/element\]/ism",'bb_parse_element', $Text); } - // html5 video and audio - if (strpos($Text,'[/video]') !== false) { + if (strpos($Text,'[/video]') !== false) { $Text = preg_replace_callback("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mpeg|mpg))\[\/video\]/ism", 'tryzrlvideo', $Text); } - if (strpos($Text,'[/audio]') !== false) { + if (strpos($Text,'[/audio]') !== false) { $Text = preg_replace_callback("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3|opus))\[\/audio\]/ism", 'tryzrlaudio', $Text); } - if (strpos($Text,'[/zvideo]') !== false) { + if (strpos($Text,'[/zvideo]') !== false) { $Text = preg_replace_callback("/\[zvideo\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mpeg|mpg))\[\/zvideo\]/ism", 'tryzrlvideo', $Text); } - if (strpos($Text,'[/zaudio]') !== false) { + if (strpos($Text,'[/zaudio]') !== false) { $Text = preg_replace_callback("/\[zaudio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3|opus))\[\/zaudio\]/ism", 'tryzrlaudio', $Text); } // Try to Oembed if ($tryoembed) { - - if (strpos($Text,'[/video]') !== false) { + 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 (strpos($Text,'[/zvideo]') !== false) { + if (strpos($Text,'[/zvideo]') !== false) { $Text = preg_replace_callback("/\[zvideo\](.*?)\[\/zvideo\]/ism", 'tryoembed', $Text); } if (strpos($Text,'[/zaudio]') !== false) { @@ -816,43 +840,40 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace("/\[zaudio\](.*?)\[\/zaudio\]/", '$1', $Text); } - - - if ($tryoembed){ if (strpos($Text,'[/iframe]') !== false) { - $Text = preg_replace_callback("/\[iframe\](.*?)\[\/iframe\]/ism", 'bbiframe', $Text); + $Text = preg_replace_callback("/\[iframe\](.*?)\[\/iframe\]/ism", 'bb_iframe', $Text); } - } - else { + } else { if (strpos($Text,'[/iframe]') !== false) { $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '$1', $Text); } } + // Youtube extensions 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_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); + $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", '', $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_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("/\[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); + $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); @@ -871,7 +892,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Summary (e.g. title) is required, earlier revisions only required description (in addition to // start which is always required). Allow desc with a missing summary for compatibility. - if((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) { + if ((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) { $sub = format_event_html($ev); $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text); @@ -885,26 +906,25 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Unhide all [noparse] contained bbtags unspacefying them // and triming the [noparse] tag. if (strpos($Text,'[noparse]') !== false) { - $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_unspacefy_and_trim',$Text); + $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); + $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_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim', $Text); } - $Text = preg_replace('/\[\&\;([#a-z0-9]+)\;\]/','&$1;',$Text); + $Text = preg_replace('/\[\&\;([#a-z0-9]+)\;\]/', '&$1;', $Text); // fix any escaped ampersands that may have been converted into links - $Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text); + $Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism", '<$1$2=$3&$4>', $Text); - $Text = preg_replace("/\<(.*?)(src|href)=\"[^zhfm#](.*?)\>/ism",'<$1$2="">',$Text); + $Text = preg_replace("/\<(.*?)(src|href)=\"[^zhfm#](.*?)\>/ism", '<$1$2="">', $Text); - $Text = bb_replace_images($Text,$saved_images); + $Text = bb_replace_images($Text, $saved_images); - call_hooks('bbcode',$Text); + call_hooks('bbcode', $Text); return $Text; } - -- cgit v1.2.3