加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 教程 > 正文

Discuz! 帖子外链自动添加nofollow的技巧

发布时间:2021-11-30 18:13:24 所属栏目:教程 来源:互联网
导读:让系统自动把外链都加上nofollow属性,修改方法如下: 1. 打开目录source/function/function_discuzcode.php文件,查找parseurl函数,对照以下代码进行修改: 01 function parseurl($url, $text, $scheme) { 02 global $_G; 03 if(!$url preg_match(/((https?
  让系统自动把外链都加上nofollow属性,修改方法如下:   1. 打开目录source/function/function_discuzcode.php文件,查找parseurl函数,对照以下代码进行修改:
01
function parseurl($url, $text, $scheme) {
02
        global $_G;
03
        if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}://|www.)[^["']+/i", trim($text), $matches)) {
04
                $url = $matches[0];
05
                $length = 65;
06
                if(strlen($url) > $length) {
07
                        $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
08
                }
09
        $url = nofollow($url);
10
                return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
11
        } else {
12
                $url = substr($url, 1);
13
                if(substr(strtolower($url), 0, 4) == 'www.') {
14
                        $url = 'http://'.$url;
15
                }
16
                $url = !$scheme ? $_G['siteurl'].$url : $url;
17
                return '<a href="'.nofollow($url).'" target="_blank">'.$text.'</a>';
18
        }
19
}
复制代码   2. 在parseurl函数后面新增nofollow函数,代码如下:
01
function nofollow($url = '')
02
{
03
    $temp = array();
04
 
05
    if( ! empty($url))
06
    {
07
        $temp = parse_url($url);
08
 
09
        if(isset($temp['host']) && $temp['host'] != $_SERVER['HTTP_HOST'])
10
        {
11
            $url .= '" rel="nofollow"';
12
        }
13
    }
14
 
15
    unset($temp);
16
    return $url;
17
}
 

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读