0 0 0

织梦限制每篇文章只显示三个关键词内链

admin
2024-08-28 16:47:14 132

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

修改 function ReplaceKeyword($kw,&$body)方法:

function ReplaceKeyword($kw,&$body)
{
global $cfg_cmspath;
$maxkey = 2;
$kws = explode(",",trim($kw));    //以分好为间隔符
$karr = $kaarr = $GLOBALS['replaced'] = array();
$i=0;
//暂时屏蔽超链接
$body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
/*
foreach($kws as $k)
{
$k = trim($k);
if($k!="")
{
if($i > $maxkey)
{
break;
}
$myrow = $this->dsql->GetOne("SELECT * FROM dede_keywords WHERE keyword='$k' AND rpurl<>'' ");
if(is_array($myrow))
{
$karr[] = $k;
$GLOBALS['replaced'][$k] = 0;
$kaarr[] = "<a href='{$myrow['rpurl']}'><u>$k</u></a>";
}
$i++;
}
}
*/
$query = "SELECT * FROM dede_keywords WHERE rpurl<>'' ORDER BY length(keyword) DESC";
$this->dsql->SetQuery($query);
$this->dsql->Execute();
$j = 0;
while($row = $this->dsql->GetArray())
{
$action = 1;
if($j >= $maxkey) break;
$key = trim($row['keyword']);
$key_url = trim($row['rpurl']);
if(count(explode($key,$body)) > 1 || count(explode($body,$key)) > 1) {
$p = 0;
if(empty($karr)){
$karr[] = $key;
$kaarr[] = "<a href='$key_url' target='_blank'><u>$key</u></a>";
$j++;
}else{
foreach($karr as $k => $v){
$p++;
if(count(explode($key,$v)) > 1 || count(explode($v,$key)) > 1){
$action = 0;
break;
}
}
if($p == count($karr) && $action){
$karr[] = $key;
$kaarr[] = "<a href='$key_url' target='_blank'><u>$key</u></a>";
$j++;
}
}
}
}
/* while($row = $this->dsql->GetArray())
{
$key = trim($row['keyword']);
$rul=trim($row['rpurl']);
$karr[] = $key;
$kaarr[] = "<a class='title-prefix' href='$rul' target='_blank'><u>$key</u></a>";
//if($i > 2){break;}
} */
// 这里可能会有错误
if (version_compare(PHP_VERSION, '5.5.0', '>='))
{
$body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
} else {
$body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
}
//恢复超链接
$body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
return $body;
}
}//End Archives


最新回复 (0)

    暂无评论

请先登录后发表评论!

返回
请先登录后发表评论!