• 實(shí)現(xiàn)教程
后臺(tái)-系統(tǒng)-核心設(shè)置-關(guān)鍵字替換,選擇【是】
1
后臺(tái)-系統(tǒng)-其他選項(xiàng)-關(guān)鍵詞替換次數(shù),填【1】或者【0】
1:表示文檔內(nèi)容里有多個(gè)關(guān)鍵詞,只讓1個(gè)是內(nèi)鏈
0:表示文檔內(nèi)容里有多個(gè)關(guān)鍵詞,都是內(nèi)鏈
根據(jù)自己的需要填
2
打開(kāi)/include/arc.archives.class.php文件
找到(大概在1187行至1241行)
function ReplaceKeyword($kw,&$body)
{
...中間代碼省略
}
改成
function ReplaceKeyword($kw,&$body)
{
global $cfg_replace_num;
//如果當(dāng)前文檔沒(méi)有tag直接不內(nèi)鏈,需要匹配所有tag的話(huà),刪除下面行
if(GetTags($this->Fields['aid']) == '') return $body;
$search = "/(alt\s*=\s*|title\s*=\s*|src\s*=\s*)[\"|\'](.+?)[\"|\']/is";
$body = preg_replace_callback($search, array('Archives', '_base64_encode'), $body);
$addsql = '';
$this->dsql->SetQuery("SELECT tid FROM `58pic_taglist` WHERE aid = '{$this->Fields['aid']}' ");
$this->dsql->Execute();
$ids = '';
while($row = $this->dsql->GetArray())
{
$ids .= ( $ids=='' ? $row['tid'] : ','.$row['tid'] );
}
if($ids != '')
{
$addsql = " WHERE id IN($ids) ";
}
$query = "SELECT * FROM `58pic_tagindex` $addsql ORDER BY addtime DESC";
$this->dsql->SetQuery($query);
$this->dsql->Execute();
$linkdatas = array();
while($row = $this->dsql->GetArray())
{
$row['keyword'] = $row['tag'];
$row['rpurl'] = $cfg_cmsurl."/tags.php?/".urlencode($row['tag'])."/";
$linkdatas[] = $row;
}
if($linkdatas) {
$word = $replacement = array();
foreach($linkdatas as $v) {
$word0[] = "/<a[^>]*>{$v['keyword']}<\/a>/is";
$word1[] = '/'.$v['keyword'].'/is';
$word2[] = $v['keyword'];
$replacement[] = '<a href="'.$v['rpurl'].'" target="_blank">'.$v['keyword'].'</a>';
}
if($cfg_replace_num) {
$body = preg_replace($word0, $word2, $body, $cfg_replace_num);
$body = preg_replace($word1, $replacement, $body, $cfg_replace_num);
} else {
$body = str_replace($word2, $replacement, $body);
}
}
$body = preg_replace_callback($search, array('Archives', '_base64_decode'), $body);
return $body;
}
function _base64_encode($matches) {
return $matches[1]."\"".base64_encode($matches[2])."\"";
}
function _base64_decode($matches) {
return $matches[1]."\"".base64_decode($matches[2])."\"";
3
如果你的tag鏈接是偽靜態(tài)或者靜態(tài)鏈接
找到
$cfg_cmsurl."/tags.php?/".urlencode($row['tag'])."/";
改成
/include/taglib/tag.lib.php文件內(nèi)的地址一樣
4