mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-11 00:11:53 +00:00
d721066d27
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@225 48356398-32a2-884e-a903-53898d9a118a
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
require_once 'HTMLPurifier/AttrDef.php';
|
|
require_once 'HTMLPurifier/CSSDefinition.php';
|
|
|
|
class HTMLPurifier_AttrDef_CSS
|
|
{
|
|
|
|
function validate($css, $config, &$context) {
|
|
|
|
$definition = HTMLPurifier_CSSDefinition::instance();
|
|
|
|
// we're going to break the spec and explode by semicolons.
|
|
// This is because semicolon rarely appears in escaped form
|
|
|
|
$declarations = explode(';', $css);
|
|
$propvalues = array();
|
|
|
|
foreach ($declarations as $declaration) {
|
|
if (!$declaration) continue;
|
|
if (!strpos($declaration, ':')) continue;
|
|
list($property, $value) = explode(':', $declaration, 2);
|
|
if (!isset($definition->info[$property])) continue;
|
|
$result = $definition->info[$property]->validate($value,$config,$context);
|
|
if ($result === false) continue;
|
|
$propvalues[$property] = $result;
|
|
}
|
|
|
|
$new_declarations = '';
|
|
foreach ($propvalues as $prop => $value) {
|
|
$new_declarations .= "$prop:$value;";
|
|
}
|
|
|
|
return $new_declarations ? $new_declarations : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|