mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-22 08:21:52 +00:00
Extract RemoveForeignElements strategy from Definition object.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@111 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
8e91e841f5
commit
4b8a206417
42
library/HTMLPurifier/Strategy/RemoveForeignElements.php
Normal file
42
library/HTMLPurifier/Strategy/RemoveForeignElements.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/Strategy.php';
|
||||
require_once 'HTMLPurifier/Definition.php';
|
||||
require_once 'HTMLPurifier/Generator.php';
|
||||
|
||||
class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
|
||||
{
|
||||
|
||||
var $generator;
|
||||
var $definition;
|
||||
|
||||
function HTMLPurifier_Definition() {
|
||||
$this->generator = new HTMLPurifier_Generator();
|
||||
$this->definition = HTMLPurifier_Definition::instance();
|
||||
}
|
||||
|
||||
function execute($tokens) {
|
||||
$result = array();
|
||||
foreach($tokens as $token) {
|
||||
if (!empty( $token->is_tag )) {
|
||||
if (!isset($this->definition->info[$token->name])) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user