1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | class Protector_postcommon_post_htmlpurify4guest extends ProtectorFilterAbstract |
7: | { |
8: | public $purifier; |
9: | public $method; |
10: | |
11: | |
12: | |
13: | |
14: | public function execute() |
15: | { |
16: | global $xoopsUser; |
17: | |
18: | |
19: | if (version_compare(PHP_VERSION, '5.0.0') < 0) { |
20: | die('Turn postcommon_post_htmlpurify4guest.php off because this filter cannot run with PHP4'); |
21: | } |
22: | |
23: | if (is_object($xoopsUser)) { |
24: | return true; |
25: | } |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | require_once dirname(__DIR__) . '/library/HTMLPurifier.auto.php'; |
41: | $config = HTMLPurifier_Config::createDefault(); |
42: | $config->set('Cache', 'SerializerPath', XOOPS_VAR_PATH . '/configs/protector'); |
43: | $config->set('Core', 'Encoding', _CHARSET); |
44: | |
45: | $this->purifier = new HTMLPurifier($config); |
46: | $this->method = 'purify'; |
47: | |
48: | |
49: | $_POST = $this->purify_recursive($_POST); |
50: | return null; |
51: | } |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | public function purify_recursive($data) |
59: | { |
60: | if (is_array($data)) { |
61: | return array_map(array($this, 'purify_recursive'), $data); |
62: | } else { |
63: | return strlen($data) > 32 ? call_user_func(array($this->purifier, $this->method), $data) : $data; |
64: | } |
65: | } |
66: | } |
67: | |