b301 / purifier
Laravel 5 HtmlPurifier 包
此包的官方仓库似乎已不存在,因此已冻结该包。
2.1.3
2019-03-01 10:11 UTC
Requires
- php: >=5.5.9
- ezyang/htmlpurifier: 4.10.*
- illuminate/config: 5.0.* || 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*
- illuminate/filesystem: 5.0.* || 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*
- illuminate/support: 5.0.* || 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*
Requires (Dev)
- graham-campbell/testbench: ^3.2
- mockery/mockery: 0.9.*
- phpunit/phpunit: ^4.8|^5.0
- scrutinizer/ocular: ^1.3
Suggests
- laravel/framework: To test the Laravel bindings
- laravel/lumen-framework: To test the Lumen bindings
This package is not auto-updated.
Last update: 2024-01-23 06:20:37 UTC
README
一个简单的 Laravel 5 服务提供者,用于包含 HTMLPurifier for Laravel 5。
对于 Laravel 4 HTMLPurifier for Laravel 4
可以通过在项目的 composer.json
文件中要求 mews/purifier
包来通过 Composer 安装此包
{ "require": { "laravel/framework": "~5.0", "mews/purifier": "~2.0", } }
或者
使用 Composer 安装此包
composer require mews/purifier
使用 composer update
更新包或使用 composer install
安装。
使用方法
要使用 HTMLPurifier 服务提供者,您必须在启动 Laravel 应用程序时注册该提供者。主要有两种方法可以实现。
对于 Laravel 5.0 到 5.4
在 config/app.php
文件中找到 providers
键并注册 HTMLPurifier 服务提供者。
'providers' => [ // ... Mews\Purifier\PurifierServiceProvider::class, ]
在 app/config/app.php
文件中找到 aliases
键。
'aliases' => [ // ... 'Purifier' => Mews\Purifier\Facades\Purifier::class, ]
对于 Laravel 5.5+
服务提供者将自动发现。您无需将其添加到任何地方。
配置
要使用自己的设置,请发布配置。
$ php artisan vendor:publish --provider="Mews\Purifier\PurifierServiceProvider"
配置文件 config/purifier.php
应该像这样
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'], ], ], ];
示例
默认
clean(Input::get('inputname'));
或者
Purifier::clean(Input::get('inputname'));
动态配置
clean('This is my H1 title', 'titles'); clean('This is my H1 title', array('Attr.EnableID' => true));
或者
Purifier::clean('This is my H1 title', 'titles'); Purifier::clean('This is my H1 title', array('Attr.EnableID' => true));
对于 Laravel 4 HTMLPurifier for Laravel 4