$text = preg_replace("/\[zrl\=(.*?)\](.*?)\[\/zrl\]/ism", '[url=$1]$2[/url]', $text);
if (in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::DIASPORA, self::OSTATUS, self::MASTODON_API, self::TWITTER_API, self::ACTIVITYPUB])) {
- $text = self::shortenLinkDescription($text);
+ $text = self::shortenLinkDescription($text, $simple_html);
} else {
$text = self::unifyLinks($text);
}
);
}
- private static function shortenLinkDescription(string $text): string
+ private static function shortenLinkDescription(string $text, int $simple_html): string
{
+ if ($simple_html == self::INTERNAL) {
+ $max_length = DI::config()->get('system', 'display_link_length');
+ } else {
+ $max_length = 30;
+ }
+
$text = preg_replace_callback(
"/\[url\](.*?)\[\/url\]/ism",
- function ($match) {
- return "[url=" . self::escapeUrl($match[1]) . "]" . Strings::getStyledURL($match[1]) . "[/url]";
+ function ($match) use ($max_length) {
+ return "[url=" . self::escapeUrl($match[1]) . "]" . Strings::getStyledURL($match[1], $max_length) . "[/url]";
},
$text
);
$text = preg_replace_callback(
"/\[url\=(.*?)\](.*?)\[\/url\]/ism",
- function ($match) {
+ function ($match) use ($max_length) {
if ($match[1] == $match[2]) {
- return "[url=" . self::escapeUrl($match[1]) . "]" . Strings::getStyledURL($match[2]) . "[/url]";
+ return "[url=" . self::escapeUrl($match[1]) . "]" . Strings::getStyledURL($match[2], $max_length) . "[/url]";
} else {
return "[url=" . self::escapeUrl($match[1]) . "]" . $match[2] . "[/url]";
}
/**
* 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'])) {
$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;
// Display the first resharer as icon and text on a reshared item.
'display_resharer' => false,
+ // display_link_length (integer)
+ // Maximum length of displayed links. Default value is 30, 0 deactivates the functionality.
+ 'display_link_length' => 30,
+
// dlogfile (Path)
// location of the developer log file.
'dlogfile' => '',