PDA

View Full Version : Question about external links coding


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.

kh99
03-11-2012, 04:15 PM
I looked at it and can't see anything offhand, but what I usually do is print out some debug info using print_r(), maybe to a file. If you look at $allowed and $target_url I'm guessing that you'll see the problem.