无限星辰工作室-客户无限互联网动力之源
标题:
Discuz! X3.2帖子内容外链自动加nofollow解决方案之一
[打印本页]
作者:
crx349
时间:
2014-11-15 01:51
标题:
Discuz! X3.2帖子内容外链自动加nofollow解决方案之一
系统自动把外链都加上nofollow属性,修改方法如下:
1、打开目录source/function/function_discuzcode.php文件,查找parseurl函数:
搜索
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));
}
return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" 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;
return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
}
}
复制代码
修改为:
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));
}
$url = nofollow($url);
return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" 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;
return '<a href="'.nofollow($url).'" target="_blank">'.$text.'</a>';
}
}
复制代码
2.在parseurl函数后面新增nofollow函数,代码如下:
function nofollow($url = '')
{
$temp = array();
if( ! empty($url))
{
$temp = parse_url($url);
if(isset($temp['host']) && $temp['host'] != $_SERVER['HTTP_HOST'])
{
$url .= '" rel="nofollow"';
}
}
unset($temp);
return $url;
}
复制代码
欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://xmspace.net/)
Powered by Discuz! X3.4