Download the PHP package dilneiss/purify without Composer
On this page you can find all versions of the php package dilneiss/purify. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package purify
Purify
Purify is a Laravel wrapper around HTMLPurifier by ezyang.
Requirements
- PHP >= 7.1
- Laravel >= 5.5
Installation
To install Purify, run the following in the root of your project:
Then, publish the configuration file using:
If you are using Lumen, you should copy the config file purify.php
by hand, and add this line to your bootstrap/app.php
:
Usage
Cleaning a String
To clean a users input, simply use the clean method:
Cleaning an Array
Need to purify an array of user input? Just pass in an array:
Dynamic Configuration
Need a different configuration for a single input? Pass in a configuration array into the second parameter:
Note: Configuration passed into the second parameter is not merged with your current configuration.
Replacing the HTML Purifier instance
Need to replace the HTML Purifier instance with your own? Call the setPurifier()
method:
Practices
If you're looking into sanitization, you're likely wanting to sanitize inputted user HTML content that is then stored in your database to be rendered onto your application.
In this scenario, it's likely best practice to sanitize on the way out instead of the on the way in. Remember, the database doesn't care what text it contains.
This way you can allow anything to be inserted in the database, and have strong sanization rules on the way out.
This helps tremendously if you change your sanization requirements later down the line, then all rendered content will follow these sanization rules.
Configuration
Inside the configuration file, the entire settings array is passed directly to the HTML Purifier configuration, so feel free to customize it however you wish. For the configuration documentation, please visit the HTML Purifier Website:
http://htmlpurifier.org/live/configdoc/plain.html
Custom Configuration Rules
There's multiple ways of creating custom rules on the HTML Purifier instance.
Below is an example service provider you can use as a starting point to add rules to the instance. This provider gives compatibility with Basecamp's Trix WYSIWYG editor:
Credit to Antonio Primera for resolving some HTML Purifier configuration issues with trix.
After this service provider is created, make sure you insert it into your providers
array in the config/app.php
file, and update your HTML.Allowed
string in the config/purify.php
file.
Note: Remember that after this definition is created, and you have ran
Purify::clean()
, the definition will be cached, and you will have to clear it from yourstorage/app/purify
folder if you want to make changes to the definition.Otherwise, you will have to change the definition version number or ID for it to be re-cached.