1: <?php
2:
3: /**
4: * Class protector_postcommon_post_htmlpurify4everyone
5: */
6: class Protector_postcommon_post_htmlpurify4everyone extends ProtectorFilterAbstract
7: {
8: public $purifier;
9: public $method;
10:
11: public function execute()
12: {
13: // HTMLPurifier runs with PHP5 only
14: if (version_compare(PHP_VERSION, '5.0.0') < 0) {
15: die('Turn postcommon_post_htmlpurify4everyone.php off because this filter cannot run with PHP4');
16: }
17: /*
18: if ( file_exists( XOOPS_ROOT_PATH.'/class/icms.htmlpurifier.php' ) ) {
19: // use HTMLPurifier inside ImpressCMS
20: if ( ! class_exists( 'icms_HTMLPurifier' ) ) {
21: require_once ICMS_ROOT_PATH.'/class/icms.htmlpurifier.php' ;
22: }
23: // $pure =& icms_HTMLPurifier::getPurifierInstance() ;
24: // $_POST = $pure->icms_html_purifier( $_POST , 'protector' ) ;
25: $this->purifier =& icms_HTMLPurifier::getPurifierInstance() ;
26: $this->method = 'icms_html_purifier' ;
27:
28: } else {
29: */
30: // use HTMLPurifier inside Protector
31: require_once dirname(__DIR__) . '/library/HTMLPurifier.auto.php';
32: $config = HTMLPurifier_Config::createDefault();
33: $config->set('Cache', 'SerializerPath', XOOPS_VAR_PATH . '/configs/protector');
34: $config->set('Core', 'Encoding', _CHARSET);
35: //$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional');
36: $this->purifier = new HTMLPurifier($config);
37: $this->method = 'purify';
38: // }
39:
40: $_POST = $this->purify_recursive($_POST);
41: }
42:
43: /**
44: * @param $data
45: *
46: * @return array|mixed
47: */
48: public function purify_recursive($data)
49: {
50: if (is_array($data)) {
51: return array_map(array($this, 'purify_recursive'), $data);
52: } else {
53: return strlen($data) > 32 ? call_user_func(array($this->purifier, $this->method), $data) : $data;
54: }
55: }
56: }
57: