From 2002fc8a2a1a1349fe5d06b2b5d6c33c51779840 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 8 May 2017 12:18:30 +0000 Subject: [PATCH] Better design for links in Mastodon posts --- include/bbcode.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/bbcode.php b/include/bbcode.php index d891f23dae..8969b35e11 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -170,6 +170,36 @@ function cleancss($input) { return $cleaned; } +function bb_style_url($match) { + $url = $match[1]; + + $parts = parse_url($url); + if (!isset($parts['scheme'])) { + return $url; + } + + $styled_url = $url; + + $scheme = $parts['scheme'].'://'; + $styled_url = str_replace($scheme, '', $styled_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); + } +} + + function stripcode_br_cb($s) { return '[code]' . str_replace('
', '', $s[1]) . '[/code]'; } @@ -956,6 +986,10 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa $Text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text); + if ($simplehtml == 7) { + $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text); + } + $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '$2', $Text);