0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-09-18 18:25:18 +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:
Edward Z. Yang 2008-03-13 05:35:57 +00:00
parent c0dd6944a3
commit 42d2858c9d
3 changed files with 44 additions and 0 deletions

1
NEWS
View File

@ -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

View 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);
}

View 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>