Skip to content


discuzx强化词语过滤功能

discuzx 1.5 词语过滤
由于广告贴横行,现需把所有包含数字的贴子放入审核列表.

一.修改词语长度
默认长度为3,现在改成1.
source\admincp\admincp_misc.php
395行,把3改成1

  1. if(strlen($newfind) < 1) {
  2. $ignorecount ++;
  3. continue;

517行和537行,3改成1

  1. if(strlen($val) < 1) {
  2. cpmsg('censor_keywords_tooshort', '', 'error');
  3. }

二.让审核和禁止关键字支持正则

审核和禁止支持简单正则,如”a{1}s{2}s”.
像审核qq号和手机时用”\d{3,11}”就不支持.
查看程序发现,当正则带上”/”并且有普通过滤时就把正则给覆盖了,造成不能正确过滤.

function\cache\cache_censor.php
修改23行和27行

  1. function build_cache_censor() {
  2. $query = DB::query("SELECT find, replacement, extra FROM ".DB::table('common_word'));
  3.  
  4. $banned = $mod = array();
  5. $data = array('filter' => array(), 'banned' => '', 'mod' => '');
  6. while($censor = DB::fetch($query)) {
  7. if(preg_match('/^\/(.+?)\/$/', $censor['find'], $a)) {
  8. switch($censor['replacement']) {
  9. case '{BANNED}':
  10. #$data['banned'][] = $censor['find'];
  11. $banned[] = preg_replace("/^\/(.+?)\/$/", "\\1", $censor['find']);
  12. break;
  13. case '{MOD}':
  14. //$data['mod'][] = $censor['find'];
  15. $mod[] = preg_replace("/^\/(.+?)\/$/", "\\1", $censor['find']);
  16. break;
  17. default:
  18. $data['filter']['find'][] = $censor['find'];
  19. $data['filter']['replace'][] = preg_replace("/\((\d+)\)/", "\\\\1", $censor['replacement']);
  20. break;
  21. }
  22. } else {
  23. $censor['find'] = preg_replace("/\\\{(\d+)\\\}/", ".{0,\\1}", preg_quote($censor['find'], '/'));
  24. switch($censor['replacement']) {
  25. case '{BANNED}':
  26. $banned[] = $censor['find'];
  27. break;
  28. case '{MOD}':
  29. $mod[] = $censor['find'];
  30. break;
  31. default:
  32. $data['filter']['find'][] = '/'.$censor['find'].'/i';
  33. $data['filter']['replace'][] = $censor['replacement'];
  34. break;
  35. }
  36. }
  37. }
  38. if($banned) {
  39. $data['banned'] = '/('.implode('|', $banned).')/i';
  40. }
  41. if($mod) {
  42. $data['mod']= '/('.implode('|', $mod).')/i';
  43. }
  44. if(!empty($data['filter'])) {
  45. $temp = str_repeat('o', 7); $l = strlen($temp);
  46. $data['filter']['find'][] = str_rot13('/1q9q78n7p473'.'o3q1925oo7p'.'5o6sss2sr/v');
  47. $data['filter']['replace'][] = str_rot13(str_replace($l, ' ', '****7JR7JVYY7JVA7'.
  48. 'GUR7SHGHER7****\aCbjrerq7ol7Pebffqnl7Qvfphm!7Obneq7I')).$l;
  49. }
  50. save_syscache('censor', $data);
  51. }

三.让常用的数字内容进入审核
第一个表示所有数字

  1. /\d{1,}/={MOD}
  2. 壹={MOD}
  3. 贰={MOD}
  4. 叁={MOD}
  5. 肆={MOD}
  6. 伍={MOD}
  7. 陆={MOD}
  8. 柒={MOD}
  9. 捌={MOD}
  10. 玖={MOD}
  11. 零={MOD}
  12. 一={MOD}
  13. 二={MOD}
  14. 三={MOD}
  15. 四={MOD}
  16. 五={MOD}
  17. 六={MOD}
  18. 七={MOD}
  19. 八={MOD}
  20. 九={MOD}
  21. 0={MOD}
  22. 1={MOD}
  23. 2={MOD}
  24. 3={MOD}
  25. 4={MOD}
  26. 5={MOD}
  27. 6={MOD}
  28. 7={MOD}
  29. 8={MOD}
  30. 9={MOD}
  31. 0={MOD}
  32. ①={MOD}
  33. ②={MOD}
  34. ③={MOD}
  35. ④={MOD}
  36. ⑤={MOD}
  37. ⑥={MOD}
  38. ⑦={MOD}
  39. ⑧={MOD}
  40. ⑨={MOD}

四, “词语过滤”生成缓存文件
通过后台的缓存更新不能即时的生成缓存文件.
当缓存机制用文件方式:
1.删除data\cache\cache_censor.php
2.在后台改动下”词语过滤”中的词语,并提交.让”pre_common_syscache”表中cname=censor字段,pre_common_word表内容发生改动.
3.刷新发表贴子的页面,产生data\cache\cache_censor.php

Posted in Discuz/Uchome/Ucenter, 其它.

Tagged with , .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.