3 require_once 'HTMLPurifier/Strategy.php';
4 require_once 'HTMLPurifier/HTMLDefinition.php';
5 require_once 'HTMLPurifier/Generator.php';
6 require_once 'HTMLPurifier/TagTransform.php';
8 HTMLPurifier_ConfigSchema
::define(
9 'Core', 'RemoveInvalidImg', true, 'bool',
10 'This directive enables pre-emptive URI checking in <code>img</code> '.
11 'tags, as the attribute validation strategy is not authorized to '.
12 'remove elements from the document. This directive has been available '.
13 'since 1.3.0, revert to pre-1.3.0 behavior by setting to false.'
17 * Removes all unrecognized tags from the list of tokens.
19 * This strategy iterates through all the tokens and removes unrecognized
20 * tokens. If a token is not recognized but a TagTransform is defined for
21 * that element, the element will be transformed accordingly.
24 class HTMLPurifier_Strategy_RemoveForeignElements
extends HTMLPurifier_Strategy
27 function execute($tokens, $config, &$context) {
28 $definition = $config->getHTMLDefinition();
29 $generator = new HTMLPurifier_Generator();
31 $escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
32 $remove_invalid_img = $config->get('Core', 'RemoveInvalidImg');
33 foreach($tokens as $token) {
34 if (!empty( $token->is_tag
)) {
36 if (isset($definition->info
[$token->name
])) {
37 // leave untouched, except for a few special cases:
39 // hard-coded image special case, pre-emptively drop
40 // if not available. Probably not abstract-able
41 if ( $token->name
== 'img' && $remove_invalid_img ) {
42 if (!isset($token->attr
['src'])) {
45 if (!isset($definition->info
['img']->attr
['src'])) {
52 validate($token->attr
['src'],
54 if ($token->attr
['src'] === false) continue;
58 isset($definition->info_tag_transform
[$token->name
])
60 // there is a transformation for this tag
62 $token = $definition->
63 info_tag_transform
[$token->name
]->
64 transform($token, $config, $context);
65 } elseif ($escape_invalid_tags) {
66 // invalid tag, generate HTML and insert in
67 $token = new HTMLPurifier_Token_Text(
68 $generator->generateFromToken($token, $config, $context)
73 } elseif ($token->type
== 'comment') {
76 } elseif ($token->type
== 'text') {