Topic: Open external link in new window
Hi.
I modified 2 functions in the file parser.php so that the external links open in a new window and not the internal links of your DNS .
Open /include/parser.php and modify the 2 fonctions:
//
// Truncate URL if longer than 55 characters (add http:// or ftp:// if missing)
//
function handle_url_tag($url, $link = '')
{
global $pun_user;
$full_url = str_replace(array(' ', '\'', '`'), array('%20', '', ''), $url);
if (strpos($url, 'www.') === 0) // If it starts with www, we add http://
$full_url = 'http://'.$full_url;
else if (strpos($url, 'ftp.') === 0) // Else if it starts with ftp, we add ftp://
$full_url = 'ftp://'.$full_url;
else if (!preg_match('#^([a-z0-9]{3,6})://#', $url, $bah)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
// Ok, not very pretty :-)
$link = ($link == '' || $link == $url) ? ((strlen($url) > 55) ? substr($url, 0 , 39).' … '.substr($url, -10) : $url) : stripslashes($link);
//return '<a href="'.$full_url.'">'.$link.'</a>';
if (stristr($url, $_SERVER["SERVER_NAME"]) === false)
{
return '<a href="'.$full_url.'" onclick="window.open(this.href); return false;">'.$link.'</a>';
}
else
{
return '<a href="'.$full_url.'">'.$link.'</a>';
}
}
and
//
// Turns an URL from the [img] tag into an <img> tag or a <a href...> tag
//
function handle_img_tag($url, $is_signature = false)
{
global $lang_common, $pun_config, $pun_user;
//$img_tag = '<a href="'.$url.'"><'.$lang_common['Image link'].'></a>';
if (stristr($url, $_SERVER["SERVER_NAME"]) === false)
{
$img_tag = '<a href="'.$url.'" onclick="window.open(this.href); return false;"><'.$lang_common['Image link'].'></a>';
}
else
{
$img_tag = '<a href="'.$url.'"><'.$lang_common['Image link'].'></a>';
}
if ($is_signature && $pun_user['show_img_sig'] != '0')
$img_tag = '<img class="sigimage" src="'.$url.'" alt="'.htmlspecialchars($url).'" />';
else if (!$is_signature && $pun_user['show_img'] != '0')
$img_tag = '<img class="postimg" src="'.$url.'" alt="'.htmlspecialchars($url).'" />';
return $img_tag;
}
test here: http://www.anges-dechus.info/punbb/viewtopic.php?id=964