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