A simple Laravel 4/5 service provider for including the HTMLPurifier for Laravel 4/5.
The HTMLPurifier Service Provider can be installed via Composer by requiring the
ezyang/htmlpurifier
, mews/purifier
package and setting the minimum-stability
to dev
(required for Laravel 4/5) in your
project's composer.json
.
For Laravel 4
{
"require": {
"laravel/framework": "4.0.*",
"mews/purifier": "dev-master"
},
"minimum-stability": "1.0.2"
}
For Laravel 5
{
"require": {
"laravel/framework": "4.0.*",
"mews/purifier": "dev-master"
},
"minimum-stability": "dev"
}
Update your packages with composer update
or install with composer install
.
To use the HTMLPurifier Service Provider, you must register the provider when bootstrapping your Laravel application. There are essentially two ways to do this.
Find the providers
key in app/config/app.php
and register the HTMLPurifier Service Provider.
'providers' => array(
// ...
'Mews\Purifier\PurifierServiceProvider',
)
Find the aliases
key in app/config/app.php
.
'aliases' => array(
// ...
'Purifier' => 'Mews\Purifier\Facades\Purifier',
)
To use your own settings, publish config.
$ php artisan config:publish mews/purifier
Config file app/config/packages/mews/purifier/config.php
return array(
"settings" => array(
"default" => array(
"HTML.SafeIframe" => 'true',
"URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
),
"titles" => array(
'AutoFormat.AutoParagraph' => false,
'AutoFormat.Linkify' => false,
)
),
);
default
Purifier::clean(Input::get('inputname'));
dynamic config
Purifier::clean('This is my H1 title', 'titles');
Purifier::clean('This is my H1 title', array('Attr.EnableID' => true));