All Projects â†’ mewebstudio â†’ Purifier

mewebstudio / Purifier

Licence: mit
HTMLPurifier for Laravel 5/6/7/8

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Purifier

Larasupport
📦 Adds Laravel Packages Support to Lumen and Vendor Publish Artisan Command.
Stars: ✭ 104 (-93.23%)
Mutual labels:  laravel
Laravel Amp
Package that helps you set up AMP (Accelerated Mobile Pages) using Laravel
Stars: ✭ 106 (-93.1%)
Mutual labels:  laravel
Vue Laravel Spa
Single Page Application made with Vue.JS2, Vue Router, Vuex and Laravel 5.6.
Stars: ✭ 107 (-93.04%)
Mutual labels:  laravel
Ardent
Self-validating, secure and smart models for Laravel's Eloquent ORM
Stars: ✭ 1,412 (-8.13%)
Mutual labels:  laravel
No Captcha
No CAPTCHA reCAPTCHA For Laravel.
Stars: ✭ 1,484 (-3.45%)
Mutual labels:  laravel
Laravel Deployer
🚀 Zero-downtime deployment out-of-the-box
Stars: ✭ 1,536 (-0.07%)
Mutual labels:  laravel
Laravel Dashboard Chart Tile
Create all the charts you want for your laravel dashboard
Stars: ✭ 102 (-93.36%)
Mutual labels:  laravel
Docs.spatie.be Old
Code of docs.spatie.be
Stars: ✭ 107 (-93.04%)
Mutual labels:  laravel
Cloudbookmark
云书签
Stars: ✭ 106 (-93.1%)
Mutual labels:  laravel
Laravel Enum
Elegant Enum implementation for Laravel
Stars: ✭ 107 (-93.04%)
Mutual labels:  laravel
Laravel Like Comment
Ajax based site wide like and commenting system for laravel.
Stars: ✭ 105 (-93.17%)
Mutual labels:  laravel
Dendrogram
php系统树图扩展组件
Stars: ✭ 106 (-93.1%)
Mutual labels:  laravel
Laravel Settings
Store key value pair in database as settings
Stars: ✭ 107 (-93.04%)
Mutual labels:  laravel
Collect
A Collections-only split from Laravel's Illuminate Support
Stars: ✭ 1,433 (-6.77%)
Mutual labels:  laravel
Invoice As A Service
💰 Simple invoicing service (REST API): from JSON to PDF
Stars: ✭ 106 (-93.1%)
Mutual labels:  laravel
Laravel Factory Prefill
Prefills factories with faker method suggestions to increase productivity
Stars: ✭ 104 (-93.23%)
Mutual labels:  laravel
Openlaravel
A collection of open source projects built using Laravel.
Stars: ✭ 106 (-93.1%)
Mutual labels:  laravel
Llum
Llum (light in catalan language) illuminates your Laravel projects speeding up your Github/Laravel development workflow
Stars: ✭ 107 (-93.04%)
Mutual labels:  laravel
Laravel Cacheable
Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.
Stars: ✭ 107 (-93.04%)
Mutual labels:  laravel
Laravel Tenancy Passport Demo
Laravel demo with Passport and Tenancy
Stars: ✭ 107 (-93.04%)
Mutual labels:  laravel

HTMLPurifier for Laravel 5/6/7/8

Build Status codecov Latest Stable Version Latest Unstable Version License Total Downloads

A simple Laravel service provider for easily using HTMLPurifier inside Laravel. From their website:

HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications. Tired of using BBCode due to the current landscape of deficient or insecure HTML filters? Have a WYSIWYG editor but never been able to use it? Looking for high-quality, standards-compliant, open-source components for that application you're building? HTML Purifier is for you!

Installation

For Laravel 5.5+

Require this package with composer:

composer require mews/purifier

The service provider will be auto-discovered. You do not need to add the provider anywhere.

For Laravel 5.0 to 5.4

Require this package with composer:

composer require mews/purifier

Find the providers key in config/app.php and register the HTMLPurifier Service Provider.

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

Find the aliases key in config/app.php and register the Purifier alias.

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

For Laravel 4

Check out HTMLPurifier for Laravel 4

Usage

Use these methods inside your requests or middleware, wherever you need the HTML cleaned up:

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

use URI filter

Purifier::clean('This is my H1 title', 'titles', function (HTMLPurifier_Config $config) {
    $uri = $config->getDefinition('URI');
    $uri->addFilter(new HTMLPurifier_URIFilter_NameOfFilter(), $config);
});

Alternatively, in Laravel 7+, if you're looking to clean your HTML inside your Eloquent models, you can use our custom casts:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mews\Purifier\Casts\CleanHtml;
use Mews\Purifier\Casts\CleanHtmlInput;
use Mews\Purifier\Casts\CleanHtmlOutput;

class Monster extends Model
{
    protected $casts = [
        'bio'            => CleanHtml::class, // cleans both when getting and setting the value
        'description'    => CleanHtmlInput::class, // cleans when setting the value
        'history'        => CleanHtmlOutput::class, // cleans when getting the value
    ];
}

Configuration

To use your own settings, publish config.

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

Config file config/purifier.php should like this

return [
    'encoding'           => 'UTF-8',
    'finalize'           => true,
    'ignoreNonStrings'   => false,
    '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'],
        ],
    ],

];

Change log

Please see the Github Releases Tab for more information on what has changed recently.

Security

If you discover any security related issues, please email the author instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

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].