cache_censor.php
2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: cache_censor.php 24379 2011-09-15 11:58:17Z zhengqingpeng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
function build_cache_censor() {
$banned = $mod = array();
$bannednum = $modnum = 0;
$data = array('filter' => array(), 'banned' => '', 'mod' => '');
foreach(C::t('common_word')->fetch_all() as $censor) {
if(preg_match('/^\/(.+?)\/$/', $censor['find'], $a)) {
switch($censor['replacement']) {
case '{BANNED}':
$data['banned'][] = $censor['find'];
break;
case '{MOD}':
$data['mod'][] = $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'];
$bannednum ++;
if($bannednum == 1000) {
$data['banned'][] = '/('.implode('|', $banned).')/i';
$banned = array();
$bannednum = 0;
}
break;
case '{MOD}':
$mod[] = $censor['find'];
$modnum ++;
if($modnum == 1000) {
$data['mod'][] = '/('.implode('|', $mod).')/i';
$mod = array();
$modnum = 0;
}
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;
}
savecache('censor', $data);
}
?>