00001 <?php
00002
00008 class HTMLPurifier_AttrValidator
00009 {
00010
00021 public function validateToken(&$token, &$config, $context) {
00022
00023 $definition = $config->getHTMLDefinition();
00024 $e =& $context->get('ErrorCollector', true);
00025
00026
00027 $ok =& $context->get('IDAccumulator', true);
00028 if (!$ok) {
00029 $id_accumulator = HTMLPurifier_IDAccumulator::build($config, $context);
00030 $context->register('IDAccumulator', $id_accumulator);
00031 }
00032
00033
00034 $current_token =& $context->get('CurrentToken', true);
00035 if (!$current_token) $context->register('CurrentToken', $token);
00036
00037 if (
00038 !$token instanceof HTMLPurifier_Token_Start &&
00039 !$token instanceof HTMLPurifier_Token_Empty
00040 ) return $token;
00041
00042
00043
00044 $d_defs = $definition->info_global_attr;
00045
00046
00047 $attr = $token->attr;
00048
00049
00050
00051 foreach ($definition->info_attr_transform_pre as $transform) {
00052 $attr = $transform->transform($o = $attr, $config, $context);
00053 if ($e && ($attr != $o)) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
00054 }
00055
00056
00057
00058 foreach ($definition->info[$token->name]->attr_transform_pre as $transform) {
00059 $attr = $transform->transform($o = $attr, $config, $context);
00060 if ($e && ($attr != $o)) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
00061 }
00062
00063
00064
00065
00066 $defs = $definition->info[$token->name]->attr;
00067
00068 $attr_key = false;
00069 $context->register('CurrentAttr', $attr_key);
00070
00071
00072
00073 foreach ($attr as $attr_key => $value) {
00074
00075
00076 if ( isset($defs[$attr_key]) ) {
00077
00078 if ($defs[$attr_key] === false) {
00079
00080
00081
00082
00083
00084 $result = false;
00085 } else {
00086
00087 $result = $defs[$attr_key]->validate(
00088 $value, $config, $context
00089 );
00090 }
00091 } elseif ( isset($d_defs[$attr_key]) ) {
00092
00093
00094 $result = $d_defs[$attr_key]->validate(
00095 $value, $config, $context
00096 );
00097 } else {
00098
00099 $result = false;
00100 }
00101
00102
00103 if ($result === false || $result === null) {
00104
00105
00106 if ($e) $e->send(E_ERROR, 'AttrValidator: Attribute removed');
00107
00108
00109 unset($attr[$attr_key]);
00110 } elseif (is_string($result)) {
00111
00112
00113
00114
00115
00116 $attr[$attr_key] = $result;
00117 }
00118
00119
00120
00121
00122
00123
00124 }
00125
00126 $context->destroy('CurrentAttr');
00127
00128
00129
00130
00131 foreach ($definition->info_attr_transform_post as $transform) {
00132 $attr = $transform->transform($o = $attr, $config, $context);
00133 if ($e && ($attr != $o)) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
00134 }
00135
00136
00137 foreach ($definition->info[$token->name]->attr_transform_post as $transform) {
00138 $attr = $transform->transform($o = $attr, $config, $context);
00139 if ($e && ($attr != $o)) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
00140 }
00141
00142 $token->attr = $attr;
00143
00144
00145 if (!$current_token) $context->destroy('CurrentToken');
00146
00147 }
00148
00149
00150 }
00151