DEDECMS 5.7 维护关键词内链不生效的临时解决办法

修改文件:/include/arc.archives.class.php

找到大约1230行:

        // 这里可能会有错误
        if (version_compare(PHP_VERSION, '5.5.0', '>='))
        {
            print_r($kaarr);
            $body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
        } else {
            $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
        }

替换成:

if (version_compare(PHP_VERSION, '5.5.0', '>='))
{
    global $cfg_replace_num;
    //$body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
    if($cfg_replace_num > 0)
    {
        $query = "SELECT * FROM #@__keywords WHERE rpurl<>'' ORDER BY rank DESC";
        $this->dsql->SetQuery($query);
        $this->dsql->Execute();
        while($row = $this->dsql->GetArray())
        {
            $key = trim($row['keyword']);
            $key_url=trim($row['rpurl']);
            $body = str_replace_limit($key, "<a href='$key_url' target='_blank'><u>$key</u></a>", $body, $cfg_replace_num);
        }

    }
    else
    {
        $query = "SELECT * FROM #@__keywords WHERE rpurl<>'' ORDER BY rank DESC";
        $this->dsql->SetQuery($query);
        $this->dsql->Execute();
        while($row = $this->dsql->GetArray())
        {
            $key = trim($row['keyword']);
            $key_url=trim($row['rpurl']);
            $body = str_replace($key, "<a href='$key_url' target='_blank'><u>$key</u></a>", $body);
        }
    }

} else {
    $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
}

接着查找:

//高亮专用, 替换多次是可能不能达到最多次
function _highlight($string, $words, $result, $pre)

在其上面增加

//指定替换次数功能
function str_replace_limit($search, $replace, $subject, $limit){
    if(is_array($search)){
        foreach($search as $k=>$v){
            $search[$k] = '`'. preg_quote($search[$k], '`'). '`';
        }
    }else{
        $search = '`'. preg_quote($search, '`'). '`';
    }
    return preg_replace($search, $replace, $subject, $limit);
}

OK,DEDE后台系统设置——性能设置——使用关键词关连文章——选择是

原创文章,作者:管理员,如若转载,请注明出处:https://www.bajiege.com/soft/dedecms/dedecms-5-7-%e7%bb%b4%e6%8a%a4%e5%85%b3%e9%94%ae%e8%af%8d%e5%86%85%e9%93%be%e4%b8%8d%e7%94%9f%e6%95%88%e7%9a%84%e4%b8%b4%e6%97%b6%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95.html

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据