1: <?php
2:
3: /**
4: * Class protector_postcommon_post_htmlpurify4guest
5: */
6: class Protector_postcommon_post_htmlpurify4guest extends ProtectorFilterAbstract
7: {
8: public $purifier;
9: public $method;
10:
11: /**
12: * @return bool
13: */
14: public function execute()
15: {
16: global $xoopsUser;
17:
18: // HTMLPurifier runs with PHP5 only
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: if ( file_exists( XOOPS_ROOT_PATH.'/class/icms.htmlpurifier.php' ) ) {
28: // use HTMLPurifier inside ImpressCMS
29: if ( ! class_exists( 'icms_HTMLPurifier' ) ) {
30: require_once ICMS_ROOT_PATH.'/class/icms.htmlpurifier.php' ;
31: }
32: // $pure =& icms_HTMLPurifier::getPurifierInstance() ;
33: // $_POST = $pure->icms_html_purifier( $_POST , 'protector' ) ;
34: $this->purifier =& icms_HTMLPurifier::getPurifierInstance() ;
35: $this->method = 'icms_html_purifier' ;
36:
37: } else {
38: */
39: // use HTMLPurifier inside Protector
40: require_once dirname(__DIR__) . '/library/HTMLPurifier.auto.php';
41: $config = HTMLPurifier_Config::createDefault();
42: $config->set('Cache', 'SerializerPath', XOOPS_TRUST_PATH . '/modules/protector/configs');
43: $config->set('Core', 'Encoding', _CHARSET);
44: //$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional');
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: * @param $data
55: *
56: * @return array|mixed
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: