2006-07-24 01:50:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/Strategy.php';
|
2006-08-14 21:22:49 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLDefinition.php';
|
2006-07-24 01:50:02 +00:00
|
|
|
require_once 'HTMLPurifier/Generator.php';
|
2006-08-02 02:24:03 +00:00
|
|
|
require_once 'HTMLPurifier/TagTransform.php';
|
2006-07-24 01:50:02 +00:00
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
/**
|
|
|
|
* Removes all unrecognized tags from the list of tokens.
|
|
|
|
*
|
|
|
|
* This strategy iterates through all the tokens and removes unrecognized
|
2006-08-02 02:26:01 +00:00
|
|
|
* tokens. If a token is not recognized but a TagTransform is defined for
|
|
|
|
* that element, the element will be transformed accordingly.
|
2006-07-30 19:11:18 +00:00
|
|
|
*/
|
|
|
|
|
2006-07-24 01:50:02 +00:00
|
|
|
class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
|
|
|
|
{
|
|
|
|
|
|
|
|
var $generator;
|
|
|
|
var $definition;
|
|
|
|
|
2006-07-24 02:49:37 +00:00
|
|
|
function HTMLPurifier_Strategy_RemoveForeignElements() {
|
2006-07-24 01:50:02 +00:00
|
|
|
$this->generator = new HTMLPurifier_Generator();
|
2006-08-14 21:22:49 +00:00
|
|
|
$this->definition = HTMLPurifier_HTMLDefinition::instance();
|
2006-07-24 01:50:02 +00:00
|
|
|
}
|
|
|
|
|
2006-08-14 02:46:34 +00:00
|
|
|
function execute($tokens, $config) {
|
2006-07-24 01:50:02 +00:00
|
|
|
$result = array();
|
|
|
|
foreach($tokens as $token) {
|
|
|
|
if (!empty( $token->is_tag )) {
|
2006-07-30 19:11:18 +00:00
|
|
|
// DEFINITION CALL
|
2006-08-02 02:24:03 +00:00
|
|
|
if (isset($this->definition->info[$token->name])) {
|
|
|
|
// leave untouched
|
|
|
|
} elseif (
|
|
|
|
isset($this->definition->info_tag_transform[$token->name])
|
|
|
|
) {
|
|
|
|
// there is a transformation for this tag
|
|
|
|
// DEFINITION CALL
|
|
|
|
$token = $this->
|
|
|
|
definition->
|
|
|
|
info_tag_transform[$token->name]->
|
|
|
|
transform($token);
|
|
|
|
} else {
|
2006-07-24 01:50:02 +00:00
|
|
|
// invalid tag, generate HTML and insert in
|
|
|
|
$token = new HTMLPurifier_Token_Text(
|
|
|
|
$this->generator->generateFromToken($token)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} elseif ($token->type == 'comment') {
|
|
|
|
// strip comments
|
|
|
|
continue;
|
|
|
|
} elseif ($token->type == 'text') {
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$result[] = $token;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|