mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-03-11 17:18:44 +00:00
[3.1.0] Experimental kses support.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1610 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
c0dd6944a3
commit
42d2858c9d
1
NEWS
1
NEWS
@ -35,6 +35,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
||||
to true to use them.
|
||||
! HTML Purifier now has its own Exception hierarchy under HTMLPurifier_Exception.
|
||||
Developer error (not enduser error) can cause these to be triggered.
|
||||
! Experimental kses() wrapper introduced with HTMLPurifier.kses.php
|
||||
- Autoclose now operates iteratively, i.e. <span><span><div> now has
|
||||
both span tags closed.
|
||||
- Various HTMLPurifier_Config convenience functions now accept another parameter
|
||||
|
28
library/HTMLPurifier.kses.php
Normal file
28
library/HTMLPurifier.kses.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Emulation layer for code that used kses(), substituting in HTML Purifier.
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/HTMLPurifier.auto.php';
|
||||
|
||||
function kses($string, $allowed_html, $allowed_protocols = null) {
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$allowed_elements = array();
|
||||
$allowed_attributes = array();
|
||||
foreach ($allowed_html as $element => $attributes) {
|
||||
$allowed_elements[$element] = true;
|
||||
foreach ($attributes as $attribute => $x) {
|
||||
$allowed_attributes["$element.$attribute"] = true;
|
||||
}
|
||||
}
|
||||
$config->set('HTML', 'AllowedElements', $allowed_elements);
|
||||
$config->set('HTML', 'AllowedAttributes', $allowed_attributes);
|
||||
$allowed_schemes = array();
|
||||
if ($allowed_protocols !== null) {
|
||||
$config->set('URI', 'AllowedSchemes', $allowed_protocols);
|
||||
}
|
||||
$purifier = new HTMLPurifier($config);
|
||||
return $purifier->purify($string);
|
||||
}
|
15
tests/HTMLPurifier/PHPT/kses/basic.phpt
Normal file
15
tests/HTMLPurifier/PHPT/kses/basic.phpt
Normal file
@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
HTMLPurifier.kses.php basic test
|
||||
--FILE--
|
||||
<?php
|
||||
require '../library/HTMLPurifier.kses.php';
|
||||
echo kses(
|
||||
'<a class="foo" style="color:#F00;" href="https://google.com">Foo<i>Bar</i>',
|
||||
array(
|
||||
'a' => array('class' => 1, 'href' => 1),
|
||||
),
|
||||
array('http') // no https!
|
||||
);
|
||||
|
||||
--EXPECT--
|
||||
<a class="foo">FooBar</a>
|
Loading…
x
Reference in New Issue
Block a user