Source for file HTMLModuleManager.php
Documentation is available at HTMLModuleManager.php
* Instance of HTMLPurifier_DoctypeRegistry
* Instance of current doctype
* Instance of HTMLPurifier_AttrTypes
* Active instances of modules for the specified doctype are
* indexed, by name, in this array.
* Array of recognized HTMLPurifier_Module instances, indexed by
* module's class name. This array is usually lazy loaded, but a
* user can overload a module by pre-emptively registering it.
* List of extra modules that were added by the user using addModule().
* These get unconditionally merged into the current doctype, whatever
* Associative array of element name to list of modules that have
* definitions for the element; this array is dynamically filled.
/** List of prefixes we should use for registering small names */
public $prefixes =
array('HTMLPurifier_HTMLModule_');
public $contentSets; /**< Instance of HTMLPurifier_ContentSets */
/** If set to true, unsafe elements and attributes will be allowed */
// editable internal objects
'CommonAttributes', 'Text', 'Hypertext', 'List',
'Presentation', 'Edit', 'Bdo', 'Tables', 'Image',
'StyleAttribute', 'Scripting', 'Object'
$transitional =
array('Legacy', 'Target');
$xml =
array('XMLCommonAttributes');
$non_xml =
array('NonXMLCommonAttributes');
'HTML 4.01 Transitional', false,
array('Tidy_Transitional', 'Tidy_Proprietary'),
'-//W3C//DTD HTML 4.01 Transitional//EN',
'http://www.w3.org/TR/html4/loose.dtd'
'HTML 4.01 Strict', false,
array('Tidy_Strict', 'Tidy_Proprietary'),
'-//W3C//DTD HTML 4.01//EN',
'http://www.w3.org/TR/html4/strict.dtd'
'XHTML 1.0 Transitional', true,
array('Tidy_Transitional', 'Tidy_XHTML', 'Tidy_Proprietary'),
'-//W3C//DTD XHTML 1.0 Transitional//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
'XHTML 1.0 Strict', true,
array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Strict', 'Tidy_Proprietary'),
'-//W3C//DTD XHTML 1.0 Strict//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Proprietary', 'Tidy_Strict'), // Tidy_XHTML1_1
'-//W3C//DTD XHTML 1.1//EN',
'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'
* Registers a module to the recognized module list, useful for
* overloading pre-existing modules.
* @param $module Mixed: string module name, with or without
* HTMLPurifier_HTMLModule prefix, or instance of
* subclass of HTMLPurifier_HTMLModule.
* @param $overload Boolean whether or not to overload previous modules.
* If this is not set, and you do overload a module,
* HTML Purifier will complain with a warning.
* @note This function will not call autoload, you must instantiate
* (and thus invoke) autoload outside the method.
* @note If a string is passed as a module name, different variants
* will be tested in this order:
* - Check for HTMLPurifier_HTMLModule_$name
* - Check all prefixes with $name in order they were added
* - Check for literal object name
* If your object name collides with an internal class, specify
* your module manually. All modules must have been included
* externally: registerModule will not perform inclusions for you!
// attempt to load the module
$original_module =
$module;
$module =
$prefix .
$original_module;
$module =
$original_module;
if (empty($module->name)) {
trigger_error('Overloading ' .
$module->name .
' without explicit overload parameter', E_USER_WARNING);
* Adds a module to the current doctype by first registering it,
* and then tacking it on to the active doctype
if (is_object($module)) $module =
$module->name;
* Adds a class prefix that registerModule() will use to resolve a
* string name to a concrete class
* Performs processing on modules, after being called you may
* use getElement() and getElements()
* @param $config Instance of HTMLPurifier_Config
public function setup($config) {
$this->trusted =
$config->get('HTML', 'Trusted');
$modules =
$this->doctype->modules;
// take out the default modules that aren't allowed
$lookup =
$config->get('HTML', 'AllowedModules');
$special_cases =
$config->get('HTML', 'CoreModules');
foreach ($modules as $k =>
$m) {
if (isset
($special_cases[$m])) continue;
if (!isset
($lookup[$m])) unset
($modules[$k]);
// merge in custom modules
// add proprietary module (this gets special treatment because
// it is completely removed from doctypes, etc.)
if ($config->get('HTML', 'Proprietary')) {
$modules[] =
'Proprietary';
// add SafeObject/Safeembed modules
if ($config->get('HTML', 'SafeObject')) {
$modules[] =
'SafeObject';
if ($config->get('HTML', 'SafeEmbed')) {
$modules[] =
'SafeEmbed';
foreach ($modules as $module) {
$this->modules[$module]->setup($config);
foreach ($this->doctype->tidyModules as $module) {
$this->modules[$module]->setup($config);
foreach ($this->modules as $module) {
foreach ($module->info_injector as $i =>
$injector) {
$class =
"HTMLPurifier_Injector_$injector";
$n[$injector->name] =
$injector;
$module->info_injector =
$n;
// setup lookup table based on all valid modules
foreach ($this->modules as $module) {
foreach ($module->info as $name =>
$def) {
// note the different choice
// content set assembly deals with all possible modules,
// not just ones deemed to be "safe"
// there is no way to directly disable a global attribute,
// but using AllowedAttributes or simply not including
// the module in your custom doctype should be sufficient
* Takes a module and adds it to the active module collection,
* registering it if necessary.
* Retrieves merged element definitions.
* @return Array of HTMLPurifier_ElementDef
foreach ($this->modules as $module) {
if (!$this->trusted &&
!$module->safe) continue;
foreach ($module->info as $name =>
$v) {
if (isset
($elements[$name])) continue;
// remove dud elements, this happens when an element that
// appeared to be safe actually wasn't
foreach ($elements as $n =>
$v) {
if ($v ===
false) unset
($elements[$n]);
* Retrieves a single merged element definition
* @param $name Name of element
* @param $trusted Boolean trusted overriding parameter: set to true
* if you want the full version of an element
* @return Merged HTMLPurifier_ElementDef
* @note You may notice that modules are getting iterated over twice (once
* in getElements() and once here). This
public function getElement($name, $trusted =
null) {
// setup global state variables
if ($trusted ===
null) $trusted =
$this->trusted;
// iterate through each module that has registered itself to this
$module =
$this->modules[$module_name];
// refuse to create/merge from a module that is deemed unsafe--
// pretend the module doesn't exist--when trusted mode is not on.
if (!$trusted &&
!$module->safe) {
// clone is used because, ideally speaking, the original
// definition should not be modified. Usually, this will
// make no difference, but for consistency's sake
$new_def =
clone $module->info[$name];
if (!$def &&
$new_def->standalone) {
// This will occur even if $new_def is standalone. In practice,
// this will usually result in a full replacement.
// non-standalone definitions that don't have a standalone
// to merge into could be deferred to the end
// attribute value expansions
// descendants_are_inline, for ChildDef_Chameleon
strpos($def->content_model, 'Inline') !==
false) {
if ($name !=
'del' &&
$name !=
'ins') {
// this is for you, ins/del
$def->descendants_are_inline =
true;
// add information on required attributes
foreach ($def->attr as $attr_name =>
$attr_def) {
if ($attr_def->required) {
$def->required_attr[] =
$attr_name;
Documentation generated on Thu, 19 Jun 2008 18:49:31 -0400 by phpDocumentor 1.4.2