function.seo.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. if(!defined('IN_DISCUZ')) {
  3. exit('Access Denied');
  4. }
  5. function miluseo_replace($info, $bbs = 1) {
  6. if(!$info) return;
  7. include_once libfile('function/home');
  8. $set = tool_common_get('article_seo');
  9. $key_arr = array('push_title_header','push_title_footer','push_content_header','push_content_body','push_content_footer','push_reply_header', 'push_reply_body', 'push_reply_footer');
  10. foreach($key_arr as $v){
  11. $$v = st_format_wrap($set[$v]);
  12. }
  13. $info_key = array('title', 'content', 'reply');
  14. $hide = $bbs == 1 ? 0 : 1;
  15. foreach($info_key as $v){
  16. if(!$info[$v]) continue;
  17. if($v != 'title'){//添加随机隐藏内容
  18. $rand_arr_key = 'push_'.$v.'_body';
  19. if($$rand_arr_key){
  20. $rand_arr = implode('*_*', $$rand_arr_key);
  21. $info[$v] = preg_replace("/\r\n|\n|\r/e", "miluseo_jammer('', '$rand_arr', $bbs)", $info[$v]);
  22. $info[$v] = preg_replace("/<\/p>|<\/P>/e", "miluseo_jammer('</p>', '$rand_arr', $bbs)", $info[$v]);
  23. }
  24. }
  25. $header_arr = 'push_'.$v.'_header';
  26. $header_arr = $$header_arr;
  27. $header = $header_arr[array_rand($header_arr)];
  28. $footer_arr = 'push_'.$v.'_footer';
  29. $footer_arr = $$footer_arr;
  30. $footer = $footer_arr[array_rand($footer_arr)];
  31. $info[$v] = $header.$info[$v];
  32. $info[$v] .= $footer;
  33. if($v == 'title') $info[$v] = getstr(trim($info[$v]), 80, 1, 1);
  34. }
  35. return $info;
  36. }
  37. function miluseo_jammer($flag,$rand_arr, $bbs = 1) {
  38. $rand_arr = explode('*_*', $rand_arr);
  39. $randomstr = $rand_arr[array_rand($rand_arr)];
  40. return mt_rand(0, 1) && $bbs==1 ? $flag.'<font class="jammer">'.$randomstr.'</font>'."\r\n" :
  41. $flag."\r\n".'<span style="display:none">'.$randomstr.'</span>';
  42. }
  43. function miluseo_word_replace($data, $word = ''){
  44. if(!VIP) return $data;
  45. if(!$data) return $data;
  46. $words = $words ? $words : get_seo_word_arr(2);
  47. if(!$words) return $data;
  48. if(is_array($data)){
  49. foreach($data as $k => $v){
  50. $v = strtr($v,$words);
  51. $data[$k] = $v;
  52. }
  53. }else{
  54. $data = strtr($data,$words);
  55. }
  56. return $data;
  57. }
  58. function get_seo_word_arr($text = 0){
  59. global $_G;
  60. $words = array();
  61. $data_file = SEO_WORD_FILE;
  62. $handle = fopen($data_file, "r");
  63. $data = fread($handle, filesize($data_file));
  64. $data = $old_data = trim($data);
  65. if(GBK) $data = st_str_iconv($data);
  66. if($text == 1) return $data;
  67. $word_arr = explode("\r\n", $data);
  68. if(!$word_arr){
  69. $word_arr = explode("\r\n", $old_data);
  70. }
  71. if(!$word_arr) return;
  72. if($text == 0) return $word_arr;
  73. $ext_str = get_seo_word_split();
  74. foreach((array)$word_arr as $k=>$v){
  75. if(!$k) continue;
  76. $str_arr = explode($ext_str, $v);//关键词分割符
  77. $words += array("$str_arr[0]" => "$str_arr[1]");
  78. }
  79. return $words;
  80. }
  81. function get_seo_word_split(){
  82. $format_str = stlang('format_str');
  83. $format_arr = explode('@', $format_str);
  84. $ext_str = '→';
  85. foreach((array)$format_arr as $k => $v){
  86. $v_arr = explode('|', $v);
  87. if($v_arr[0] == '&rarr;') $ext_str = $v_arr[1];
  88. }
  89. return $ext_str;
  90. }
  91. ?>