samergains
03-11-2012, 03:37 PM
Hi everyone,
I'm trying to modify the file includes/class_bbcode.php to make the external links coded.
I added a block of code to the function called handle_bbcode_url
$coding_needed = true;
if (!isset($current_url))
{
$current_url = @parse_url($this->registry->options['bburl']);
$current_host = preg_replace('#:(\d)+$#', '', VB_HTTP_HOST);
$allowed = preg_split('#\s+#', $this->registry->options['url_nofollow_whitelist'], -1, PREG_SPLIT_NO_EMPTY);
$allowed[] = preg_replace('#^www\.#i', '', $current_host);
$allowed[] = preg_replace('#^www\.#i', '', $current_url['host']);
}
$target_url = preg_replace('#^([a-z0-9]+:(//)?)#', '', $rightlink);
if(isset($allowed))
{
foreach ($allowed AS $host)
{
if (stripos($target_url, $host) !== false)
{
if ($this->registry->options['url_nofollow']) {
$is_external = false;
}
$coding_needed = false;
}
}
}
if ($coding_needed && preg_match('~^https?://~i', $rightlink)) {
$t = $rightlink;
$rightlink = '/forum/outgoing.php?to=';
for ($i = 0; $i < strlen($t); $i ++) {
$rightlink .= dechex(ord(substr($t, $i, 1)));
}
}
it's working fine but the problem is that it's coding all the link not only the external ones. the parameter coding_needed is always true.
how can I fix that?
thanks in advance for any ideas.
I'm trying to modify the file includes/class_bbcode.php to make the external links coded.
I added a block of code to the function called handle_bbcode_url
$coding_needed = true;
if (!isset($current_url))
{
$current_url = @parse_url($this->registry->options['bburl']);
$current_host = preg_replace('#:(\d)+$#', '', VB_HTTP_HOST);
$allowed = preg_split('#\s+#', $this->registry->options['url_nofollow_whitelist'], -1, PREG_SPLIT_NO_EMPTY);
$allowed[] = preg_replace('#^www\.#i', '', $current_host);
$allowed[] = preg_replace('#^www\.#i', '', $current_url['host']);
}
$target_url = preg_replace('#^([a-z0-9]+:(//)?)#', '', $rightlink);
if(isset($allowed))
{
foreach ($allowed AS $host)
{
if (stripos($target_url, $host) !== false)
{
if ($this->registry->options['url_nofollow']) {
$is_external = false;
}
$coding_needed = false;
}
}
}
if ($coding_needed && preg_match('~^https?://~i', $rightlink)) {
$t = $rightlink;
$rightlink = '/forum/outgoing.php?to=';
for ($i = 0; $i < strlen($t); $i ++) {
$rightlink .= dechex(ord(substr($t, $i, 1)));
}
}
it's working fine but the problem is that it's coding all the link not only the external ones. the parameter coding_needed is always true.
how can I fix that?
thanks in advance for any ideas.