mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-10 07:38:41 +00:00
6ff78d2f79
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@497 48356398-32a2-884e-a903-53898d9a118a
59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
require_once 'HTMLPurifier/Strategy.php';
|
|
require_once 'HTMLPurifier/HTMLDefinition.php';
|
|
require_once 'HTMLPurifier/Generator.php';
|
|
require_once 'HTMLPurifier/TagTransform.php';
|
|
|
|
/**
|
|
* Removes all unrecognized tags from the list of tokens.
|
|
*
|
|
* This strategy iterates through all the tokens and removes unrecognized
|
|
* tokens. If a token is not recognized but a TagTransform is defined for
|
|
* that element, the element will be transformed accordingly.
|
|
*/
|
|
|
|
class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
|
|
{
|
|
|
|
function execute($tokens, $config, &$context) {
|
|
$definition = $config->getHTMLDefinition();
|
|
$generator = new HTMLPurifier_Generator();
|
|
$result = array();
|
|
$escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
|
|
foreach($tokens as $token) {
|
|
if (!empty( $token->is_tag )) {
|
|
// DEFINITION CALL
|
|
if (isset($definition->info[$token->name])) {
|
|
// leave untouched
|
|
} elseif (
|
|
isset($definition->info_tag_transform[$token->name])
|
|
) {
|
|
// there is a transformation for this tag
|
|
// DEFINITION CALL
|
|
$token = $definition->
|
|
info_tag_transform[$token->name]->
|
|
transform($token, $config, $context);
|
|
} elseif ($escape_invalid_tags) {
|
|
// invalid tag, generate HTML and insert in
|
|
$token = new HTMLPurifier_Token_Text(
|
|
$generator->generateFromToken($token, $config, $context)
|
|
);
|
|
} else {
|
|
continue;
|
|
}
|
|
} elseif ($token->type == 'comment') {
|
|
// strip comments
|
|
continue;
|
|
} elseif ($token->type == 'text') {
|
|
} else {
|
|
continue;
|
|
}
|
|
$result[] = $token;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|