最终实现效果如下图:内容生成之后会自动加上本篇文章的tags标签(文档生成时候自动加入,编辑器中内容实际没加入,更有利)
function ReplaceKeyword($kw,&$body) { ...中间代码省略 } 整个改成
function ReplaceKeyword($kw,&$body){global $cfg_replace_num;$search = "/(alts*=s*|titles*=s*|srcs*=s*)["|'](.+?)["|']/is";$body = preg_replace_callback($search, array('Archives', '_base64_encode'), $body);$addsql = '';if(isset($this->Fields['tags']) && !empty($this->Fields['aid'])){$this->dsql->SetQuery("SELECT tid FROM `dede_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) ";}if($addsql=='') return $body;}$query = "SELECT * FROM `dede_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."/".urlencode($row['tag'])."/";$linkdatas[] = $row;}if($linkdatas) {$word = $replacement = array();foreach($linkdatas as $v) {$word1[] = '/(?!(<a.*?))' . preg_quote($v['keyword'], '/') . '(?!.*</a>)/s';$word2[] = $v['keyword'];$replacement[] = '<a href="'.$v['rpurl'].'" target="_blank">'.$v['keyword'].'</a>';}if($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]).""";} |