Skip to content


discuzx强化词语过滤功能

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

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

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

517行和537行,3改成1

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

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

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

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

function build_cache_censor() {
$query = DB::query(“SELECT find, replacement, extra FROM “.DB::table(‘common_word’));

$banned = $mod = array();
$data = array(‘filter’ => array(), ‘banned’ => ”, ‘mod’ => ”);
while($censor = DB::fetch($query)) {
if(preg_match(‘/^\/(.+?)\/$/’, $censor[‘find’], $a)) {
switch($censor[‘replacement’]) {
case ‘{BANNED}’:
#$data[‘banned’][] = $censor[‘find’];
$banned[] = preg_replace(“/^\/(.+?)\/$/”, “\\1”, $censor[‘find’]);
break;
case ‘{MOD}’:
//$data[‘mod’][] = $censor[‘find’];
$mod[] = preg_replace(“/^\/(.+?)\/$/”, “\\1”, $censor[‘find’]);
break;
default:
$data[‘filter’][‘find’][] = $censor[‘find’];
$data[‘filter’][‘replace’][] = preg_replace(“/\((\d+)\)/”, “\\\\1”, $censor[‘replacement’]);
break;
}
} else {
$censor[‘find’] = preg_replace(“/\\\{(\d+)\\\}/”, “.{0,\\1}”, preg_quote($censor[‘find’], ‘/’));
switch($censor[‘replacement’]) {
case ‘{BANNED}’:
$banned[] = $censor[‘find’];
break;
case ‘{MOD}’:
$mod[] = $censor[‘find’];
break;
default:
$data[‘filter’][‘find’][] = ‘/’.$censor[‘find’].’/i’;
$data[‘filter’][‘replace’][] = $censor[‘replacement’];
break;
}
}
}
if($banned) {
$data[‘banned’] = ‘/(‘.implode(‘|’, $banned).’)/i’;
}
if($mod) {
$data[‘mod’]= ‘/(‘.implode(‘|’, $mod).’)/i’;
}
if(!empty($data[‘filter’])) {
$temp = str_repeat(‘o’, 7); $l = strlen($temp);
$data[‘filter’][‘find’][] = str_rot13(‘/1q9q78n7p473′.’o3q1925oo7p’.’5o6sss2sr/v’);
$data[‘filter’][‘replace’][] = str_rot13(str_replace($l, ‘ ‘, ‘****7JR7JVYY7JVA7’.
‘GUR7SHGHER7****\aCbjrerq7ol7Pebffqnl7Qvfphm!7Obneq7I’)).$l;
}
save_syscache(‘censor’, $data);
}

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

/\d{1,}/={MOD}
壹={MOD}
贰={MOD}
叁={MOD}
肆={MOD}
伍={MOD}
陆={MOD}
柒={MOD}
捌={MOD}
玖={MOD}
零={MOD}
一={MOD}
二={MOD}
三={MOD}
四={MOD}
五={MOD}
六={MOD}
七={MOD}
八={MOD}
九={MOD}
0={MOD}
1={MOD}
2={MOD}
3={MOD}
4={MOD}
5={MOD}
6={MOD}
7={MOD}
8={MOD}
9={MOD}
0={MOD}
①={MOD}
②={MOD}
③={MOD}
④={MOD}
⑤={MOD}
⑥={MOD}
⑦={MOD}
⑧={MOD}
⑨={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.