https://github.com/mikemix/zf2htmlpurifier
HTML Purifier as ZF2 filter
https://github.com/mikemix/zf2htmlpurifier
Last synced: 8 months ago
JSON representation
HTML Purifier as ZF2 filter
- Host: GitHub
- URL: https://github.com/mikemix/zf2htmlpurifier
- Owner: mikemix
- License: mit
- Created: 2015-01-27T20:40:30.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-11-16T13:25:59.000Z (about 10 years ago)
- Last Synced: 2025-04-09T20:17:17.569Z (8 months ago)
- Language: PHP
- Size: 242 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zf2htmlpurifier
[](https://scrutinizer-ci.com/g/mikemix/zf2htmlpurifier/?branch=master) [](https://scrutinizer-ci.com/g/mikemix/zf2htmlpurifier/?branch=master) [](https://scrutinizer-ci.com/g/mikemix/zf2htmlpurifier/build-status/master)
HTML Purifier as ZF2 filter. Protect yourself from XSS attacks with two simple steps.
Install
-------
Install with [Composer](https://packagist.org/packages/mikemix/zf2htmlpurifier) ```"mikemix/zf2htmlpurifier": "~1.0"```
Use
---
Include in form field's filter chain ```zf2htmlpurifier\Filter\HTMLPurifierFilter```, for example:
```php
add([
'name' => 'field',
]);
}
public function getInputFilterSpecification()
{
return array(
// other elements
'field' => array(
'required' => true,
'filters' => array(
array('name' => 'zf2htmlpurifier\Filter\HTMLPurifierFilter'),
),
),
);
}
// or with modern php
public function getInputFilterSpecification()
{
return [
// other elements
'field' => [
'required' => true,
'filters' => [
['name' => zf2htmlpurifier\Filter\HTMLPurifierFilter::class],
],
],
];
}
}
// in controller (ugly code example without Dependency Injection)
$fm = $this->getServiceLocator()->get('FormElementManager');
$form = $fm->get(MyApp\Form\ExampleForm::class);
$form->setData(['field' => 'link']);
$form->isValid();
// outputs: link
echo $form->getData('field');
```
Fine tuning HTMLPurifier
------------------------
You can pass options to configure the HTMLPurifier library.
```php
// the form
public function getInputFilterSpecification()
{
return [
// other elements
'field' => [
'required' => true,
'filters' => [
['name' => zf2htmlpurifier\Filter\HTMLPurifierFilter::class, 'options' => ['config' => [
'Cache.SerializerPath' => '/other/path',
'Some.Setting' => 'Setting value',
]]],
],
],
];
}
```
Standalone usage
----------------
It can be used as standalone class as well:
```php
$purifier = new \zf2htmlpurifier\Filter\HTMLPurifierFilter();
echo $purifier->filter('link');
```
TODO
----
* Convert this to Module and allow defining default HTMLPurifier config via the configuration files