Better design for links in Mastodon posts
This commit is contained in:
parent
077941a116
commit
2002fc8a2a
|
@ -170,6 +170,36 @@ function cleancss($input) {
|
||||||
return $cleaned;
|
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 = '<a href="%s" rel="nofollow noopener" target="_blank">'.
|
||||||
|
'<span class="invisible">%s</span>';
|
||||||
|
|
||||||
|
if (strlen($styled_url) > 30) {
|
||||||
|
$html .= '<span class="ellipsis">%s</span>'.
|
||||||
|
'<span class="invisible">%s</span></a>';
|
||||||
|
|
||||||
|
$ellipsis = substr($styled_url, 0, 30);
|
||||||
|
$rest = substr($styled_url, 30);
|
||||||
|
return sprintf($html, $url, $scheme, $ellipsis, $rest);
|
||||||
|
} else {
|
||||||
|
$html .= '%s</a>';
|
||||||
|
return sprintf($html, $url, $scheme, $styled_url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function stripcode_br_cb($s) {
|
function stripcode_br_cb($s) {
|
||||||
return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]';
|
return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]';
|
||||||
}
|
}
|
||||||
|
@ -956,6 +986,10 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
|
||||||
$Text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
|
$Text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
|
||||||
'$1<a href="$2" class="tag" title="$3">$3</a>', $Text);
|
'$1<a href="$2" class="tag" title="$3">$3</a>', $Text);
|
||||||
|
|
||||||
|
if ($simplehtml == 7) {
|
||||||
|
$Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text);
|
||||||
|
}
|
||||||
|
|
||||||
$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$1</a>', $Text);
|
$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$1</a>', $Text);
|
||||||
$Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
|
$Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
|
||||||
//$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
|
//$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
|
||||||
|
|
Loading…
Reference in a new issue