mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-08 23:08:42 +00:00
d48f9b6b21
- Update TODO . Add another possible plaintext formatter . Reference config-ideas.txt for URI options - Update code-quality.txt, removing issues that have been addressed and updating time for post-beta - Update config-ideas.txt . Added more possible URI directives . Removed silly language control directive - Improved documentation on Class, CSS and Host git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@524 48356398-32a2-884e-a903-53898d9a118a
61 lines
2.1 KiB
PHP
61 lines
2.1 KiB
PHP
<?php
|
|
|
|
require_once 'HTMLPurifier/AttrDef.php';
|
|
require_once 'HTMLPurifier/CSSDefinition.php';
|
|
|
|
/**
|
|
* Validates the HTML attribute style, otherwise known as CSS.
|
|
* @note We don't implement the whole CSS specification, so it might be
|
|
* difficult to reuse this component in the context of validating
|
|
* actual stylesheet declarations.
|
|
*/
|
|
class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef
|
|
{
|
|
|
|
function validate($css, $config, &$context) {
|
|
|
|
$css = $this->parseCDATA($css);
|
|
|
|
$definition = $config->getCSSDefinition();
|
|
|
|
// 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);
|
|
$property = trim($property);
|
|
$value = trim($value);
|
|
if (!isset($definition->info[$property])) continue;
|
|
// inefficient call, since the validator will do this again
|
|
if (strtolower(trim($value)) !== 'inherit') {
|
|
// inherit works for everything (but only on the base property)
|
|
$result = $definition->info[$property]->validate(
|
|
$value, $config, $context );
|
|
} else {
|
|
$result = 'inherit';
|
|
}
|
|
if ($result === false) continue;
|
|
$propvalues[$property] = $result;
|
|
}
|
|
|
|
// procedure does not write the new CSS simultaneously, so it's
|
|
// slightly inefficient, but it's the only way of getting rid of
|
|
// duplicates. Perhaps config to optimize it, but not now.
|
|
|
|
$new_declarations = '';
|
|
foreach ($propvalues as $prop => $value) {
|
|
$new_declarations .= "$prop:$value;";
|
|
}
|
|
|
|
return $new_declarations ? $new_declarations : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|