|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?php
-
-
- class HTMLPurifier_AttrValidator
- {
-
-
-
- public function validateToken($token, $config, $context)
- {
- $definition = $config->getHTMLDefinition();
- $e =& $context->get('ErrorCollector', true);
-
-
- $ok =& $context->get('IDAccumulator', true);
- if (!$ok) {
- $id_accumulator = HTMLPurifier_IDAccumulator::build($config, $context);
- $context->register('IDAccumulator', $id_accumulator);
- }
-
-
- $current_token =& $context->get('CurrentToken', true);
- if (!$current_token) {
- $context->register('CurrentToken', $token);
- }
-
- if (!$token instanceof HTMLPurifier_Token_Start &&
- !$token instanceof HTMLPurifier_Token_Empty
- ) {
- return;
- }
-
-
-
- $d_defs = $definition->info_global_attr;
-
-
- $attr = $token->attr;
-
-
-
- foreach ($definition->info_attr_transform_pre as $transform) {
- $attr = $transform->transform($o = $attr, $config, $context);
- if ($e) {
- if ($attr != $o) {
- $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
- }
- }
- }
-
-
-
- foreach ($definition->info[$token->name]->attr_transform_pre as $transform) {
- $attr = $transform->transform($o = $attr, $config, $context);
- if ($e) {
- if ($attr != $o) {
- $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
- }
- }
- }
-
-
-
-
- $defs = $definition->info[$token->name]->attr;
-
- $attr_key = false;
- $context->register('CurrentAttr', $attr_key);
-
-
-
- foreach ($attr as $attr_key => $value) {
-
-
- if (isset($defs[$attr_key])) {
-
- if ($defs[$attr_key] === false) {
-
-
-
-
-
- $result = false;
- } else {
-
- $result = $defs[$attr_key]->validate(
- $value,
- $config,
- $context
- );
- }
- } elseif (isset($d_defs[$attr_key])) {
-
-
- $result = $d_defs[$attr_key]->validate(
- $value,
- $config,
- $context
- );
- } else {
-
- $result = false;
- }
-
-
- if ($result === false || $result === null) {
-
-
- if ($e) {
- $e->send(E_ERROR, 'AttrValidator: Attribute removed');
- }
-
-
- unset($attr[$attr_key]);
- } elseif (is_string($result)) {
-
-
-
-
-
- $attr[$attr_key] = $result;
- } else {
-
- }
-
-
-
-
-
-
- }
-
- $context->destroy('CurrentAttr');
-
-
-
-
- foreach ($definition->info_attr_transform_post as $transform) {
- $attr = $transform->transform($o = $attr, $config, $context);
- if ($e) {
- if ($attr != $o) {
- $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
- }
- }
- }
-
-
- foreach ($definition->info[$token->name]->attr_transform_post as $transform) {
- $attr = $transform->transform($o = $attr, $config, $context);
- if ($e) {
- if ($attr != $o) {
- $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
- }
- }
- }
-
- $token->attr = $attr;
-
-
- if (!$current_token) {
- $context->destroy('CurrentToken');
- }
-
- }
-
-
- }
-
-
|