1 function _keylinks($txt, $replacenum = '',$link_mode = 1) { 2 $keywords = $this->data['keywords']; 3 4 if($keywords) 5 { 6 $keywords = strpos(',',$keywords) === false ? explode(' ',$keywords) : explode(',',$keywords); 7 } 8 9 if($link_mode && !empty($keywords)) 10 { 11 foreach($keywords as $keyword) 12 { 13 $linkdatas[] = $keyword; 14 } 15 } else { 16 $linkdatas = getcache('keylink','commons'); 17 } 18 19 if($linkdatas) 20 { 21 $word = $replacement = array(); 22 23 foreach($linkdatas as $v) 24 { 25 if($link_mode && $keywords) 26 { 27 $word1[] = '/' . preg_quote($v, '/') . '(?!([^<]*>)|([^<]*<\/a>))/is'; 28 $word2[] = $v; 29 $replacement[] = '<a href="javascript:;" onclick="show_ajax(this)" class="keylink">'.$v.'</a>'; 30 } else { 31 $word1[] = '/' . preg_quote($v[0], '/') . '(?!([^<]*>)|([^<]*<\/a>))/is'; 32 $word2[] = $v[0]; 33 $replacement[] = '<a href="'.$v[1].'" target="_blank" class="keylink">'.$v[0].'</a>'; 34 } 35 } 36 37 if($replacenum != '') 38 { 39 $txt = preg_replace($word1, $replacement, $txt, $replacenum); 40 } else { 41 $txt = str_replace($word2, $replacement, $txt); 42 } 43 } 44 45 return $txt; 46 }