1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > html外链自动加nofollow Discuz! 帖子外链自动添加nofollow的方法

html外链自动加nofollow Discuz! 帖子外链自动添加nofollow的方法

时间:2019-09-08 17:42:40

相关推荐

html外链自动加nofollow Discuz! 帖子外链自动添加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));

}

$url = nofollow($url);

return ''.$text.'';

} else {

$url = substr($url, 1);

if(substr(strtolower($url), 0, 4) == 'www.') {

$url = 'http://'.$url;

}

$url = !$scheme ? $_G['siteurl'].$url : $url;

return ''.$text.'';

}

}

,复制代码,,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;

}

, 让系统自动把外链都加上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));

}

$url = nofollow($url);

return ''.$text.'';

} else {

$url = substr($url, 1);

if(substr(strtolower($url), 0, 4) == 'www.') {

$url = 'http://'.$url;

}

$url = !$scheme ? $_G['siteurl'].$url : $url;

return ''.$text.'';

}

}

复制代码 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;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。