2006-07-30 18:37:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/Strategy.php';
|
|
|
|
require_once 'HTMLPurifier/Definition.php';
|
|
|
|
require_once 'HTMLPurifier/IDAccumulator.php';
|
|
|
|
|
|
|
|
class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
|
|
|
{
|
|
|
|
|
|
|
|
var $definition;
|
|
|
|
|
|
|
|
function HTMLPurifier_Strategy_ValidateAttributes() {
|
|
|
|
$this->definition = HTMLPurifier_Definition::instance();
|
|
|
|
}
|
|
|
|
|
2006-08-04 01:47:48 +00:00
|
|
|
function execute($tokens, $config = null) {
|
|
|
|
|
|
|
|
// load default configuration object if none passed
|
|
|
|
if (!$config) $config = HTMLPurifier_Config::createDefault();
|
|
|
|
|
|
|
|
// setup ID accumulator and load it with blacklisted IDs
|
2006-07-30 18:37:42 +00:00
|
|
|
$accumulator = new HTMLPurifier_IDAccumulator();
|
2006-08-04 01:47:48 +00:00
|
|
|
$accumulator->load($config->attr_id_blacklist);
|
|
|
|
|
|
|
|
// DEFINITION CALL
|
2006-07-30 19:11:18 +00:00
|
|
|
$d_defs = $this->definition->info_global_attr;
|
2006-08-04 01:47:48 +00:00
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
foreach ($tokens as $key => $token) {
|
2006-08-05 01:50:13 +00:00
|
|
|
if ($token->type !== 'start' && $token->type !== 'empty') continue;
|
2006-07-30 19:11:18 +00:00
|
|
|
|
|
|
|
// DEFINITION CALL
|
|
|
|
$defs = $this->definition->info[$token->name]->attr;
|
|
|
|
|
2006-08-05 02:16:28 +00:00
|
|
|
$attr = $token->attributes;
|
|
|
|
|
2006-08-05 01:50:13 +00:00
|
|
|
// DEFINITION CALL
|
|
|
|
foreach ($this->definition->info_attr_transform as $transformer) {
|
2006-08-05 02:16:28 +00:00
|
|
|
$attr = $transformer->transform($attr);
|
2006-08-05 01:50:13 +00:00
|
|
|
}
|
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
foreach ($attr as $attr_key => $value) {
|
2006-08-04 01:52:54 +00:00
|
|
|
|
|
|
|
// call the definition
|
2006-07-30 18:37:42 +00:00
|
|
|
if ( isset($defs[$attr_key]) ) {
|
|
|
|
if (!$defs[$attr_key]) {
|
|
|
|
$result = false;
|
|
|
|
} else {
|
2006-08-04 01:52:54 +00:00
|
|
|
$result = $defs[$attr_key]->validate($value, $config, $accumulator);
|
2006-07-30 18:37:42 +00:00
|
|
|
}
|
|
|
|
} elseif ( isset($d_defs[$attr_key]) ) {
|
2006-08-04 01:52:54 +00:00
|
|
|
$result = $d_defs[$attr_key]->validate($value, $config, $accumulator);
|
2006-07-30 18:37:42 +00:00
|
|
|
} else {
|
|
|
|
$result = false;
|
|
|
|
}
|
2006-08-04 01:52:54 +00:00
|
|
|
|
|
|
|
// put the results into effect
|
2006-08-04 03:01:45 +00:00
|
|
|
if ($result === false || $result === null) {
|
2006-07-30 18:37:42 +00:00
|
|
|
unset($attr[$attr_key]);
|
2006-08-04 00:11:54 +00:00
|
|
|
} elseif (is_string($result)) {
|
|
|
|
// simple substitution
|
|
|
|
$attr[$attr_key] = $result;
|
2006-07-30 18:37:42 +00:00
|
|
|
}
|
2006-08-04 00:11:54 +00:00
|
|
|
// we'd also want slightly more complicated substitution,
|
|
|
|
// although we're not sure how colliding attributes would
|
|
|
|
// resolve
|
2006-07-30 18:37:42 +00:00
|
|
|
}
|
2006-08-05 02:16:28 +00:00
|
|
|
|
|
|
|
// commit changes
|
|
|
|
// could interfere with flyweight implementation
|
|
|
|
$tokens[$key]->attributes = $attr;
|
2006-07-30 18:37:42 +00:00
|
|
|
}
|
|
|
|
return $tokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|