X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fbbcode.php;h=13061958c5f12682deb5bc52f87ea5868f9f5a93;hb=e9f001aa5d45bb928af9332f1d24cb54bf9fdb86;hp=e63a8d394ec41f6663b3001acd2327ca13b76c10;hpb=7d1a6cc1d60798ff91719686c1b4686f1c4d33e6;p=friendica.git diff --git a/include/bbcode.php b/include/bbcode.php index e63a8d394e..13061958c5 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1,7 +1,241 @@ ' . generate_map(str_replace('/',' ',$match[1])) . '', $match[0]); +} +function bb_map_location($match) { + // the extra space in the following line is intentional + return str_replace($match[0],'
' . generate_named_map($match[1]) . '
', $match[0]); +} + +function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { + $Text = preg_replace_callback("/(.*?)\[attachment(.*?)\](.*?)\[\/attachment\]/ism", + function ($match) use ($simplehtml, $tryoembed){ + + $attributes = $match[2]; + + $type = ""; + preg_match("/type='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $type = strtolower($matches[1]); + + preg_match('/type="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $type = strtolower($matches[1]); + + if ($type == "") + return($match[0]); + + if (!in_array($type, array("link", "audio", "video"))) + return($match[0]); + + $url = ""; + preg_match("/url='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $url = $matches[1]; + + preg_match('/url="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $url = $matches[1]; + + $title = ""; + preg_match("/title='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $title = $matches[1]; + + preg_match('/title="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $title = $matches[1]; + + //$title = htmlentities($title, ENT_QUOTES, 'UTF-8', false); + $title = bbcode(html_entity_decode($title, ENT_QUOTES, 'UTF-8'), false, false, true); + $title = str_replace(array("[", "]"), array("[", "]"), $title); + + $image = ""; + if ($type != "video") { + preg_match("/image='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $image = $matches[1]; + + preg_match('/image="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $image = $matches[1]; + } + + $preview = ""; + if ($type != "video") { + preg_match("/preview='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $preview = $matches[1]; + + preg_match('/preview="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $preview = $matches[1]; + } + + if (((strpos($match[1], "[img=") !== false) OR (strpos($match[1], "[img]") !== false)) AND ($image != "")) { + $preview = $image; + $image = ""; + } + + if ($simplehtml == 7) + $text = sprintf('%s', + $url, $title, $title); + elseif (($simplehtml != 4) AND ($simplehtml != 0)) + $text = sprintf('%s
', $url, $title); + else { + $text = sprintf('', $type); + + $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $url, $title), $url, $title); + if ($tryoembed) + $oembed = tryoembed($bookmark); + else + $oembed = $bookmark[0]; + + if (strstr(strtolower($oembed), "', $Text); else $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", - 'https://www.youtube.com/watch?v=$1', $Text); + 'https://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); + $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?:\/\/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", - 'https://vimeo.com/$1', $Text); + 'https://vimeo.com/$1', $Text); // $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); - // oembed tag $Text = oembed_bbcode2html($Text); @@ -691,7 +1186,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal // If we found an event earlier, strip out all the event code and replace with a reformatted version. // Replace the event-start section with the entire formatted event. The other bbcode is stripped. - // Summary (e.g. title) is required, earlier revisions only required description (in addition to + // 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')) { @@ -699,13 +1194,17 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text); $Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism",'',$Text); - $Text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/ism",$sub,$Text); + $Text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/ism",$sub,$Text); $Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism",'',$Text); $Text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism",'',$Text); $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text); } - // Unhide all [noparse] contained bbtags unspacefying them + + //replace oneliner with + $Text = preg_replace_callback("|(?!]*>)([^<]*)(?!]*>)|ism", 'bb_onelinecode_cb', $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); @@ -719,30 +1218,31 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal // 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)=\"(?!http|ftp|mailto|cid)(.*?)\>/ism",'<$1$2="">',$Text); + $Text = preg_replace("/\<([^>]*?)(src|href)=\"(?!http|ftp|mailto|gopher|cid)(.*?)\>/ism",'<$1$2="">',$Text); if($saved_image) $Text = bb_replace_images($Text, $saved_image); - // Clean up the HTML by loading and saving the HTML with the DOM - // Only do it when it has to be done - for performance reasons - // Update: Now it is done every time - since bad structured html can break a whole page - //if (!$tryoembed) { - // $doc = new DOMDocument(); - // $doc->preserveWhiteSpace = false; + // Clean up the HTML by loading and saving the HTML with the DOM. + // Bad structured html can break a whole page. + // For performance reasons do it only with ativated item cache or at export. + if (!$tryoembed OR (get_itemcachepath() != "")) { + $doc = new DOMDocument(); + $doc->preserveWhiteSpace = false; - // $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8"); + $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8"); - // $doctype = ''; - // @$doc->loadHTML($doctype."".$Text.""); + $doctype = ''; + $encoding = ''; + @$doc->loadHTML($encoding.$doctype."".$Text.""); + $doc->encoding = 'UTF-8'; + $Text = $doc->saveHTML(); + $Text = str_replace(array("", "", $doctype, $encoding), array("", "", "", ""), $Text); - // $Text = $doc->saveHTML(); - // $Text = str_replace(array("", "", $doctype), array("", "", ""), $Text); + $Text = str_replace('
','', $Text); - // $Text = str_replace('
','', $Text); - - // $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES'); - //} + //$Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES'); + } // Clean up some useless linebreaks in lists //$Text = str_replace('
  • ','
  • ', $Text); // $Text = str_replace('
    save_timestamp($stamp1, "parser"); - - return $Text; + return trim($Text); } +?>