Function moved to the "Strings" class
parent
332b6f21ca
commit
5966f0cc62
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue