2006-07-23 00:11:03 +00:00
|
|
|
<?php
|
|
|
|
|
2006-07-23 03:43:53 +00:00
|
|
|
/*!
|
|
|
|
* @mainpage
|
|
|
|
*
|
|
|
|
* HTMLPurifier is a purification class that will take an arbitrary snippet of
|
|
|
|
* HTML and rigorously test, validate and filter it into a version that
|
|
|
|
* is safe for output onto webpages. It achieves this by:
|
|
|
|
*
|
|
|
|
* -# Lexing (parsing into tokens) the document,
|
2006-07-24 02:49:37 +00:00
|
|
|
* -# Executing various strategies on the tokens:
|
|
|
|
* -# Removing all elements not in the whitelist,
|
|
|
|
* -# Making the tokens well-formed,
|
|
|
|
* -# Fixing the nesting of the nodes, and
|
|
|
|
* -# Validating attributes of the nodes; and
|
2006-07-23 03:43:53 +00:00
|
|
|
* -# Generating HTML from the purified tokens.
|
|
|
|
*
|
|
|
|
* See /docs/spec.txt for more details.
|
|
|
|
*/
|
|
|
|
|
2006-08-14 00:27:15 +00:00
|
|
|
require_once 'HTMLPurifier/ConfigDef.php';
|
|
|
|
require_once 'HTMLPurifier/Config.php';
|
2006-07-23 00:11:03 +00:00
|
|
|
require_once 'HTMLPurifier/Lexer.php';
|
2006-08-14 21:22:49 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLDefinition.php';
|
2006-07-23 00:11:03 +00:00
|
|
|
require_once 'HTMLPurifier/Generator.php';
|
2006-08-14 00:27:15 +00:00
|
|
|
require_once 'HTMLPurifier/Strategy/Core.php';
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-07-23 03:43:53 +00:00
|
|
|
/**
|
|
|
|
* Main library execution class.
|
|
|
|
*
|
|
|
|
* Facade that performs calls to the HTMLPurifier_Lexer,
|
2006-07-24 02:51:19 +00:00
|
|
|
* HTMLPurifier_Strategy and HTMLPurifier_Generator subsystems in order to
|
2006-07-23 03:43:53 +00:00
|
|
|
* purify HTML.
|
|
|
|
*/
|
2006-07-23 00:11:03 +00:00
|
|
|
class HTMLPurifier
|
|
|
|
{
|
|
|
|
|
2006-08-14 00:27:15 +00:00
|
|
|
var $config;
|
|
|
|
|
2006-07-23 03:43:53 +00:00
|
|
|
/**
|
|
|
|
* Initializes the purifier.
|
2006-08-04 01:47:48 +00:00
|
|
|
* @param $config Configuration for all instances of the purifier
|
2006-07-23 03:43:53 +00:00
|
|
|
*/
|
2006-08-04 01:47:48 +00:00
|
|
|
function HTMLPurifier($config = null) {
|
2006-08-14 00:27:15 +00:00
|
|
|
$this->config = $config ? $config : HTMLPurifier_Config::createDefault();
|
2006-07-23 00:11:03 +00:00
|
|
|
}
|
|
|
|
|
2006-07-23 03:43:53 +00:00
|
|
|
/**
|
|
|
|
* Purifies HTML.
|
|
|
|
*
|
|
|
|
* @param $html String of HTML to purify
|
2006-08-04 01:47:48 +00:00
|
|
|
* @param $config HTMLPurifier_Config object for this specific round
|
2006-07-23 03:43:53 +00:00
|
|
|
* @return Purified HTML
|
|
|
|
*/
|
2006-08-04 01:47:48 +00:00
|
|
|
function purify($html, $config = null) {
|
2006-08-14 00:27:15 +00:00
|
|
|
$config = $config ? $config : $this->config;
|
|
|
|
$lexer = HTMLPurifier_Lexer::create();
|
|
|
|
$strategy = new HTMLPurifier_Strategy_Core();
|
|
|
|
$generator = new HTMLPurifier_Generator();
|
|
|
|
return $generator->generateFromTokens(
|
|
|
|
$strategy->execute(
|
2006-08-14 02:46:34 +00:00
|
|
|
$lexer->tokenizeHTML($html), $config
|
2006-08-14 00:27:15 +00:00
|
|
|
)
|
|
|
|
);
|
2006-07-23 00:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-04-15 01:13:42 +00:00
|
|
|
?>
|