Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
9b6f84ca
Commit
9b6f84ca
authored
Aug 08, 2014
by
Alex-Code
Committed by
Carsten Brandt
Aug 12, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BaseHtmlPurifier config can now be a closure
`$config` can now be a closure that will have the `$configInstance` passed as the first param. updated docs. close #4656
parent
7728274c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
BaseHtmlPurifier.php
framework/helpers/BaseHtmlPurifier.php
+26
-4
No files found.
framework/helpers/BaseHtmlPurifier.php
View file @
9b6f84ca
...
...
@@ -19,17 +19,39 @@ class BaseHtmlPurifier
{
/**
* Passes markup through HTMLPurifier making it safe to output to end user
*
* @param string $content The HTML content to purify
* @param array|\Closure|null $config The config to use for HtmlPurifier.
* If not specified or `null` the default config will be used.
* You can use an array or an anonymous function to provide configuration options:
*
* @param string $content
* @param array|null $config
* @return string
* - An array will be passed to the `HTMLPurifier_Config::create()` method.
* - An anonymous function will be called after the config was created.
* The signature should be: `function($config)` where `$config` will be an
* instance of `HTMLPurifier_Config`.
*
* Here is a usage example of such a function:
*
* ~~~
* // Allow the HTML5 data attribute `data-type` on `img` elements.
* $content = HtmlPurifier::process($content, function($config) {
* $config->getHTMLDefinition(true)
* ->addAttribute('img', 'data-type', 'Text');
* });
* ~~~
*
* @return string the purified HTML content.
*/
public
static
function
process
(
$content
,
$config
=
null
)
{
$configInstance
=
\HTMLPurifier_Config
::
create
(
$config
);
$configInstance
=
\HTMLPurifier_Config
::
create
(
$config
instanceof
\Closure
?
null
:
$config
);
$configInstance
->
autoFinalize
=
false
;
$purifier
=
\HTMLPurifier
::
instance
(
$configInstance
);
$purifier
->
config
->
set
(
'Cache.SerializerPath'
,
\Yii
::
$app
->
getRuntimePath
());
if
(
$config
instanceof
\Closure
)
{
call_user_func
(
$config
,
$configInstance
);
}
return
$purifier
->
purify
(
$content
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment