From 8788aa450c79669ad76d0520b73433d06a606e5d Mon Sep 17 00:00:00 2001 From: rwxsu <37944358+rwxsu@users.noreply.github.com> Date: Mon, 6 Aug 2018 01:51:37 -0700 Subject: [PATCH] Prefix http or https if user hasn't explicitly set (#327) * Prefix http or https if user hasn't explicitly set Adding this because href prefixes the server's url if http:// or https:// is not provided. * Fixed whitespace --- forum.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/forum.php b/forum.php index c1748d9..772e07b 100644 --- a/forum.php +++ b/forum.php @@ -25,6 +25,7 @@ function TransformToBBCode($string) { '[img]{$1}[/img]' => '<a href="$1" target="_BLANK"><img src="$1" alt="image" style="width: 100%"></a>', '[link]{$1}[/link]' => '<a href="$1">$1</a>', '[link={$1}]{$2}[/link]' => '<a href="$1" target="_BLANK">$2</a>', + '[url={$1}]{$2}[/url]' => '<a href="$1" target="_BLANK">$2</a>', '[color={$1}]{$2}[/color]' => '<font color="$1">$2</font>', '[*]{$1}[/*]' => '<li>$1</li>', '[youtube]{$1}[/youtube]' => '<div class="youtube"><div class="aspectratio"><iframe src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe></div></div>', @@ -33,6 +34,11 @@ function TransformToBBCode($string) { foreach ($tags as $tag => $value) { $code = preg_replace('/placeholder([0-9]+)/', '(.*?)', preg_quote(preg_replace('/\{\$([0-9]+)\}/', 'placeholder$1', $tag), '/')); $string = preg_replace('/'.$code.'/i', $value, $string); + if (strpos($string, "<a href=") !== false) { + if (strpos($string, "http") === false) { + $string = substr_replace($string, "//", 9, 0); + } + } } return $string;