1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 
<?php
namespace Omeka\Stdlib;

class HtmlPurifier
{
    protected $config;
    protected $purifier;
    protected $useHtmlPurifier;

    public function __construct($useHtmlPurifier)
    {
        $this->useHtmlPurifier = $useHtmlPurifier;
    }

    public function purify($html)
    {
        if ($this->useHtmlPurifier) {
            $purifier = $this->getPurifier();
            $html = $purifier->purify($html);
        }
        return $html;
    }

    public function getConfig()
    {
        if ($this->config === null) {
            $this->config = \HTMLPurifier_Config::createDefault();
        }
        return $this->config;
    }

    protected function getPurifier()
    {
        if ($this->purifier === null) {
            $config = $this->getConfig();
            $config->set('Cache.DefinitionImpl', null);
            $this->purifier = new \HTMLPurifier($config);
        }
        return $this->purifier;
    }
}