https://github.com/bnomei/kirby3-htmlpurifier
Static class method, Uniform-Guard and Field-Method to filter your "dirty" HTML inputs to "clean" HTML.
https://github.com/bnomei/kirby3-htmlpurifier
filter form headless html htmlawed input kirby3 kirby3-cms kirby3-plugin kql kses safe sanitize security striptags submit uniform xss
Last synced: about 1 year ago
JSON representation
Static class method, Uniform-Guard and Field-Method to filter your "dirty" HTML inputs to "clean" HTML.
- Host: GitHub
- URL: https://github.com/bnomei/kirby3-htmlpurifier
- Owner: bnomei
- License: mit
- Created: 2020-03-09T10:23:34.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-20T07:14:53.000Z (about 3 years ago)
- Last Synced: 2024-10-11T03:05:32.038Z (over 1 year ago)
- Topics: filter, form, headless, html, htmlawed, input, kirby3, kirby3-cms, kirby3-plugin, kql, kses, safe, sanitize, security, striptags, submit, uniform, xss
- Language: PHP
- Homepage:
- Size: 482 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Kirby HtmlPurifier


[](https://travis-ci.com/bnomei/kirby3-htmlpurifier)
[](https://coveralls.io/github/bnomei/kirby3-htmlpurifier)
[](https://codeclimate.com/github/bnomei/kirby3-htmlpurifier)
[](https://twitter.com/bnomei)
Static class method, Uniform-Guard and Field-Method to filter your "dirty" HTML inputs to "clean" HTML.
[strip_tags](https://www.php.net/manual/en/function.strip-tags.php) and [PHP Input Filter](https://www.phpclasses.org/package/2189-PHP-Filter-out-unwanted-PHP-Javascript-HTML-tags-.html) are not good enough for you? Installing a plugin that has a dependency with lots of code does not bother you? You are willing to take the performance hit if you use it? Read on then...
## Installation
- unzip [master.zip](https://github.com/bnomei/kirby3-htmlpurifier/archive/master.zip) as folder `site/plugins/kirby3-htmlpurifier` or
- `git submodule add https://github.com/bnomei/kirby3-htmlpurifier.git site/plugins/kirby3-htmlpurifier` or
- `composer require bnomei/kirby3-htmlpurifier`
## Usage PHP
```php
$cleanHtml = \Bnomei\HtmlPurifier::purify($dirtyHtml);
```
## Usage Uniform-Guard
Because of the plugin loading order the `htmlPurifyGuard` will only be available with composer installations of this plugin.
```php
$form = new \Uniform\Form;
if (kirby()->request()->is('POST')) {
$form->honeypotGuard() // needs to be called explicitly now
->htmlPurifyGuard(); // purified all data
if ($form->success()) {
// ...
}
}
```
## Usage Field-Method
```php
$dirtHtml = (string) $page->myfield();
$cleanHtml = (string) $page->myfield()->htmlPurify();
$cleanHtml = (string) $page->myfield()->kirbytext()->htmlPurify();
```
## Usage with KQL for headless
If you want to make extra sure your html output to headless is valid html you can purify your fields. Be advised that this will come with a performance penalty since purification is no simple task.
> ⚠️ All proprietary elements (``, ...) and attributes (`srcset`, `sizes`, `data-*`, `x-*:`, `@*:`, ...) will be removed!
**KQL Query**
```json
{
"query": "page('photography')",
"select": {
"url": true,
"title": true,
"textWithPurifiedHtml": "page.text.kirbytext.htmlPurify"
}
}
```
**Example: Vue**
```vue
```
## Settings
| bnomei.htmlpurifier. | Default | Description |
|---------------------------|----------------|---------------------------|
| config | callback | overwrite this to adjust the config of used HtmlPurifier dependency |
## Dependecies
- [Kirby 3 Plugin Uniform](https://github.com/mzur/kirby-uniform)
- [HtmlPurifier](https://github.com/ezyang/htmlpurifier)
## Disclaimer
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please [create a new issue](https://github.com/bnomei/kirby3-htmlpurifier/issues/new).
## License
[MIT](https://opensource.org/licenses/MIT)
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.