Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Latest commit

 

History

History
71 lines (50 loc) · 2.05 KB

Configuration.md

File metadata and controls

71 lines (50 loc) · 2.05 KB

Configuration

Purifier Filter Configuration

Important: Before you start declaring a configuration you should lookup how HTML Purifier can be configured. http://htmlpurifier.org/docs

In src/Application.php add:

$this->addPlugin('Burzum/HtmlPurifier');

In config/boostrap.php you can either set the purifier config as an array or pass a native config object.

The array style would look like this:

Purifier::config('ConfigName', [
		'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img',
		'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt'
	]
);

The plugin will construct a HTML Purifier config from that and instantiate the purifier.

A pure HTML Purifier config might look like this one:

$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.AllowedElements', 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img');
$config->set('HTML.AllowedAttributes', 'a.href, a.title, img.src, img.alt');
$config->set('HTML.AllowedAttributes', "*.style");
$config->set('CSS.AllowedProperties', 'text-decoration');
$config->set('HTML.TidyLevel', 'heavy');
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');

Simply assign it to a config:

Purifier::config('ConfigName', $config);

Now that you have a configured instance of HTML Purifier ready you can use it directly and get you an instance of the purifier

Purifier::config('ConfigName');

or clean some dirty HTML directly by calling

Purifier::clean($markup, 'ConfigName');

Remember to add use Burzum\HtmlPurifier\Lib\Purifier; when ussing Purifier class

For some automatization you can also use the Behavior or Helper.

Caching

It is recommended to change the path of the purifier libs cache to your tmp folder. For example:

Purifier::config('ConfigName', [
		'Cache.SerializerPath' => ROOT . DS . 'tmp' . DS . 'purifier',
    ]
);

See this page as well http://htmlpurifier.org/live/configdoc/plain.html#Cache.