X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fbbcode.php;h=8ccdfd981c1a2c3658762694b63ec82892ae5c4d;hb=56ee734b00aead633d5d213a6b140b75bc17ba96;hp=0d0cb0177c2f692b88d92f77a0c74e6ca9b3b831;hpb=979fc6d38a842373cfaf17b18daadea003761ed9;p=friendica.git diff --git a/include/bbcode.php b/include/bbcode.php index 0d0cb0177c..8ccdfd981c 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1,41 +1,47 @@ ' . generate_map(str_replace('/',' ',$match[1])) . '', $match[0]); + return str_replace($match[0], '
' . 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]); + return str_replace($match[0], '
' . generate_named_map($match[1]) . '
', $match[0]); } function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { $data = get_attachment_data($Text); - if (!$data) + if (!$data) { return $Text; + } if (isset($data["title"])) { $data["title"] = strip_tags($data["title"]); @@ -55,83 +61,91 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { // If the link description is similar to the text above then don't add the link description if (($data["title"] != "") AND ((strpos($test1,$test2) !== false) OR - (similar_text($test1,$test2) / strlen($data["title"])) > 0.9)) + (similar_text($test1,$test2) / strlen($data["title"])) > 0.9)) { $title2 = $data["url"]; - $text = sprintf('%s
', + } + $text = sprintf('%s
', $data["url"], $data["title"], $title2); - } elseif (($simplehtml != 4) AND ($simplehtml != 0)) + } elseif (($simplehtml != 4) AND ($simplehtml != 0)) { $text = sprintf('%s
', $data["url"], $data["title"]); - else { + } else { $text = sprintf('', $data["type"]); $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]); - if ($tryoembed) + if ($tryoembed) { $oembed = tryoembed($bookmark); - else + } else { $oembed = $bookmark[0]; + } - if (strstr(strtolower($oembed), "', $Text); - else + } else { $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); + $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) + if ($tryoembed) { $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text); - else + } else { $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '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?:\/\/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) + if ($tryoembed) { $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text); - else + } else { $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", 'https://vimeo.com/$1', $Text); + } // $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); @@ -1132,46 +1212,62 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal // 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, $simplehtml); - $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\-finish\](.*?)\[\/event\-finish\]/ism",'',$Text); - $Text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism",'',$Text); - $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text); - $Text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism",'',$Text); + $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\-finish\](.*?)\[\/event\-finish\]/ism", '', $Text); + $Text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism", '', $Text); + $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism", '', $Text); + $Text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $Text); } - //replace oneliner with - $Text = preg_replace_callback("|(?!]*>)([^<]*)(?!]*>)|ism", 'bb_onelinecode_cb', $Text); + // Replace inline code blocks + $Text = preg_replace_callback("|(?!]*>)([^<]*)(?!]*>)|ism", + function ($match) use ($simplehtml) { + $return = '' . $match[1] . ''; + // Use for Diaspora inline code blocks + if ($simplehtml === 3) { + $return = '' . $match[1] . ''; + } + return $return; + } + , $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); + $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); - $Text = preg_replace('/\[\&\;([#a-z0-9]+)\;\]/','&$1;',$Text); - $Text = preg_replace('/\&\#039\;/','\'',$Text); - $Text = preg_replace('/\"\;/','"',$Text); + $Text = preg_replace('/\[\&\;([#a-z0-9]+)\;\]/', '&$1;', $Text); + $Text = preg_replace('/\&\#039\;/', '\'', $Text); + $Text = preg_replace('/\"\;/', '"', $Text); // fix any escaped ampersands that may have been converted into links $Text = preg_replace('/\<([^>]*?)(src|href)=(.*?)\&\;(.*?)\>/ism', '<$1$2=$3&$4>', $Text); - // sanitizes src attributes (only relative URIs or http URLs) - $Text = preg_replace('#<([^>]*?)(src)="(?!/|http)(.*?)"(.*?)>#ism', '<$1$2=""$4 class="invalid-src" title="' . t('Invalid source protocol') . '">', $Text); + // sanitizes src attributes (http and redir URLs for displaying in a web page, cid used for inline images in emails) + static $allowed_src_protocols = array('http', 'redir', 'cid'); + $Text = preg_replace('#<([^>]*?)(src)="(?!' . implode('|', $allowed_src_protocols) . ')(.*?)"(.*?)>#ism', + '<$1$2=""$4 class="invalid-src" title="' . t('Invalid source protocol') . '">', $Text); + + // sanitize href attributes (only whitelisted protocols URLs) + // default value for backward compatibility + $allowed_link_protocols = Config::get('system', 'allowed_link_protocols', array('ftp', 'mailto', 'gopher', 'cid')); + + // Always allowed protocol even if config isn't set or not including it + $allowed_link_protocols[] = 'http'; - // sanitize href attributes (only relative URIs or whitelisted protocols URLs) - $allowed_link_protocols = get_config('system', 'allowed_link_protocols'); - $regex = '#<([^>]*?)(href)="(?!/|http|' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism'; + $regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism'; $Text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 class="invalid-href" title="' . t('Invalid link protocol') . '">', $Text); - if($saved_image) { + if ($saved_image) { $Text = bb_replace_images($Text, $saved_image); } @@ -1191,19 +1287,19 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = $doc->saveHTML(); $Text = str_replace(array("", "", $doctype, $encoding), array("", "", "", ""), $Text); - $Text = str_replace('
','', $Text); + $Text = str_replace('
', '', $Text); //$Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES'); } // Clean up some useless linebreaks in lists - //$Text = str_replace('

','', $Text); - //$Text = str_replace('
','', $Text); - //$Text = str_replace('
  • ','
  • ', $Text); - // $Text = str_replace('

    ', '', $Text); + //$Text = str_replace('

  • ', '', $Text); + //$Text = str_replace('
  • ', '
  • ', $Text); + //$Text = str_replace('