14 public function execute($tokens, $config, $context) {
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');
24 $comment_lookup = $config->get(
'HTML.AllowedComments');
25 $comment_regexp = $config->get(
'HTML.AllowedCommentsRegexp');
26 $check_comments = $comment_lookup !== array() || $comment_regexp !== null;
28 $remove_script_contents = $config->get(
'Core.RemoveScriptContents');
29 $hidden_elements = $config->get(
'Core.HiddenElements');
32 if ($remove_script_contents ===
true) {
33 $hidden_elements[
'script'] =
true;
34 } elseif ($remove_script_contents ===
false && isset($hidden_elements[
'script'])) {
35 unset($hidden_elements[
'script']);
41 $remove_until =
false;
44 $textify_comments =
false;
47 $context->register(
'CurrentToken', $token);
50 if ($config->get(
'Core.CollectErrors')) {
51 $e =& $context->get(
'ErrorCollector');
54 foreach($tokens as $token) {
56 if (empty($token->is_tag) || $token->name !== $remove_until) {
60 if (!empty( $token->is_tag )) {
65 isset($definition->info_tag_transform[$token->name])
67 $original_name = $token->name;
70 $token = $definition->
71 info_tag_transform[$token->name]->
72 transform($token, $config, $context);
73 if ($e) $e->send(E_NOTICE,
'Strategy_RemoveForeignElements: Tag transform', $original_name);
76 if (isset($definition->info[$token->name])) {
82 $definition->info[$token->name]->required_attr &&
83 ($token->name !=
'img' || $remove_invalid_img)
85 $attr_validator->validateToken($token, $config, $context);
87 foreach ($definition->info[$token->name]->required_attr as $name) {
88 if (!isset($token->attr[$name])) {
94 if ($e) $e->send(E_ERROR,
'Strategy_RemoveForeignElements: Missing required attribute', $name);
97 $token->armor[
'ValidateAttributes'] =
true;
101 $textify_comments = $token->name;
103 $textify_comments =
false;
106 } elseif ($escape_invalid_tags) {
108 if ($e) $e->send(E_WARNING,
'Strategy_RemoveForeignElements: Foreign element to text');
110 $generator->generateFromToken($token)
115 if (isset($hidden_elements[$token->name])) {
117 $remove_until = $token->name;
121 $remove_until =
false;
123 if ($e) $e->send(E_ERROR,
'Strategy_RemoveForeignElements: Foreign meta element removed');
125 if ($e) $e->send(E_ERROR,
'Strategy_RemoveForeignElements: Foreign element removed');
131 if ($textify_comments !==
false) {
132 $data = $token->data;
134 } elseif ($trusted || $check_comments) {
136 $trailing_hyphen =
false;
139 if (substr($token->data, -1) ==
'-') {
140 $trailing_hyphen =
true;
143 $token->data = rtrim($token->data,
'-');
144 $found_double_hyphen =
false;
145 while (strpos($token->data,
'--') !==
false) {
146 $found_double_hyphen =
true;
147 $token->data = str_replace(
'--',
'-', $token->data);
149 if ($trusted || !empty($comment_lookup[trim($token->data)]) || ($comment_regexp !== NULL && preg_match($comment_regexp, trim($token->data)))) {
152 if ($trailing_hyphen) {
153 $e->send(E_NOTICE,
'Strategy_RemoveForeignElements: Trailing hyphen in comment removed');
155 if ($found_double_hyphen) {
156 $e->send(E_NOTICE,
'Strategy_RemoveForeignElements: Hyphens in comment collapsed');
161 $e->send(E_NOTICE,
'Strategy_RemoveForeignElements: Comment removed');
167 if ($e) $e->send(E_NOTICE,
'Strategy_RemoveForeignElements: Comment removed');
176 if ($remove_until && $e) {
178 $e->send(E_ERROR,
'Strategy_RemoveForeignElements: Token removed to end', $remove_until);
181 $context->destroy(
'CurrentToken');