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

Files

Latest commit

af6ac5f · Jan 17, 2021

History

History
59 lines (41 loc) · 1.24 KB

Usage.md

File metadata and controls

59 lines (41 loc) · 1.24 KB

Usage

The Behavior

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'
        ]
    ]
);

The Helper

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');

The Shell

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

The Trait

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.