From 0870974a25ae9a5f383ad411350e824c708e9054 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 16 Feb 2007 03:16:17 +0000 Subject: [PATCH] Have processCollections() perform name to instance indexing at the get-go. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@755 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier/HTMLModuleManager.php | 36 ++++++++++------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/library/HTMLPurifier/HTMLModuleManager.php b/library/HTMLPurifier/HTMLModuleManager.php index 68f93763..6443b1b5 100644 --- a/library/HTMLPurifier/HTMLModuleManager.php +++ b/library/HTMLPurifier/HTMLModuleManager.php @@ -29,6 +29,12 @@ class HTMLPurifier_HTMLModuleManager */ var $modules = array(); + /** + * Modules that, according to the current doctype and related settings, + * may be used. + */ + // var $validModules = array(); + /** * Associative array of module class name to module order keywords or * numbers (keyword is preferred, all keywords are resolved at beginning @@ -181,6 +187,10 @@ class HTMLPurifier_HTMLModuleManager $this->modules ); + $this->processCollections($this->collectionsSafe); + $this->processCollections($this->collectionsLenient); + $this->processCollections($this->collectionsCorrectional); + // sort the lookup modules foreach ($this->elementModuleLookup as $k => $modules) { if (count($modules) > 1) { @@ -194,10 +204,6 @@ class HTMLPurifier_HTMLModuleManager } } - $this->processCollections($this->collectionsSafe); - $this->processCollections($this->collectionsLenient); - $this->processCollections($this->collectionsCorrectional); - // notice that it is vital that we get a full content sets // elements lineup, but attr collections must not go by // anything other than the modules the user wants @@ -233,17 +239,14 @@ class HTMLPurifier_HTMLModuleManager } } - // replace with real modules + // replace with real modules, invert module from list to + // assoc array of module name to module instance foreach ($cols as $col_i => $col) { if (is_string($col)) continue; - $seen = array(); // lookup array to prevent dupes foreach ($col as $module_i => $module) { - if (isset($seen[$module])) { - unset($cols[$col_i][$module_i]); - continue; - } - $cols[$col_i][$module_i] = $this->modules[$module]; - $seen[$module] = true; + unset($cols[$col_i][$module_i]); + $module = $this->modules[$module]; + $cols[$col_i][$module->name] = $module; } } @@ -294,14 +297,7 @@ class HTMLPurifier_HTMLModuleManager $modules = array_merge($modules, $this->collectionsCorrectional[$doctype]); } - // convert from numeric to module name indexing, also prevents - // duplicates - $ret = array(); - foreach ($modules as $module) { - $ret[$module->name] = $module; - } - - return $ret; + return $modules; }