Skip to content

Commit

Permalink
Kunena refuse to convert relative internal URL without leading slash …
Browse files Browse the repository at this point in the history
…to a link in post message Kunena#3864
  • Loading branch information
Jelle Kok committed Apr 29, 2016
1 parent 92fcc1a commit 172256f
Showing 1 changed file with 32 additions and 41 deletions.
73 changes: 32 additions & 41 deletions src/libraries/kunena/bbcode/bbcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,30 +229,6 @@ public function parseUrl($params)
}
}

if ($config->autolink)
{
$layout = KunenaLayout::factory('BBCode/URL');

if ($layout->getPath())
{
return (string) $layout
->set('content', $text)
->set('url', $url)
->set('target', $this->url_target);
}

$url = htmlspecialchars($url, ENT_COMPAT, 'UTF-8');

if (strpos($url, '/index.php') !== 0)
{
return "<a class=\"bbcode_url\" href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$text}</a>";
}
else
{
return "<a class=\"bbcode_url\" href=\"{$url}\" target=\"_blank\">{$text}</a>";
}
}

// Auto-linking has been disabled.
return $text;
}
Expand Down Expand Up @@ -388,10 +364,30 @@ public function IsValidURL($string, $email_too = true, $local_too = false)
{
static $re = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS';

if (empty($string)) return false;
if ($local_too && $string[0] == '/') $string = 'http://www.domain.com' . $string;
if ($email_too && substr($string, 0, 7) == "mailto:") return $this->IsValidEmail(substr($string, 7));
if (preg_match($re, $string)) return true;
if (empty($string))
{
return false;
}

if ($local_too && $string[0] == '/')
{
return true;
}

if (strpos($string, 'index.php'))
{
return true;
}

if ($email_too && substr($string, 0, 7) == "mailto:")
{
return $this->IsValidEmail(substr($string, 7));
}

if (preg_match($re, $string))
{
return true;
}

return false;
}
Expand Down Expand Up @@ -1119,7 +1115,14 @@ public function DoURL($bbcode, $action, $name, $default, $params, $content)
if (!preg_match('#^(/|https?:|ftp:)#ui', $url))
{
// Add scheme to raw domain URLs.
$url = "http://{$url}";
if (!preg_match('index.php', $url))
{
$url = JUri::root() ."{$url}";
}
else
{
$url = "http://{$url}";
}
}

if (!$bbcode->IsValidURL($url, false, true))
Expand Down Expand Up @@ -1149,18 +1152,6 @@ public function DoURL($bbcode, $action, $name, $default, $params, $content)
->set('url', $url)
->set('target', $target);
}

// TODO: Remove in Kunena 4.0
$target = ' target="' . htmlspecialchars($target, ENT_COMPAT, 'UTF-8') . '"';

if (strpos($url, '/index.php') !== 0)
{
return '<a href="' . htmlspecialchars($url, ENT_COMPAT, 'UTF-8') . '" class="bbcode_url" rel="nofollow"' . $target . '>' . $content . '</a>';
}
else
{
return '<a href="' . htmlspecialchars($url, ENT_COMPAT, 'UTF-8') . '" class="bbcode_url"' . $target . '>' . $content . '</a>';
}
}

// Format a [size] tag by producing a <span> with a style with a different font-size.
Expand Down

0 comments on commit 172256f

Please sign in to comment.