Discuz帖子内容中的外部链接加上rel=nofollow
帖子中可能会有很多用户加上外部链接,可以加上nofollow来降低导出权重,只保留本站域名的链接,即链接中本站域名出现在最开始的位置,认定为合法的内部链接.
修改文件:source/function/function_discuzcode.php
- function p arseurl($url, $text, $scheme) {
- glob al $_G;
- if(!$url && preg_m atch("/((https?|ftp|gopher|news|telnet|rtsp|mms|c allto|bctp|thunder|qqdl|syn ac ast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $m atches)) {
- $url = $m atches[0];
- $length = 65;
- if(strlen($url) > $length) {
- $text = substr($url, 0, intv al($length * 0.5)).' ... '.substr($url, - intv al($length * 0.3));
- }
- $nofllow = strpos($url, $_G['siteurl']) !== 0 ? '" rel="nofollow' : '';
- return '< a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url) . $nofllow .'" t arget="_bl ank">'.$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 .'" t arget="_bl ank">'.$text.'</ a>';
- }
- }