|
| 1 | +# Configuration |
| 2 | + |
| 3 | +## Purifier Filter Configuration |
| 4 | + |
| 5 | +Important: Before you start declaring a configuration you should lookup how HTML Purifier can be configured. http://htmlpurifier.org/docs |
| 6 | + |
| 7 | +In `config/boostrap.php` you can either set the purifier config as an array or pass a native config object. |
| 8 | + |
| 9 | +The array style would look like this: |
| 10 | + |
| 11 | +```php |
| 12 | +Purifier::config('ConfigName', array( |
| 13 | + 'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img', |
| 14 | + 'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt' |
| 15 | + ) |
| 16 | +); |
| 17 | +``` |
| 18 | + |
| 19 | +The plugin will construct a HTML Purifier config from that and instantiate the purifier. |
| 20 | + |
| 21 | +A pure HTML Purifier config might look like this one: |
| 22 | + |
| 23 | +```php |
| 24 | +$config = HTMLPurifier_Config::createDefault(); |
| 25 | +$config->set('HTML.AllowedElements', 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img'); |
| 26 | +$config->set('HTML.AllowedAttributes', 'a.href, a.title, img.src, img.alt'); |
| 27 | +$config->set('HTML.AllowedAttributes', "*.style"); |
| 28 | +$config->set('CSS.AllowedProperties', 'text-decoration'); |
| 29 | +$config->set('HTML.TidyLevel', 'heavy'); |
| 30 | +$config->set('HTML.Doctype', 'XHTML 1.0 Transitional'); |
| 31 | +``` |
| 32 | + |
| 33 | +Simply assign it to a config: |
| 34 | + |
| 35 | +```php |
| 36 | +Purifier::config('ConfigName', $config); |
| 37 | +``` |
| 38 | + |
| 39 | +Now that you have a configured instance of HTML Purifier ready you can use it directly and get you an instance of the purifier |
| 40 | + |
| 41 | +```php |
| 42 | +Purifier::config('ConfigName'); |
| 43 | +``` |
| 44 | + |
| 45 | +or clean some dirty HTML directly by calling |
| 46 | + |
| 47 | +```php |
| 48 | +Purifier::clean($markup, 'ConfigName'); |
| 49 | +``` |
| 50 | + |
| 51 | +For some automatization you can also use the Behavior or Helper. |
| 52 | + |
| 53 | +## Caching ### |
| 54 | + |
| 55 | +It is recommended to change the path of the purifier libs cache to your `tmp` folder. For example: |
| 56 | + |
| 57 | +```php |
| 58 | +Purifier::config('ConfigName', array( |
| 59 | + 'Cache.SerializerPath' => ROOT . DS . 'tmp' . DS . 'purifier', |
| 60 | + ) |
| 61 | +); |
| 62 | +``` |
| 63 | + |
| 64 | +See this page as well [http://htmlpurifier.org/live/configdoc/plain.html#Cache](http://htmlpurifier.org/live/configdoc/plain.html#Cache). |
0 commit comments