Discuz帖子内容中的外部链接加上rel=nofollow [DZX3/X2]

帖子中可能会有很多用户加上外部链接,可以加上nofollow来降低导出权重。
只保留本站域名的链接。

即,链接中本站域名出现在最开始的位置,认定为合法的内部链接。

修改文件 source/function/function_discuzcode.php
[php]
function parseurl($url, $text, $scheme) {
global $_G;
if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"’]+/i", trim($text), $matches)) {
$url = $matches[0];
$length = 65;
if(strlen($url) > $length) {
$text = substr($url, 0, intval($length * 0.5)).’ … ‘.substr($url, – intval($length * 0.3));
}
$nofllow = strpos($url, $_G[‘siteurl’]) !== 0 ? ‘" rel="nofollow’ : ”;
return ‘<a href="’.(substr(strtolower($url), 0, 4) == ‘www.’ ? ‘http://’.$url : $url) . $nofllow .’" target="_blank">’.$text.'</a>’;
} else {
$url = substr($url, 1);
if(substr(strtolower($url), 0, 4) == ‘www.’) {
$url = ‘http://’.$url;
}
$url = !$scheme ? $_G[‘siteurl’].$url : $url;
$nofllow = strpos($url, $_G[‘siteurl’]) !== 0 ? ‘" rel="nofollow’ : ”;
return ‘<a href="’.$url . $nofllow .’" target="_blank">’.$text.'</a>’;
}
}
[/php]

发表评论