2006-08-12 20:22:09 +00:00
|
|
|
<?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);
|
2006-08-13 04:52:40 +00:00
|
|
|
$propvalues = array();
|
2006-08-12 20:22:09 +00:00
|
|
|
|
|
|
|
foreach ($declarations as $declaration) {
|
|
|
|
if (!$declaration) continue;
|
|
|
|
if (!strpos($declaration, ':')) continue;
|
|
|
|
list($property, $value) = explode(':', $declaration, 2);
|
|
|
|
if (!isset($definition->info[$property])) continue;
|
2006-08-13 16:52:31 +00:00
|
|
|
// inefficient call, since the validator will do this again
|
|
|
|
// inherit works for everything
|
|
|
|
if (strtolower(trim($value)) !== 'inherit') {
|
|
|
|
$result = $definition->info[$property]->validate(
|
|
|
|
$value, $config, $context );
|
|
|
|
} else {
|
|
|
|
$result = 'inherit';
|
|
|
|
}
|
2006-08-12 20:22:09 +00:00
|
|
|
if ($result === false) continue;
|
2006-08-13 04:52:40 +00:00
|
|
|
$propvalues[$property] = $result;
|
|
|
|
}
|
|
|
|
|
2006-08-13 16:52:31 +00:00
|
|
|
// slightly inefficient, but it's the only way of getting rid of
|
|
|
|
// duplicates. Perhaps config to optimize it, but not now.
|
|
|
|
|
2006-08-13 04:52:40 +00:00
|
|
|
$new_declarations = '';
|
|
|
|
foreach ($propvalues as $prop => $value) {
|
|
|
|
$new_declarations .= "$prop:$value;";
|
2006-08-12 20:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $new_declarations ? $new_declarations : false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|