Function moved to the "Strings" class

This commit is contained in:
Michael 2023-05-26 14:26:55 +00:00
parent 332b6f21ca
commit 5966f0cc62
2 changed files with 19 additions and 20 deletions

View file

@ -508,26 +508,7 @@ class BBCode
*/ */
private static function convertUrlForActivityPub(string $url): string private static function convertUrlForActivityPub(string $url): string
{ {
return sprintf('<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>', $url, self::getStyledURL($url)); return sprintf('<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>', $url, Strings::getStyledURL($url));
}
/**
* Converts an URL in a nicer format (without the scheme and possibly shortened)
*
* @param string $url URL that is about to be reformatted
* @return string reformatted link
*/
public static function getStyledURL(string $url): string
{
$parts = parse_url($url);
$scheme = $parts['scheme'] . '://';
$styled_url = str_replace($scheme, '', $url);
if (strlen($styled_url) > 30) {
$styled_url = substr($styled_url, 0, 30) . "";
}
return $styled_url;
} }
/* /*

View file

@ -561,4 +561,22 @@ class Strings
return $shorthand; return $shorthand;
} }
/**
* Converts an URL in a nicer format (without the scheme and possibly shortened)
*
* @param string $url URL that is about to be reformatted
* @return string reformatted link
*/
public static function getStyledURL(string $url): string
{
$parts = parse_url($url);
$scheme = $parts['scheme'] . '://';
$styled_url = str_replace($scheme, '', $url);
if (strlen($styled_url) > 30) {
$styled_url = substr($styled_url, 0, 30) . "";
}
return $styled_url;
}
} }