X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fbbcode.php;h=b68a7c5b188ec74c7e181fd9056a2f8e76084fe5;hb=9d4d29ad9eb6302fb02eda0ba5f6bcd128a86f49;hp=13061958c5f12682deb5bc52f87ea5868f9f5a93;hpb=4b6afbf6814acde5151edc74f0b6cf1fd7685432;p=friendica.git
diff --git a/include/bbcode.php b/include/bbcode.php
index 13061958c5..b68a7c5b18 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -2,7 +2,23 @@
require_once("include/oembed.php");
require_once('include/event.php');
require_once('include/map.php');
+require_once('mod/proxy.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 +99,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 +126,9 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
$text = $oembed;
else {
if (($image != "") AND !strstr(strtolower($oembed), "![]()
![%s](%s)
', $url, $image, $title);
+ $text .= sprintf('![%s](%s)
', $url, proxy_url($image), $title);
elseif (($preview != "") AND !strstr(strtolower($oembed), "![]()
![%s](%s)
', $url, $preview, $title);
+ $text .= sprintf('![%s](%s)
', $url, proxy_url($preview), $title);
$text .= $oembed;
@@ -276,14 +301,12 @@ function bb_onelinecode_cb($match) {
}
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);
@@ -293,7 +316,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;
}
@@ -455,7 +478,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 . '#$]', '
', $newbody);
+ $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '
', $newbody);
$cnt++;
}
@@ -585,7 +608,7 @@ function bb_ShareAttributes($share, $simplehtml) {
default:
$headline = trim($share[1]).'";
@@ -934,12 +957,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);
@@ -1102,13 +1127,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", '
', $Text);
$Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '
', $Text);
@@ -1190,7 +1219,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// 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);