From e4b621eec2d6c1bc19e95d2a6e725a55a795728e Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 20 May 2007 18:14:52 +0000 Subject: [PATCH] [1.7.0] Make doctype object available from config, switch generator over to it. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1076 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier/Config.php | 15 +++++++++++++++ library/HTMLPurifier/DoctypeRegistry.php | 3 +-- library/HTMLPurifier/Generator.php | 9 ++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/library/HTMLPurifier/Config.php b/library/HTMLPurifier/Config.php index 3184b8c9..8878684e 100644 --- a/library/HTMLPurifier/Config.php +++ b/library/HTMLPurifier/Config.php @@ -46,6 +46,11 @@ class HTMLPurifier_Config */ var $autoFinalize = true; + /** + * Instance of HTMLPurifier_Doctype, representing current doctype + */ + var $doctype; + /** * @param $definition HTMLPurifier_ConfigSchema that defines what directives * are allowed. @@ -225,6 +230,16 @@ class HTMLPurifier_Config } } + /** + * Returns the current doctype object + */ + function getDoctype() { + if (!$this->doctype) { + $this->getHTMLDefinition(); + } + return $this->doctype; + } + /** * Loads configuration values from an ini file * @param $filename Name of ini file diff --git a/library/HTMLPurifier/DoctypeRegistry.php b/library/HTMLPurifier/DoctypeRegistry.php index 34ed4736..40dc4cc3 100644 --- a/library/HTMLPurifier/DoctypeRegistry.php +++ b/library/HTMLPurifier/DoctypeRegistry.php @@ -93,8 +93,7 @@ class HTMLPurifier_DoctypeRegistry function make($config) { $original_doctype = $this->get($this->getDoctypeFromConfig($config)); $doctype = $original_doctype->copy(); - // FIXME!!! Set $doctype into $config so others can use it, - // you might need to use two copies + $config->doctype = $doctype; return $doctype; } diff --git a/library/HTMLPurifier/Generator.php b/library/HTMLPurifier/Generator.php index 502be982..14b147c6 100644 --- a/library/HTMLPurifier/Generator.php +++ b/library/HTMLPurifier/Generator.php @@ -84,12 +84,11 @@ class HTMLPurifier_Generator $html = ''; if (!$config) $config = HTMLPurifier_Config::createDefault(); $this->_clean_utf8 = $config->get('Output', 'EnableRedundantUTF8Cleaning'); - - // this should replaced with a query to the Doctype object in - // config to determine whether or not this is an XML-based language - $this->_xhtml = $config->get('HTML', 'XHTML'); - $this->_scriptFix = $config->get('Output', 'CommentScriptContents'); + + $doctype = $config->getDoctype(); + $this->_xhtml = $doctype->xml; + if (!$tokens) return ''; for ($i = 0, $size = count($tokens); $i < $size; $i++) { if ($this->_scriptFix && $tokens[$i]->name === 'script') {