1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-04 21:28:06 +02:00

Outfit a bunch of other classes so they can accept a configuration object. Put in basic scaffolding for extractBody() functionality.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@257 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2006-08-15 00:31:12 +00:00
parent 24c64dbbac
commit d7140f2e05
14 changed files with 75 additions and 26 deletions

View File

@@ -5,26 +5,28 @@
class HTMLPurifier_Generator
{
function generateFromTokens($tokens) {
// only unit tests may omit configuration: internals MUST pass config
function generateFromTokens($tokens, $config = null) {
$html = '';
if (!$config) $config = HTMLPurifier_Config::createDefault();
if (!$tokens) return '';
foreach ($tokens as $token) {
$html .= $this->generateFromToken($token);
$html .= $this->generateFromToken($token, $config);
}
return $html;
}
function generateFromToken($token) {
function generateFromToken($token, $config) {
if (!isset($token->type)) return '';
if ($token->type == 'start') {
$attr = $this->generateAttributes($token->attributes);
$attr = $this->generateAttributes($token->attributes, $config);
return '<' . $token->name . ($attr ? ' ' : '') . $attr . '>';
} elseif ($token->type == 'end') {
return '</' . $token->name . '>';
} elseif ($token->type == 'empty') {
$attr = $this->generateAttributes($token->attributes);
$attr = $this->generateAttributes($token->attributes, $config);
return '<' . $token->name . ($attr ? ' ' : '') . $attr . ' />';
} elseif ($token->type == 'text') {
@@ -36,7 +38,7 @@ class HTMLPurifier_Generator
}
}
function generateAttributes($assoc_array_of_attributes) {
function generateAttributes($assoc_array_of_attributes, $config) {
$html = '';
foreach ($assoc_array_of_attributes as $key => $value) {
$html .= $key.'="'.htmlspecialchars($value, ENT_COMPAT, 'UTF-8').'" ';