mirror of
https://github.com/friendica/friendica
synced 2025-05-05 17:04:11 +02:00
Configurable maximum link length
This commit is contained in:
parent
ca5f93a4d5
commit
ecc4f73007
3 changed files with 21 additions and 10 deletions
|
@ -565,10 +565,11 @@ class Strings
|
|||
/**
|
||||
* Converts an URL in a nicer format (without the scheme and possibly shortened)
|
||||
*
|
||||
* @param string $url URL that is about to be reformatted
|
||||
* @param string $url URL that is about to be reformatted
|
||||
* @param int $max_length Maximum length of an url before it is shortened
|
||||
* @return string reformatted link
|
||||
*/
|
||||
public static function getStyledURL(string $url): string
|
||||
public static function getStyledURL(string $url, int $max_length = 30): string
|
||||
{
|
||||
$parts = parse_url($url);
|
||||
if (empty($parts['scheme'])) {
|
||||
|
@ -578,8 +579,8 @@ class Strings
|
|||
$scheme = [$parts['scheme'] . '://www.', $parts['scheme'] . '://'];
|
||||
$styled_url = str_replace($scheme, '', $url);
|
||||
|
||||
if (strlen($styled_url) > 30) {
|
||||
$styled_url = substr($styled_url, 0, 30) . "…";
|
||||
if (!empty($max_length) && strlen($styled_url) > $max_length) {
|
||||
$styled_url = substr($styled_url, 0, $max_length) . "…";
|
||||
}
|
||||
|
||||
return $styled_url;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue