Set a config you want to use and the fields you want to sanitize.
public $actsAs = array(
'Burzum/HtmlPurifier.HtmlPurifier' => [
'purifierConfig' => 'ConfigName',
'fields' => [
'body', 'excerpt'
]
]
);
In your controller load the helper and set a default config if you want.
public $helpers = array(
'Burzum/HtmlPurifier.HtmlPurifier' => array(
'config' => 'ConfigName'
)
);
In the views you can then use the helper like this:
$this->HtmlPurifier->clean($markup, 'ConfigName');
Using the shell is very easy and self-explaining:
cake purify <table> <fields>
You can specify a purifier config to use as well:
cake purify <table> <fields> --config myconfig
Where ever you need the purifier you can simply add it to your class by using the PurifierTrait.
The trait add two methods:
- purifyHtml($markup, $config = 'default'): Cleans a passed string of HTML.
- getHtmlPurifier($config = 'default'): Gets a
\HtmlPurifier
instance by config name.
See the official php documentation for traits if you don't know how to use it.