X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fbbcode.php;h=9a43cdb305e140222650bcfdd9dd97f307da934b;hb=8abdbb799a44795bf53a558f29b495147d88c04f;hp=2a70f95e59ee4fe159d3119b25558d92c8350507;hpb=b9d8587f413d198b854ccb213521e47327088566;p=friendica.git
diff --git a/include/bbcode.php b/include/bbcode.php
index 2a70f95e59..9a43cdb305 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -1,5 +1,7 @@
0.9)) {
- $title2 = $data["url"];
- }
- $text = sprintf('%s
',
- $data["url"], $data["title"], $title2);
+ $text = style_url_for_mastodon($data["url"]);
} elseif (($simplehtml != 4) AND ($simplehtml != 0)) {
$text = sprintf('%s
', $data["url"], $data["title"]);
} else {
@@ -97,7 +88,7 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
}
}
}
- return $data["text"] . $text . $data["after"];
+ return trim($data["text"].' '.$text.' '.$data["after"]);
}
function bb_remove_share_information($Text, $plaintext = false, $nolink = false) {
@@ -168,6 +159,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]) AND ($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]';
}
@@ -940,7 +979,14 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
// 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 ($simplehtml != 7) {
if (!$forplaintext) {
- $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text);
+ if ($simplehtml != 7) {
+ $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text);
+ } else {
+ $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url]$2[/url]', $Text);
+
+ $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text);
+ $Text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text);
+ }
} else {
$Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism", " $1 ", $Text);
$Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_RemovePictureLinks', $Text);