2006-07-24 01:50:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/Strategy.php';
|
|
|
|
require_once 'HTMLPurifier/Definition.php';
|
|
|
|
require_once 'HTMLPurifier/Generator.php';
|
|
|
|
|
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
|
|
|
|
* tokens.
|
|
|
|
*/
|
|
|
|
|
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();
|
|
|
|
$this->definition = HTMLPurifier_Definition::instance();
|
|
|
|
}
|
|
|
|
|
|
|
|
function execute($tokens) {
|
|
|
|
$result = array();
|
|
|
|
foreach($tokens as $token) {
|
|
|
|
if (!empty( $token->is_tag )) {
|
2006-07-30 19:11:18 +00:00
|
|
|
// DEFINITION CALL
|
|
|
|
if (!isset($this->definition->info[$token->name])) {
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|