Enable HTMLpurifier with Zend_Loader

I want to use HTMLpurifier in conjunction with the Zend Framework. I would like to download the class and its files using Zend_Loader. How would you turn it on? Would you just use HTMLPurifier.auto.php or know how best to do this?

+3
source share
4 answers

I am using HTML Purifier as a filter in my Zend Framework project. Here's a modified 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);
    }
}
+6
source

If I do not understand the question (or HTMLpurifier). If you have Zend_Loader running and it is configured to autoload.

require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();

- . HTMLpurifier . .

, , , .

// SITE/library/Zend/Auth.php
class Zend_Auth
{
}

// SITE/library/htmlpurifier.php
class htmlpurifier
{
}

// SITE/library/misc/htmlpurifier.php
class Misc_HTMLpurifier
{
}

?

0

, Zend_Loader. registerAutoLoad() - , Zend_Loader . :

Zend_Loader::registerAutoLoad();

//: Zend_Loader:: registerAutoLoad ('Zend_Loader'), true);

Zend_Loader Zend Framework, :

  • , .

, "Zend_Loader" - , "Loader.php" "Zend" . PHP Zend/Loader.php

, . . Zend_Loader , . Zend_Loader. :

Zend_Loader::registerAutoLoad('myLoader',true);
0

HTMLPurifier . :

library/
  HTMLPurifier\
  HTMLPurifier.auto.php
  ...
  HTMLPurifier.safe-includes.php

And then I put this on top of the file, where I use HTMLPurifier:

require_once 'HTMLPurifier.safe-includes.php';

Ugly, but it works.

0
source

Source: https://habr.com/ru/post/1704776/


All Articles