Skip to content

mewebstudio/Purifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTMLPurifier for Laravel 4

A simple Laravel 4 service provider for including the HTMLPurifier for Laravel 4.

Installation

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) in your project's composer.json.

{
    "require": {
        "laravel/framework": "4.0.*",
        "mews/purifier": "dev-master"
    },
    "minimum-stability": "dev"
}

Update your packages with composer update or install with composer install.

Usage

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

Configuration

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

Example

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

Links