Include HTMLpurifier with Zend_Loader

前端 未结 4 2101
醉梦人生
醉梦人生 2021-02-06 17:58

I want to use the HTMLpurifier in combination with the Zend Framework. I would love to load the Class and its files with the Zend_Loader. How would you include it? Would you jus

4条回答
  •  滥情空心
    2021-02-06 18:18

    I use HTML Purifier as a filter in my Zend Framework project. Here's an altered version of my class:

    require_once 'HTMLPurifier.includes.php';
    require_once 'HTMLPurifier.autoload.php';
    
    class My_Filter_HtmlPurifier implements Zend_Filter_Interface
    {
        protected $_htmlPurifier = null;
    
        public function __construct($options = null)
        {
            // set up configuration
            $config = HTMLPurifier_Config::createDefault();
            $config->set('HTML.DefinitionID', 'My Filter');
            $config->set('HTML.DefinitionRev', 1); // increment when configuration changes
            // $config->set('Cache.DefinitionImpl', null); // comment out after finalizing the config
    
            // Doctype
            $config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
    
            // configure caching
            $cachePath = APPLICATION_PATH . '/../cache/htmlpurifier';
            if (!is_dir($cachePath)) {
                mkdir($cachePath, 0755, true);
            }
            $cachePath = realpath($cachePath);
            $config->set('Cache.SerializerPath', $cachePath);
    
            if (!is_null($options)) {
                //$config = HTMLPurifier_Config::createDefault();
                foreach ($options as $option) {
                    $config->set($option[0], $option[1], $option[2]);
                }
            }
    
            $this->_htmlPurifier = new HTMLPurifier($config);
        }
    
        public function filter($value)
        {
            return $this->_htmlPurifier->purify($value);
        }
    }
    

提交回复
热议问题