2017 © Pedro Peláez
 

library purifier

HTMLPurifier package for Laravel 5

image

chromabits/purifier

HTMLPurifier package for Laravel 5

  • Thursday, August 20, 2015
  • by etcinit
  • Repository
  • 3 Watchers
  • 13 Stars
  • 16,810 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 106 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

Purifier Build Status

A HTMLPurifier service for Laravel 5, (*1)

Installation

Note: This package is for Laravel 5 only. It does not include a Facade and it requires certain "Contracts" interfaces only available in Laravel 5., (*2)

This package can be installed via Composer by requiring the chromabits/purifier package in your project's composer.json:, (*3)

{
    "require": {
        "laravel/framework": "~5.0",
        "chromabits/purifier": "~2.1"
    }
}

Update your packages with composer update or install with composer install., (*4)

Usage

To use the HTMLPurifier service, you must register the service provider when bootstrapping your Laravel application., (*5)

Find the providers key in config/app.php and register the HTMLPurifier Service Provider:, (*6)

    'providers' => [
        // ...
        'Chromabits\Purifier\PurifierServiceProvider',
    ]

After registering the provider, classes requiring the Chromabits\Purifier\Contracts\Purifier contract will get the purifier service instance through dependency injection (See below for examples)., (*7)

Configuration

To use your own settings, copy the config/purifier.php file in this package into your application's config directory, and modify as needed., (*8)

You can define mutiple sets of configurations by sspecifying new entries in the settings array key:, (*9)

return [
    "settings" => [
        "default" => [
            "HTML.SafeIframe" => 'true',
            "URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
        ],
        "titles" => [
            'AutoFormat.AutoParagraph' => false,
            'AutoFormat.Linkify' => false,
        ]
    ],
];

The service will use the default key as the default set of configuration, any other configuration will extend this. If a configuraiton file is not provided, the service will use safe defaults., (*10)

Example

Full usage example with default settings within a Laravel 5 controller:, (*11)

<?php

namespace Http\Controllers;

use Chromabits\Purifier\Contracts\Purifier;
use HTMLPurifier_Config;
use Illuminate\Http\Request;

/**
 * Class IndexController
 *
 * @package App\Http\Controllers;
 */
class IndexController {
    /**
     * @var Purifier
     */
    protected $purifier;

    /**
     * Construct an instance of MyClass
     *
     * @param Purifier $purifier
     */
    public function __construct(Purifier $purifier) {
        // Inject dependencies
        $this->purifier = $purifier;
    }

    /**
     * Get index page
     *
     * @param Request $request
     */
    public function getIndex(Request $request)
    {
        return $this->purifier->clean($request->input('first_name'));
    }
}

With dynamic configuration:, (*12)

    // Using config entries from purifier.php
    $this->purifier->clean('This is my H1 title', 'titles');

    // Passing configuration from an array (inherits default config)
    $this->purifier->clean(
        'This is my H1 title',
        [ 'Attr.EnableID' => true ]
    );

Interacting with the HTMLPurifier_Config object directly using a custom service provider and Closure:, (*13)

<?php

namespace App\Providers;

use Chromabits\Purifier\Purifier;
use Illuminate\Support\ServiceProvider;

/**
 * ...
 */
class CustomPurifierServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        // Bind contract with concrete implementation
        $this->app->bind(
            'Chromabits\Purifier\Contracts\Purifier',
            function ($app) {
                new Purifier($app, $app['config'], function (HTMLPurifier_Config $config) {
                        // Do stuff with $config here
                        return $config;
                }
            }
        );
    }
}

License

Based on the Laravel 4 Purifier service, (*14)

See LICENSE.md for license information, (*15)

The Versions

20/08 2015

dev-master

9999999-dev http://github.com/etcinit/purifier

HTMLPurifier package for Laravel 5

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Eduardo Trujillo

laravel laravel 5 l5 purifier htmlpurifier

24/02 2015

2.1.1

2.1.1.0 http://github.com/etcinit/purifier

HTMLPurifier package for Laravel 5

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Eduardo Trujillo

laravel laravel 5 l5 purifier htmlpurifier

24/02 2015

2.1.0

2.1.0.0 http://github.com/etcinit/purifier

HTMLPurifier package for Laravel 5

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Eduardo Trujillo

laravel laravel 5 l5 purifier htmlpurifier

24/02 2015

2.0.2

2.0.2.0 http://github.com/etcinit/purifier

HTMLPurifier package for Laravel 5

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Eduardo Trujillo

laravel laravel 5 l5 purifier htmlpurifier

14/12 2014

2.0.1

2.0.1.0 http://github.com/eduard44/purifier

HTMLPurifier package for Laravel 5

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Eduardo Trujillo

laravel laravel 5 l5 purifier htmlpurifier

13/12 2014

2.0.0

2.0.0.0 http://github.com/eduard44/purifier

HTMLPurifier package for Laravel 5

  Sources   Download

LGPL

The Requires

 

The Development Requires

by Eduardo Trujillo

laravel laravel 5 l5 purifier htmlpurifier

25/01 2014

1.0.1

1.0.1.0 http://github.com/mewebstudio/Purifier

HTMLPurifier Package for Laravel 4

  Sources   Download

LGPL

The Requires

 

laravel laravel 4 purifier l4 htmlpurifier