This is the patch for PunBB v1.2.20, authored by me (legolas558). It will use target="_blank" only on external URLs.
--- include/parser.php 2009-08-20 08:12:27.000000000 +0200
+++ include/parser.php 2009-08-20 08:11:07.000000000 +0200
@@ -277,7 +277,22 @@
// 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>';
+ return '<a href="'.$full_url.'"'.add_auto_target($full_url).'>'.$link.'</a>';
+}
+
+//
+// Automatically add target="_blank" for URLs not on this website
+//
+function add_auto_target($url) {
+ $p = strpos($url, '//');
+ if ($p !== false) {
+ $url = substr($url, $p+2);
+ $p = strpos($url, '/');
+ $url = substr($url, 0, $p);
+ if ($_SERVER["SERVER_NAME"] == $url)
+ return '';
+ }
+ return ' target="_blank" rel="nofollow"';
}
@@ -288,7 +303,7 @@
{
global $lang_common, $pun_config, $pun_user;
- $img_tag = '<a href="'.$url.'"><'.$lang_common['Image link'].'></a>';
+ $img_tag = '<a href="'.$url.'"'.add_auto_target($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).'" />';