我想将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); } }