X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fbbcode.php;h=6a44e19ec446e87bcef9b83f53cab95d4af85299;hb=810843763dcde2a004f992dc23c928a45ab8184b;hp=8102fc3f71e5de0ef5251b034305cddb04ee4f04;hpb=c8e0685788a26811af63f3127ecff0c9f1712ca4;p=friendica.git diff --git a/include/bbcode.php b/include/bbcode.php index 8102fc3f71..6a44e19ec4 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -2,7 +2,24 @@ require_once("include/oembed.php"); require_once('include/event.php'); require_once('include/map.php'); +require_once('mod/proxy.php'); +require_once('include/Contact.php'); +function bb_PictureCacheExt($matches) { + if (strpos($matches[3], "data:image/") === 0) + return ($matches[0]); + + $matches[3] = proxy_url($matches[3]); + return "[img=".$matches[1]."x".$matches[2]."]".$matches[3]."[/img]"; +} + +function bb_PictureCache($matches) { + if (strpos($matches[1], "data:image/") === 0) + return ($matches[0]); + + $matches[1] = proxy_url($matches[1]); + return "[img]".$matches[1]."[/img]"; +} function bb_map_coords($match) { // the extra space in the following line is intentional @@ -83,10 +100,19 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { $image = ""; } - if ($simplehtml == 7) - $text = sprintf('%s', - $url, $title, $title); - elseif (($simplehtml != 4) AND ($simplehtml != 0)) + if ($simplehtml == 7) { + $title2 = $title; + + $test1 = trim(html_entity_decode($match[1],ENT_QUOTES,'UTF-8')); + $test2 = trim(html_entity_decode($title,ENT_QUOTES,'UTF-8')); + + // If the link description is similar to the text above then don't add the link description + if (($title != "") AND ((strpos($test1,$test2) !== false) OR + (similar_text($test1,$test2) / strlen($title)) > 0.9)) + $title2 = $url; + $text = sprintf('%s
', + $url, $title, $title2); + } elseif (($simplehtml != 4) AND ($simplehtml != 0)) $text = sprintf('%s
', $url, $title); else { $text = sprintf('', $type); @@ -101,9 +127,9 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { $text = $oembed; else { if (($image != "") AND !strstr(strtolower($oembed), "
', $url, $image, $title); + $text .= sprintf('
', $url, proxy_url($image), $title); elseif (($preview != "") AND !strstr(strtolower($oembed), "
', $url, $preview, $title); + $text .= sprintf('
', $url, proxy_url($preview), $title); $text .= $oembed; @@ -268,15 +294,20 @@ function stripcode_br_cb($s) { return '[code]' . str_replace('
', '', $s[1]) . '[/code]'; } +function bb_onelinecode_cb($match) { + if (strpos($match[1],"
")===false){ + return "".$match[1].""; + } + return "".$match[1].""; +} + function tryoembed($match){ - //$url = ((count($match)==2)?$match[1]:$match[2]); $url = $match[1]; // Always embed the SSL version $url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"), array("https://www.youtube.com/", "https://player.vimeo.com/"), $url); - //logger("tryoembed: $url"); $o = oembed_fetch_url($url); @@ -286,7 +317,7 @@ function tryoembed($match){ if ($o->type=="error") return $match[0]; $html = oembed_format_object($o); - return $html; //oembed_iframe($html,$o->width,$o->height); + return $html; } @@ -448,7 +479,7 @@ function bb_replace_images($body, $images) { // We're depending on the property of 'foreach' (specified on the PHP website) that // it loops over the array starting from the first element and going sequentially // to the last element - $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '' . t('Image/photo') . '', $newbody); + $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '' . t('Image/photo') . '', $newbody); $cnt++; } @@ -511,8 +542,23 @@ function bb_ShareAttributes($share, $simplehtml) { $reldate = (($posted) ? " " . relative_date($posted) : ''); } - $userid = GetProfileUsername($profile,$author, false); - $userid_compact = GetProfileUsername($profile,$author, true); + $data = get_contact_details_by_url($profile); + + if (isset($data["name"]) AND isset($data["addr"])) + $userid_compact = $data["name"]." (".$data["addr"].")"; + else + $userid_compact = GetProfileUsername($profile,$author, true); + + if (isset($data["addr"])) + $userid = $data["addr"]; + else + $userid = GetProfileUsername($profile,$author, false); + + if (isset($data["name"])) + $author = $data["name"]; + + if (isset($data["photo"])) + $avatar = $data["photo"]; $preshare = trim($share[1]); @@ -578,7 +624,7 @@ function bb_ShareAttributes($share, $simplehtml) { default: $headline = trim($share[1]).'
'; if ($avatar != "") - $headline .= ''; + $headline .= ''; $headline .= sprintf(t('%s wrote the following post'.$reldate.':'), $profile, $author, $link); $headline .= "
"; @@ -927,12 +973,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi", 'bb_DiasporaLinks', $Text); // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text - if (!$forplaintext) - $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); - else { - $Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism"," $1 ",$Text); - $Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_RemovePictureLinks', $Text); - } +// if ($simplehtml != 7) { + if (!$forplaintext) + $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); + else { + $Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism"," $1 ",$Text); + $Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_RemovePictureLinks', $Text); + } +// } if ($tryoembed) $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text); @@ -1095,13 +1143,17 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal "
" . $t_wrote . "
$2
", $Text); + // [img=widthxheight]image source[/img] - //$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $Text); + $Text = preg_replace_callback("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", 'bb_PictureCacheExt', $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); // Images // [img]pathtoimage[/img] + $Text = preg_replace_callback("/\[img\](.*?)\[\/img\]/ism", 'bb_PictureCache', $Text); + $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . t('Image/photo') . '', $Text); @@ -1179,11 +1231,11 @@ 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')) { - $sub = format_event_html($ev); + $sub = format_event_html($ev, $simplehtml); $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text); $Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism",'',$Text); @@ -1193,6 +1245,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text); } + + //replace oneliner with + $Text = preg_replace_callback("|(?!]*>)([^<]*)(?!]*>)|ism", 'bb_onelinecode_cb', $Text); + // Unhide all [noparse] contained bbtags unspacefying them // and triming the [noparse] tag.