All Projects → LukeTowers → Purifier

LukeTowers / Purifier

Licence: MIT License
HTMLPurifier for Laravel 5

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Purifier

ai-cms
Free and open source Manga CMS (Deprecated!)
Stars: ✭ 35 (+6.06%)
Mutual labels:  laravel5
Laravel-Unsplash-Wrapper
A Laravel wrapper for Unsplash API's.
Stars: ✭ 21 (-36.36%)
Mutual labels:  laravel5
laravel-camelcase-json
Convert response JSON key to camelCase
Stars: ✭ 23 (-30.3%)
Mutual labels:  laravel5
laravel5-hal-json
Laravel 5 HAL+JSON API Transformer Package
Stars: ✭ 15 (-54.55%)
Mutual labels:  laravel5
demo-laravel-crud
My practice for basic CRUD of Laravel5 on Heroku.
Stars: ✭ 22 (-33.33%)
Mutual labels:  laravel5
devtube
Laravel YouTube and Online Video viewing and download interface.
Stars: ✭ 30 (-9.09%)
Mutual labels:  laravel5
laravel-browsershot
Browsershot wrapper for Laravel 5
Stars: ✭ 108 (+227.27%)
Mutual labels:  laravel5
enum-eloquent
Enum attribute casting for Eloquent models
Stars: ✭ 60 (+81.82%)
Mutual labels:  laravel5-package
laravel-google-ads
Google Adwords API for Laravel
Stars: ✭ 60 (+81.82%)
Mutual labels:  laravel5
boxshop
Laravel ecommerce platform
Stars: ✭ 78 (+136.36%)
Mutual labels:  laravel5
laravel-circuit-breaker
An implementation of the circuit breaker pattern for Laravel 5.6
Stars: ✭ 26 (-21.21%)
Mutual labels:  laravel5
teamo-ddd-example
Implementing Domain Driven Design in PHP using Laravel
Stars: ✭ 46 (+39.39%)
Mutual labels:  laravel5
diary-app
🔐An End-To-End Encrypted Diary Web App
Stars: ✭ 83 (+151.52%)
Mutual labels:  laravel5
laravel-api-example
💻 Build an API with Laravel 5
Stars: ✭ 47 (+42.42%)
Mutual labels:  laravel5
laravel-docker-k8s
Laravel using Docker and Kubernetes
Stars: ✭ 60 (+81.82%)
Mutual labels:  laravel5
Laravel-Crud-Generator
A Simple Laravel Library that allows to create crud operation with a single command
Stars: ✭ 20 (-39.39%)
Mutual labels:  laravel5
maintenance-mode
An enhanced maintenance mode for Laravel.
Stars: ✭ 117 (+254.55%)
Mutual labels:  laravel5
eloquent-mongodb-repository
Eloquent MongoDB Repository Implementation
Stars: ✭ 18 (-45.45%)
Mutual labels:  laravel5
laravel5-jsonapi-dingo
Laravel5 JSONAPI and Dingo together to build APIs fast
Stars: ✭ 29 (-12.12%)
Mutual labels:  laravel5
laravel-passport
Basic Usage of Laravel Passport Package with Laravel 5.5
Stars: ✭ 18 (-45.45%)
Mutual labels:  laravel5

HTMLPurifier for Laravel 5

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

This package can be installed via Composer by including the repository and requiring the luketowers/purifier package in your project's composer.json:

{
	"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/LukeTowers/Purifier"
        }
    ],
    "require": {
        "laravel/framework": "~5.0",
        "luketowers/purifier": "~3.0",
    }
}

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 config/app.php and register the HTMLPurifier Service Provider.

    'providers' => [
        // ...
        LukeTowers\Purifier\PurifierServiceProvider::class,
    ]

Find the aliases key in app/config/app.php.

    'aliases' => [
        // ...
        'Purifier' => LukeTowers\Purifier\Facades\Purifier::class,
    ]

Configuration

To use your own settings, publish config.

$ php artisan vendor:publish --provider="LukeTowers\Purifier\PurifierServiceProvider"

Config file config/purifier.php should like this

return [
    'encoding'      => 'UTF-8',
    'finalize'      => true,
    'cachePath'     => storage_path('app/purifier'),
    'cacheFileMode' => 0755,
    'settings'      => [
        'default' => [
            'HTML.Doctype'             => 'HTML 4.01 Transitional',
            'HTML.Allowed'             => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]',
            'CSS.AllowedProperties'    => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
            'AutoFormat.AutoParagraph' => true,
            'AutoFormat.RemoveEmpty'   => true,
        ],
        'test'    => [
            'Attr.EnableID' => 'true',
        ],
        "youtube" => [
            "HTML.SafeIframe"      => 'true',
            "URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
        ],
        'custom_definition' => [
            'id'  => 'html5-definitions',
            'rev' => 1,
            'debug' => false,
            'elements' => [
                // http://developers.whatwg.org/sections.html
                ['section', 'Block', 'Flow', 'Common'],
                ['nav',     'Block', 'Flow', 'Common'],
                ['article', 'Block', 'Flow', 'Common'],
                ['aside',   'Block', 'Flow', 'Common'],
                ['header',  'Block', 'Flow', 'Common'],
                ['footer',  'Block', 'Flow', 'Common'],
				
				// Content model actually excludes several tags, not modelled here
                ['address', 'Block', 'Flow', 'Common'],
                ['hgroup', 'Block', 'Required: h1 | h2 | h3 | h4 | h5 | h6', 'Common'],
				
				// http://developers.whatwg.org/grouping-content.html
                ['figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common'],
                ['figcaption', 'Inline', 'Flow', 'Common'],
				
				// http://developers.whatwg.org/the-video-element.html#the-video-element
                ['video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
                    'src' => 'URI',
					'type' => 'Text',
					'width' => 'Length',
					'height' => 'Length',
					'poster' => 'URI',
					'preload' => 'Enum#auto,metadata,none',
					'controls' => 'Bool',
                ]],
                ['source', 'Block', 'Flow', 'Common', [
					'src' => 'URI',
					'type' => 'Text',
                ]],

				// http://developers.whatwg.org/text-level-semantics.html
                ['s',    'Inline', 'Inline', 'Common'],
                ['var',  'Inline', 'Inline', 'Common'],
                ['sub',  'Inline', 'Inline', 'Common'],
                ['sup',  'Inline', 'Inline', 'Common'],
                ['mark', 'Inline', 'Inline', 'Common'],
                ['wbr',  'Inline', 'Empty', 'Core'],
				
				// http://developers.whatwg.org/edits.html
                ['ins', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']],
                ['del', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']],
            ],
            'attributes' => [
                ['iframe', 'allowfullscreen', 'Bool'],
                ['table', 'height', 'Text'],
                ['td', 'border', 'Text'],
                ['th', 'border', 'Text'],
                ['tr', 'width', 'Text'],
                ['tr', 'height', 'Text'],
                ['tr', 'border', 'Text'],
            ],
        ],
        'custom_attributes' => [
            ['a', 'target', 'Enum#_blank,_self,_target,_top'],
        ],
        'custom_elements' => [
            ['u', 'Inline', 'Inline', 'Common'],
        ],
    ],

];

Example

default

clean(Input::get('inputname'));

or

Purifier::clean(Input::get('inputname'));

dynamic config

clean('This is my H1 title', 'titles');
clean('This is my H1 title', array('Attr.EnableID' => true));

or

Purifier::clean('This is my H1 title', 'titles');
Purifier::clean('This is my H1 title', array('Attr.EnableID' => true));
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].