X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fbbcode.php;h=a14e3ee8e9b88f9377b6d9ed02adb73b1e18e59e;hb=e4a2430967f229dd02bc97c5c66be0620b3235d8;hp=d891f23dae4c07f5c4c8091e0a2a5e898130d544;hpb=86cae070f2a048e553c545caec54be72c1c14da5;p=friendica.git
diff --git a/include/bbcode.php b/include/bbcode.php
index d891f23dae..a14e3ee8e9 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -1,6 +1,7 @@
0.9)) {
- $title2 = $data["url"];
- }
- $text = sprintf('%s
',
- $data["url"], $data["title"], $title2);
- } elseif (($simplehtml != 4) AND ($simplehtml != 0)) {
+ $text = style_url_for_mastodon($data["url"]);
+ } elseif (($simplehtml != 4) && ($simplehtml != 0)) {
$text = sprintf('%s
', $data["url"], $data["title"]);
} else {
- $text = sprintf('', $data["type"]);
+ if ($simplehtml != 4) {
+ $text = sprintf('', $data["type"]);
+ } else {
+ $span_end = '';
+ }
$bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]);
if ($tryoembed) {
@@ -82,22 +77,26 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
if (strstr(strtolower($oembed), "', trim(bbcode($data["description"])));
+ $text .= sprintf('%s
', trim(bbcode($data["description"])));
}
}
+
+ if ($simplehtml != 4) {
+ $text .= '';
+ }
}
return trim($data["text"].' '.$text.' '.$data["after"]);
}
@@ -114,25 +113,25 @@ function bb_remove_share_information($Text, $plaintext = false, $nolink = false)
$title = htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false);
$text = htmlentities($data["text"], ENT_QUOTES, 'UTF-8', false);
- if ($plaintext OR (($title != "") AND strstr($text, $title))) {
+ if ($plaintext || (($title != "") && strstr($text, $title))) {
$data["title"] = $data["url"];
- } elseif (($text != "") AND strstr($title, $text)) {
+ } elseif (($text != "") && strstr($title, $text)) {
$data["text"] = $data["title"];
$data["title"] = $data["url"];
}
- if (($data["text"] == "") AND ($data["title"] != "") AND ($data["url"] == "")) {
+ if (($data["text"] == "") && ($data["title"] != "") && ($data["url"] == "")) {
return $data["title"] . $data["after"];
}
// If the link already is included in the post, don't add it again
- if (($data["url"] != "") AND strpos($data["text"], $data["url"])) {
+ if (($data["url"] != "") && strpos($data["text"], $data["url"])) {
return $data["text"] . $data["after"];
}
$text = $data["text"];
- if (($data["url"] != "") AND ($data["title"] != "")) {
+ if (($data["url"] != "") && ($data["title"] != "")) {
$text .= "\n[url=" . $data["url"] . "]" . $data["title"] . "[/url]";
} elseif (($data["url"] != "")) {
$text .= "\n" . $data["url"];
@@ -158,7 +157,7 @@ function cleancss($input) {
for ($i = 0; $i < strlen($input); $i++) {
$char = substr($input, $i, 1);
- if (($char >= "a") and ($char <= "z")) {
+ if (($char >= "a") && ($char <= "z")) {
$cleaned .= $char;
}
@@ -170,6 +169,54 @@ function cleancss($input) {
return $cleaned;
}
+/**
+ * @brief Converts [url] BBCodes in a format that looks fine on Mastodon. (callback function)
+ * @param array $match Array with the matching values
+ * @return string reformatted link including HTML codes
+ */
+function bb_style_url($match) {
+ $url = $match[1];
+
+ if (isset($match[2]) && ($match[1] != $match[2])) {
+ return $match[0];
+ }
+
+ $parts = parse_url($url);
+ if (!isset($parts['scheme'])) {
+ return $match[0];
+ }
+
+ return style_url_for_mastodon($url);
+}
+
+/**
+ * @brief Converts [url] BBCodes in a format that looks fine on Mastodon and GNU Social.
+ * @param string $url URL that is about to be reformatted
+ * @return string reformatted link including HTML codes
+ */
+function style_url_for_mastodon($url) {
+ $styled_url = $url;
+
+ $parts = parse_url($url);
+ $scheme = $parts['scheme'].'://';
+ $styled_url = str_replace($scheme, '', $styled_url);
+
+ $html = ''.
+ '%s';
+
+ if (strlen($styled_url) > 30) {
+ $html .= '%s'.
+ '%s';
+
+ $ellipsis = substr($styled_url, 0, 30);
+ $rest = substr($styled_url, 30);
+ return sprintf($html, $url, $scheme, $ellipsis, $rest);
+ } else {
+ $html .= '%s';
+ return sprintf($html, $url, $scheme, $styled_url);
+ }
+}
+
function stripcode_br_cb($s) {
return '[code]' . str_replace('
', '', $s[1]) . '[/code]';
}
@@ -448,20 +495,20 @@ function bb_ShareAttributes($share, $simplehtml) {
$data = get_contact_details_by_url($profile);
- if (isset($data["name"]) AND ($data["name"] != "") AND isset($data["addr"]) AND ($data["addr"] != ""))
+ if (isset($data["name"]) && ($data["name"] != "") && isset($data["addr"]) && ($data["addr"] != ""))
$userid_compact = $data["name"]." (".$data["addr"].")";
else
$userid_compact = GetProfileUsername($profile,$author, true);
- if (isset($data["addr"]) AND ($data["addr"] != ""))
+ if (isset($data["addr"]) && ($data["addr"] != ""))
$userid = $data["addr"];
else
$userid = GetProfileUsername($profile,$author, false);
- if (isset($data["name"]) AND ($data["name"] != ""))
+ if (isset($data["name"]) && ($data["name"] != ""))
$author = $data["name"];
- if (isset($data["micro"]) AND ($data["micro"] != ""))
+ if (isset($data["micro"]) && ($data["micro"] != ""))
$avatar = $data["micro"];
$preshare = trim($share[1]);
@@ -494,10 +541,9 @@ function bb_ShareAttributes($share, $simplehtml) {
break;
case 4:
- $headline = '
$2", $Text); @@ -1104,7 +1162,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa // Check for [quote] text // handle nested quotes $endlessloop = 0; - while ((strpos($Text, "[/quote]") !== false) and (strpos($Text, "[quote]") !== false) and (++$endlessloop < 20)) { + while ((strpos($Text, "[/quote]") !== false) && (strpos($Text, "[quote]") !== false) && (++$endlessloop < 20)) { $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/ism", "$QuoteLayout", $Text); } @@ -1114,7 +1172,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa // handle nested quotes $endlessloop = 0; - while ((strpos($Text, "[/quote]")!== false) and (strpos($Text, "[quote=") !== false) and (++$endlessloop < 20)) { + while ((strpos($Text, "[/quote]")!== false) && (strpos($Text, "[quote=") !== false) && (++$endlessloop < 20)) { $Text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism", "
$2", $Text); @@ -1140,9 +1198,9 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa return bb_ShareAttributes($match, $simplehtml); }, $Text); - $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '
([^<]*)
(?!