15 $definition =
$config->getHTMLDefinition();
19 $escape_invalid_tags =
$config->get(
'Core.EscapeInvalidTags');
20 $remove_invalid_img =
$config->get(
'Core.RemoveInvalidImg');
23 $trusted =
$config->get(
'HTML.Trusted');
25 $remove_script_contents =
$config->get(
'Core.RemoveScriptContents');
26 $hidden_elements =
$config->get(
'Core.HiddenElements');
29 if ($remove_script_contents ===
true) {
30 $hidden_elements[
'script'] =
true;
31 } elseif ($remove_script_contents ===
false && isset($hidden_elements[
'script'])) {
32 unset($hidden_elements[
'script']);
38 $remove_until =
false;
41 $textify_comments =
false;
44 $context->register(
'CurrentToken', $token);
47 if (
$config->get(
'Core.CollectErrors')) {
48 $e =& $context->get(
'ErrorCollector');
51 foreach($tokens as $token) {
53 if (empty($token->is_tag) || $token->name !== $remove_until) {
57 if (!empty( $token->is_tag )) {
62 isset($definition->info_tag_transform[$token->name])
64 $original_name = $token->name;
67 $token = $definition->
68 info_tag_transform[$token->name]->
69 transform($token,
$config, $context);
70 if ($e) $e->send(E_NOTICE,
'Strategy_RemoveForeignElements: Tag transform', $original_name);
73 if (isset($definition->info[$token->name])) {
79 $definition->info[$token->name]->required_attr &&
80 ($token->name !=
'img' || $remove_invalid_img)
82 $attr_validator->validateToken($token,
$config, $context);
84 foreach ($definition->info[$token->name]->required_attr as
$name) {
85 if (!isset($token->attr[$name])) {
91 if ($e) $e->send(E_ERROR,
'Strategy_RemoveForeignElements: Missing required attribute', $name);
94 $token->armor[
'ValidateAttributes'] =
true;
98 $textify_comments = $token->name;
100 $textify_comments =
false;
103 } elseif ($escape_invalid_tags) {
105 if ($e) $e->send(E_WARNING,
'Strategy_RemoveForeignElements: Foreign element to text');
107 $generator->generateFromToken($token)
112 if (isset($hidden_elements[$token->name])) {
114 $remove_until = $token->name;
118 $remove_until =
false;
120 if ($e) $e->send(E_ERROR,
'Strategy_RemoveForeignElements: Foreign meta element removed');
122 if ($e) $e->send(E_ERROR,
'Strategy_RemoveForeignElements: Foreign element removed');
128 if ($textify_comments !==
false) {
129 $data = $token->data;
131 } elseif ($trusted) {
135 if (substr($token->data, -1) ==
'-') {
136 $e->send(E_NOTICE,
'Strategy_RemoveForeignElements: Trailing hyphen in comment removed');
139 $token->data = rtrim($token->data,
'-');
140 $found_double_hyphen =
false;
141 while (strpos($token->data,
'--') !==
false) {
142 if ($e && !$found_double_hyphen) {
143 $e->send(E_NOTICE,
'Strategy_RemoveForeignElements: Hyphens in comment collapsed');
145 $found_double_hyphen =
true;
146 $token->data = str_replace(
'--',
'-', $token->data);
150 if ($e) $e->send(E_NOTICE,
'Strategy_RemoveForeignElements: Comment removed');
159 if ($remove_until && $e) {
161 $e->send(E_ERROR,
'Strategy_RemoveForeignElements: Token removed to end', $remove_until);
164 $context->destroy(
'CurrentToken');