0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-09-19 18:55:19 +00:00

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
This commit is contained in:
Edward Z. Yang 2007-02-16 03:16:17 +00:00
parent 5c4a0a6785
commit 0870974a25

View File

@ -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;
}