sloyakuza/laravel-html-purifier
Composer 安装命令:
composer require sloyakuza/laravel-html-purifier
包简介
An HTML Purifier for Laravel
README 文档
README
Prečisovalnica HTML za Laravel
Preprosta Laravel ponudnik storitev za enostavno uporabo HTMLPurifier v Laravelu. Z njihove spletne strani:
HTML Purifier je standardno skladna HTML filtrska knjižnica, napisana v PHP. HTML Purifier ne bo odstranil le vse zlonamerne kode (bolj znane kot XSS) s temeljito revidiranim, varnim, a dovoljenim belim seznamom, temveč bo tudi zagotovil, da so vaši dokumenti skladni s standardi, nekaj le dosegljivega s celovitim poznavanjem W3C-jevih specifikacij. Naveličate se uporabe BBCode zaradi trenutne pokrajine pomanjkljivih ali negotovih HTML filtrov? Imate WYSIWYG urednik, vendar nikoli ni bil sposoben uporabljati? Iščete visokokakovostne, standardno skladne, odprtokodne komponente za to aplikacijo, ki jo gradite? HTML Prečisovalnica je za vas!
Namestitev
Za Laravel 5.5+
Zahtevaj ta paket s skladateljem:
composer require sloyakuza/laravel-html-purifier
Ponudnik storitev bo samodejno odkrit. Ponudnika ni treba dodajati nikjer.
Za Laravel 5.0 do 5.4
Zahtevaj ta paket s skladateljem:
composer require sloyakuza/laravel-html-purifier
Poiščite providers ključ v config/app.php in registrirajte ponudnika storitev HTMLPurifier.
'providers' => [ // ... SLOYakuza\Purifier\PurifierServiceProvider::class, ]
Poiščite aliases ključ v config/app.php in registrirati vzdevke.
'aliases' => [ // ... 'Purifier' => SLOYakuza\Purifier\Facades\Purifier::class, ]
Navada
Uporabite te metode znotraj vaših zahtev ali srednje programske opreme, kjerkoli potrebujete HTML čiščenje:
\clean(Input::get('inputname'));
ali
Purifier::clean(Input::get('inputname'));
dinamična konfiguracija
\clean('This is my H1 title', 'titles'); \clean('This is my H1 title', array('Attr.EnableID' => true));
ali
Purifier::clean('This is my H1 title', 'titles'); Purifier::clean('This is my H1 title', array('Attr.EnableID' => true));
uporabiti 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); });
Druga možnost je, da v Laravel 7+, če iščete čiščenje HTML-ja v modelih Eloquent, lahko uporabite naše odlive po meri:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use SLOYakuza\Purifier\Casts\CleanHtml; use SLOYakuza\Purifier\Casts\CleanHtmlInput; use SLOYakuza\Purifier\Casts\CleanHtmlOutput; class User 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 ]; }
Konfiguracijo
Če želite uporabiti lastne nastavitve, objavite konfiguracijo.
php artisan vendor:publish --provider="SLOYakuza\Purifier\PurifierServiceProvider"
Konfiguracija datoteke config/purifier.php to bi moralo biti všeč
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'], ], ], ];
sloyakuza/laravel-html-purifier 适用场景与选型建议
sloyakuza/laravel-html-purifier 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.77k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「html」 「laravel」 「xss」 「Purifier」 「SLOYakuza」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sloyakuza/laravel-html-purifier 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sloyakuza/laravel-html-purifier 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sloyakuza/laravel-html-purifier 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Provide a way to secure accesses to all routes of an symfony application.
It's a barebone security class written on PHP
HTML and form generation
Contao CMS integrity check for some files
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
统计信息
- 总下载量: 1.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-26