From e1a72b8f5ab3bf8024f6588279416f187f845ba5 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 16 Mar 2018 20:50:53 +0000 Subject: [PATCH 1/2] Visible URL are shortened when transmitting to OStatus --- src/Content/Text/BBCode.php | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 532397c13a..6de12167e5 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -678,7 +678,7 @@ class BBCode $return = ''; if ($simplehtml == 7) { - $return = self::convertUrlForMastodon($data["url"]); + $return = self::convertUrlForOStatus($data["url"]); } elseif (($simplehtml != 4) && ($simplehtml != 0)) { $return = sprintf('%s
', $data["url"], $data["title"]); } else { @@ -790,7 +790,7 @@ class BBCode * @param array $match Array with the matching values * @return string reformatted link including HTML codes */ - private static function convertUrlForMastodonCallback($match) + private static function convertUrlForOStatusCallback($match) { $url = $match[1]; @@ -803,34 +803,27 @@ class BBCode return $match[0]; } - return self::convertUrlForMastodon($url); + return self::convertUrlForOStatus($url); } /** - * @brief Converts [url] BBCodes in a format that looks fine on Mastodon and GNU Social. + * @brief Converts [url] BBCodes in a format that looks fine on OStatus systems. * @param string $url URL that is about to be reformatted * @return string reformatted link including HTML codes */ - private static function convertUrlForMastodon($url) + private static function convertUrlForOStatus($url) { $parts = parse_url($url); $scheme = $parts['scheme'] . '://'; $styled_url = str_replace($scheme, '', $url); - $html = '' . - ''; - if (strlen($styled_url) > 30) { - $html .= '%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); + $styled_url = substr($styled_url, 0, 30) . "…"; } + + $html = '%s'; + + return sprintf($html, $url, $styled_url); } /** @@ -1501,8 +1494,8 @@ class BBCode $autolink_regex = "/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism"; $text = preg_replace($autolink_regex, '$1[url]$2[/url]', $text); if ($simple_html == 7) { - $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForMastodonCallback', $text); - $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForMastodonCallback', $text); + $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text); + $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text); } else { $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::shortenVisibleUrlCallback', $text); $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::shortenVisibleUrlCallback', $text); From dccfc83a2d0abc019939720fbc06266e4cf102f4 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 22 Mar 2018 20:47:31 +0000 Subject: [PATCH 2/2] No display improvements for regular posts --- src/Content/Text/BBCode.php | 45 ------------------------------------- 1 file changed, 45 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index b0d3a11faf..13d4e1b055 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -826,48 +826,6 @@ class BBCode return sprintf($html, $url, $styled_url); } - /** - * @brief Shortens [url] BBCodes in a format that looks less ugly than the full address. (callback function) - * @param array $match Array with the matching values - * @return string reformatted link including HTML codes - */ - private static function shortenVisibleUrlCallback($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 self::shortenVisibleUrl($url); - } - - /** - * @brief Shortens [url] BBCodes in a format that looks less ugly than the full address. - * @param string $url URL that is about to be reformatted - * @return string reformatted link including HTML codes - */ - private static function shortenVisibleUrl($url) - { - $parts = parse_url($url); - $scheme = $parts['scheme'] . '://'; - $styled_url = str_replace($scheme, '', $url); - -// Currently deactivated, due to preview problems inside of Diaspora -// if (strlen($styled_url) > 30) { -// $styled_url = substr($styled_url, 0, 30) . "…"; -// } - - $html = '%s'; - - return sprintf($html, $url, $styled_url); - } - /* * [noparse][i]italic[/i][/noparse] turns into * [noparse][ i ]italic[ /i ][/noparse], @@ -1496,9 +1454,6 @@ class BBCode if ($simple_html == 7) { $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text); $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text); - } else { - $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::shortenVisibleUrlCallback', $text); - $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::shortenVisibleUrlCallback', $text); } } else { $text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism", " $1 ", $text);