X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=include%2Fbbcode.php;h=70cd22d5f9c0eaa960c3aad0ac18a8f8e8f7a8e6;hb=714eb1a296b2529a1d1b410c0225fc1c6a3e48d0;hp=25d60647f32f2c8ea96ca0170eb91ff22fc49bdf;hpb=cab46e27724afccd4b9fe59fe9c00536cb390b2f;p=friendica.git
diff --git a/include/bbcode.php b/include/bbcode.php
index 25d60647f3..70cd22d5f9 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -1,240 +1,126 @@
%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 (($image != "") AND !strstr(strtolower($oembed), "
', $url, $image, $title);
- elseif (($preview != "") AND !strstr(strtolower($oembed), "
', $url, $preview, $title);
-
- $text .= $oembed;
-
- $text .= sprintf('%s
', trim($match[2]));
- }
+ $matches[3] = proxy_url($matches[3]);
+ return "[img=".$matches[1]."x".$matches[2]."]".$matches[3]."[/img]";
+}
- return($text);
- },$Text);
+function bb_PictureCache($matches) {
+ if (strpos($matches[1], "data:image/") === 0)
+ return ($matches[0]);
- return($Text);
+ $matches[1] = proxy_url($matches[1]);
+ return "[img]".$matches[1]."[/img]";
}
-/* function bb_rearrange_link($shared) {
- if ($shared[1] != "type-link")
- return($shared[0]);
+function bb_map_coords($match) {
+ // the extra space in the following line is intentional
+ 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]);
+}
- $newshare = trim($shared[2]);
- $newshare = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $newshare);
+function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
- if (!strpos($shared[0], "[bookmark"))
- $newshare = preg_replace("/\[url\=(.*?)\](.*?)\[\/url\]/ism", '[bookmark=$1]$2[/bookmark]', $newshare, 1);
+ $data = get_attachment_data($Text);
- preg_match("/\[img\](.*?)\[\/img\]/ism", $newshare, $matches);
+ if (!$data)
+ return $Text;
- if ($matches) {
- $newshare = str_replace($matches[0], '', $newshare);
- $newshare = "[img]".$matches[1]."[/img]\n".$newshare;
+ if (isset($data["title"])) {
+ $data["title"] = strip_tags($data["title"]);
+ $data["title"] = str_replace(array("http://", "https://"), "", $data["title"]);
}
- $search = array("\n\n", "\n ", " \n");
- $replace = array("\n", "\n", "\n");
- do {
- $oldtext = $newshare;
- $newshare = str_replace($search, $replace, $newshare);
- } while ($oldtext != $newshare);
-
- $newshare = "[class=type-link]".$newshare."[/class]";
-
- return($newshare);
-} */
-
-function bb_rearrange_share($shared) {
- if (!in_array(strtolower($shared[2]), array("type-link", "type-audio", "type-video")))
- return($shared[0]);
-
- if (!preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$shared[3], $bookmark))
- return($shared[0]);
-
- $type = substr(trim(strtolower($shared[2])), 5);
-
- $title = "";
- $url = "";
- $preview = "";
- $description = "";
-
- if (isset($bookmark[2][0]))
- $title = $bookmark[2][0];
-
- if (isset($bookmark[1][0]))
- $url = $bookmark[1][0];
-
- $cleanedshare = trim($shared[3]);
- $cleanedshare = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $cleanedshare);
- preg_match("/\[img\](.*?)\[\/img\]/ism", $cleanedshare, $matches);
+ if (((strpos($data["text"], "[img=") !== false) OR (strpos($data["text"], "[img]") !== false)) AND ($data["image"] != "")) {
+ $data["preview"] = $data["image"];
+ $data["image"] = "";
+ }
- if ($matches)
- $preview = trim($matches[1]);
+ if ($simplehtml == 7) {
+ $title2 = $data["title"];
- preg_match("/\[quote\](.*?)\[\/quote\]/ism", $cleanedshare, $matches);
- if ($matches)
- $description = trim($matches[1]);
+ $test1 = trim(html_entity_decode($data["text"],ENT_QUOTES,'UTF-8'));
+ $test2 = trim(html_entity_decode($data["title"],ENT_QUOTES,'UTF-8'));
- $url = str_replace(array("[", "]"), array("[", "]"), htmlentities($url, ENT_QUOTES, 'UTF-8', false));
- $title = str_replace(array("[", "]"), array("[", "]"), htmlentities($title, ENT_QUOTES, 'UTF-8', false));
- $preview = str_replace(array("[", "]"), array("[", "]"), htmlentities($preview, ENT_QUOTES, 'UTF-8', false));
+ // 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))
+ $title2 = $data["url"];
+ $text = sprintf('%s
',
+ $data["url"], $data["title"], $title2);
+ } elseif (($simplehtml != 4) AND ($simplehtml != 0))
+ $text = sprintf('%s
', $data["url"], $data["title"]);
+ else {
+ $text = sprintf('', $data["type"]);
- $Text = trim($shared[1])."\n[attachment type='".$type."'";
+ $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]);
+ if ($tryoembed)
+ $oembed = tryoembed($bookmark);
+ else
+ $oembed = $bookmark[0];
- if ($url != "")
- $Text .= " url='".$url."'";
- if ($title != "")
- $Text .= " title='".$title."'";
- if ($preview != "") {
- require_once("include/Photo.php");
- $picturedata = get_photo_info($preview);
+ if (strstr(strtolower($oembed), "', trim($data["description"]));
+ }
+ }
+ return $data["text"].$text.$data["after"];
}
function bb_remove_share_information($Text, $plaintext = false, $nolink = false) {
- $Text = preg_replace_callback("((.*?)\[class=(.*?)\](.*?)\[\/class\])ism",
- function ($match) use ($plaintext, $nolink){
- return(bb_cleanup_share($match, $plaintext, $nolink));
- },$Text);
- return($Text);
-}
-
-function bb_cleanup_share($shared, $plaintext, $nolink) {
- if (!in_array($shared[2], array("type-link", "type-video")))
- return($shared[0]);
- if ($plaintext)
- $shared[3] = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism","[bookmark=$1]$1[/bookmark]", $shared[3]);
+ $data = get_attachment_data($Text);
- if (!preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$shared[3], $bookmark))
- return($shared[0]);
+ if (!$data)
+ return $Text;
if ($nolink)
- return(trim($shared[1]));
-
- $title = "";
- $link = "";
-
- if (isset($bookmark[2][0]))
- $title = $bookmark[2][0];
-
- if (isset($bookmark[1][0]))
- $link = $bookmark[1][0];
-
- if (($title != "") AND (strpos($shared[1],$title) !== false))
- $title = "";
+ return $data["text"].$data["after"];
-// if (strpos($shared[1],$link) !== false)
-// $link = "";
-
- $text = trim($shared[1]);
+ if ($plaintext)
+ $data["title"] = $data["url"];
- if (($text == "") AND ($title != "") AND ($link == ""))
- $text .= "\n\n".trim($title);
+ if (($data["text"] == "") AND ($data["title"] != "") AND ($data["url"] == ""))
+ return $data["title"].$data["after"];
// If the link already is included in the post, don't add it again
- if (($link != "") AND strpos($text, $link))
- return(trim($text));
+ if (($data["url"] != "") AND strpos($data["text"], $data["url"]))
+ return $data["text"].$data["after"];
- if (($link != "") AND ($title != ""))
- $text .= "\n[url=".trim($link)."]".trim($title)."[/url]";
+ $text = $data["text"];
+
+ if (($data["url"] != "") AND ($data["title"] != ""))
+ $text .= "\n[url=".$data["url"]."]".$data["title"]."[/url]";
elseif (($link != ""))
- $text .= "\n".trim($link);
+ $text .= "\n".$data["url"];
- return(trim($text));
+ return $text.$data["after"];
}
-
function bb_cleanstyle($st) {
return "".$st[2]."";
}
@@ -266,25 +152,33 @@ 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);
+ if (!is_object($o))
+ return $match[0];
+
if (isset($match[2]))
$o->title = $match[2];
if ($o->type=="error") return $match[0];
$html = oembed_format_object($o);
- return $html; //oembed_iframe($html,$o->width,$o->height);
+ return $html;
}
@@ -446,7 +340,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++;
}
@@ -509,8 +403,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]);
@@ -525,19 +434,21 @@ function bb_ShareAttributes($share, $simplehtml) {
$text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid_compact.":
".$share[3];
break;
case 3: // Diaspora
- $headline = '";
+ $headline .= ''.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').$userid.':
';
$text = trim($share[1]);
if ($text != "")
$text .= "
";
- $text .= $headline.''.trim($share[3])."
";
+ if (substr(normalise_link($link), 0, 19) != "http://twitter.com/") {
+ $text .= $headline.''.trim($share[3])."
";
+
+ if ($link != "")
+ $text .= '
[l]';
+ } else
+ $text .= '
'.$link.'';
- if ($link != "")
- $text .= '
[l]';
break;
case 4:
$headline = '