编程语言
首页 > 编程语言> > php-在Zend_Loader中包含HTMLpurifier

php-在Zend_Loader中包含HTMLpurifier

作者:互联网

我想将HTMLpurifier与Zend Framework结合使用.我想用Zend_Loader加载Class及其文件.您将如何包含它?您只使用HTMLPurifier.auto.php还是知道一种更好的方法?

解决方法:

我在Zend Framework项目中将HTML Purifier用作过滤器.这是我班的改版:

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);
    }
}

标签:htmlpurifier,zend-framework,php
来源: https://codeday.me/bug/20191024/1921420.html