2007-02-15 14:00:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/HTMLModule.php';
|
2007-02-17 17:43:44 +00:00
|
|
|
require_once 'HTMLPurifier/ElementDef.php';
|
2007-05-14 01:58:05 +00:00
|
|
|
require_once 'HTMLPurifier/Doctype.php';
|
2007-05-15 00:31:53 +00:00
|
|
|
require_once 'HTMLPurifier/DoctypeRegistry.php';
|
2007-02-17 17:43:44 +00:00
|
|
|
|
|
|
|
require_once 'HTMLPurifier/ContentSets.php';
|
|
|
|
require_once 'HTMLPurifier/AttrTypes.php';
|
|
|
|
require_once 'HTMLPurifier/AttrCollections.php';
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/AttrDef.php';
|
|
|
|
require_once 'HTMLPurifier/AttrDef/Enum.php';
|
2007-02-15 14:00:18 +00:00
|
|
|
|
|
|
|
// W3C modules
|
2007-02-16 03:07:47 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule/CommonAttributes.php';
|
2007-02-15 14:00:18 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule/Text.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Hypertext.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/List.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Presentation.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Edit.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Bdo.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Tables.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Image.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/StyleAttribute.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Legacy.php';
|
2007-04-30 21:19:15 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule/Target.php';
|
2007-05-14 00:14:21 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule/Scripting.php';
|
2007-05-19 21:00:12 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule/XMLCommonAttributes.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/NonXMLCommonAttributes.php';
|
2007-08-02 22:44:42 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule/Ruby.php';
|
2007-02-15 14:00:18 +00:00
|
|
|
|
2007-05-19 21:00:12 +00:00
|
|
|
// tidy modules
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Tidy.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Tidy/XHTMLAndHTML4.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Tidy/XHTML.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Tidy/XHTMLStrict.php';
|
2007-05-20 02:12:01 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule/Tidy/Proprietary.php';
|
2007-02-15 14:00:18 +00:00
|
|
|
|
2007-02-18 05:29:19 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
2007-06-25 18:38:39 +00:00
|
|
|
'HTML', 'Doctype', '', 'string',
|
|
|
|
'Doctype to use during filtering. '.
|
2007-02-18 05:29:19 +00:00
|
|
|
'Technically speaking this is not actually a doctype (as it does '.
|
|
|
|
'not identify a corresponding DTD), but we are using this name '.
|
2007-06-25 18:38:39 +00:00
|
|
|
'for sake of simplicity. When non-blank, this will override any older directives '.
|
2007-06-24 22:22:00 +00:00
|
|
|
'like %HTML.XHTML or %HTML.Strict.'
|
2007-02-18 05:29:19 +00:00
|
|
|
);
|
2007-06-25 18:38:39 +00:00
|
|
|
HTMLPurifier_ConfigSchema::defineAllowedValues('HTML', 'Doctype', array(
|
|
|
|
'', 'HTML 4.01 Transitional', 'HTML 4.01 Strict',
|
|
|
|
'XHTML 1.0 Transitional', 'XHTML 1.0 Strict',
|
|
|
|
'XHTML 1.1'
|
|
|
|
));
|
|
|
|
|
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'CustomDoctype', null, 'string/null',
|
|
|
|
'
|
|
|
|
A custom doctype for power-users who defined there own document
|
|
|
|
type. This directive only applies when %HTML.Doctype is blank.
|
|
|
|
This directive has been available since 2.0.1.
|
|
|
|
'
|
|
|
|
);
|
2007-02-18 05:29:19 +00:00
|
|
|
|
2007-05-15 01:17:10 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'Trusted', false, 'bool',
|
|
|
|
'Indicates whether or not the user input is trusted or not. If the '.
|
|
|
|
'input is trusted, a more expansive set of allowed tags and attributes '.
|
2007-06-20 03:00:36 +00:00
|
|
|
'will be used. This directive has been available since 2.0.0.'
|
2007-05-15 01:17:10 +00:00
|
|
|
);
|
|
|
|
|
2007-05-20 22:29:31 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'AllowedModules', null, 'lookup/null', '
|
|
|
|
<p>
|
|
|
|
A doctype comes with a set of usual modules to use. Without having
|
|
|
|
to mucking about with the doctypes, you can quickly activate or
|
|
|
|
disable these modules by specifying which modules you wish to allow
|
|
|
|
with this directive. This is most useful for unit testing specific
|
|
|
|
modules, although end users may find it useful for their own ends.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
If you specify a module that does not exist, the manager will silently
|
|
|
|
fail to use it, so be careful! User-defined modules are not affected
|
|
|
|
by this directive. Modules defined in %HTML.CoreModules are not
|
2007-06-20 03:00:36 +00:00
|
|
|
affected by this directive. This directive has been available since 2.0.0.
|
2007-05-20 22:29:31 +00:00
|
|
|
</p>
|
|
|
|
');
|
|
|
|
|
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'CoreModules', array(
|
|
|
|
'Structure' => true,
|
|
|
|
'Text' => true,
|
|
|
|
'Hypertext' => true,
|
|
|
|
'List' => true,
|
|
|
|
'NonXMLCommonAttributes' => true,
|
|
|
|
'XMLCommonAttributes' => true,
|
|
|
|
'CommonAttributes' => true
|
|
|
|
), 'lookup', '
|
|
|
|
<p>
|
|
|
|
Certain modularized doctypes (XHTML, namely), have certain modules
|
|
|
|
that must be included for the doctype to be an conforming document
|
|
|
|
type: put those modules here. By default, XHTML\'s core modules
|
|
|
|
are used. You can set this to a blank array to disable core module
|
|
|
|
protection, but this is not recommended. This directive has been
|
2007-06-20 03:00:36 +00:00
|
|
|
available since 2.0.0.
|
2007-05-20 22:29:31 +00:00
|
|
|
</p>
|
|
|
|
');
|
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
class HTMLPurifier_HTMLModuleManager
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2007-05-15 00:31:53 +00:00
|
|
|
* Instance of HTMLPurifier_DoctypeRegistry
|
|
|
|
* @public
|
2007-02-15 14:00:18 +00:00
|
|
|
*/
|
2007-05-14 02:24:21 +00:00
|
|
|
var $doctypes;
|
2007-05-15 00:31:53 +00:00
|
|
|
|
2007-05-23 03:27:36 +00:00
|
|
|
/**
|
|
|
|
* Instance of current doctype
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $doctype;
|
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
/**
|
|
|
|
* Instance of HTMLPurifier_AttrTypes
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $attrTypes;
|
2007-02-15 14:00:18 +00:00
|
|
|
|
2007-02-17 22:17:14 +00:00
|
|
|
/**
|
2007-05-14 02:24:21 +00:00
|
|
|
* Active instances of modules for the specified doctype are
|
|
|
|
* indexed, by name, in this array.
|
2007-02-17 22:17:14 +00:00
|
|
|
*/
|
2007-05-14 02:24:21 +00:00
|
|
|
var $modules = array();
|
2007-02-17 22:17:14 +00:00
|
|
|
|
2007-05-14 00:14:21 +00:00
|
|
|
/**
|
2007-05-14 02:24:21 +00:00
|
|
|
* 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.
|
2007-05-14 00:14:21 +00:00
|
|
|
*/
|
2007-05-14 02:24:21 +00:00
|
|
|
var $registeredModules = array();
|
2007-05-14 00:14:21 +00:00
|
|
|
|
2007-05-15 02:33:19 +00:00
|
|
|
/**
|
|
|
|
* List of extra modules that were added by the user using addModule().
|
|
|
|
* These get unconditionally merged into the current doctype, whatever
|
|
|
|
* it may be.
|
|
|
|
*/
|
|
|
|
var $userModules = array();
|
|
|
|
|
2007-02-16 03:16:17 +00:00
|
|
|
/**
|
2007-05-14 02:24:21 +00:00
|
|
|
* Associative array of element name to list of modules that have
|
|
|
|
* definitions for the element; this array is dynamically filled.
|
2007-02-16 03:16:17 +00:00
|
|
|
*/
|
2007-02-17 22:17:14 +00:00
|
|
|
var $elementLookup = array();
|
2007-02-15 14:00:18 +00:00
|
|
|
|
2007-05-14 02:24:21 +00:00
|
|
|
/** List of prefixes we should use for registering small names */
|
2007-02-15 14:00:18 +00:00
|
|
|
var $prefixes = array('HTMLPurifier_HTMLModule_');
|
|
|
|
|
2007-05-14 02:24:21 +00:00
|
|
|
var $contentSets; /**< Instance of HTMLPurifier_ContentSets */
|
2007-02-15 14:00:18 +00:00
|
|
|
var $attrCollections; /**< Instance of HTMLPurifier_AttrCollections */
|
|
|
|
|
2007-05-14 00:14:21 +00:00
|
|
|
/** If set to true, unsafe elements and attributes will be allowed */
|
|
|
|
var $trusted = false;
|
|
|
|
|
2007-05-14 02:24:21 +00:00
|
|
|
function HTMLPurifier_HTMLModuleManager() {
|
2007-02-15 14:00:18 +00:00
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
// editable internal objects
|
2007-02-17 22:17:14 +00:00
|
|
|
$this->attrTypes = new HTMLPurifier_AttrTypes();
|
2007-05-15 00:31:53 +00:00
|
|
|
$this->doctypes = new HTMLPurifier_DoctypeRegistry();
|
2007-02-17 22:17:14 +00:00
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
// setup default HTML doctypes
|
2007-05-14 00:14:21 +00:00
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
// module reuse
|
2007-05-14 00:14:21 +00:00
|
|
|
$common = array(
|
|
|
|
'CommonAttributes', 'Text', 'Hypertext', 'List',
|
|
|
|
'Presentation', 'Edit', 'Bdo', 'Tables', 'Image',
|
|
|
|
'StyleAttribute', 'Scripting'
|
|
|
|
);
|
|
|
|
$transitional = array('Legacy', 'Target');
|
2007-05-19 21:00:12 +00:00
|
|
|
$xml = array('XMLCommonAttributes');
|
|
|
|
$non_xml = array('NonXMLCommonAttributes');
|
2007-05-14 00:14:21 +00:00
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
$this->doctypes->register(
|
2007-05-16 03:00:18 +00:00
|
|
|
'HTML 4.01 Transitional', false,
|
2007-05-19 21:00:12 +00:00
|
|
|
array_merge($common, $transitional, $non_xml),
|
2007-06-25 18:38:39 +00:00
|
|
|
array('Tidy_Transitional', 'Tidy_Proprietary'),
|
|
|
|
array(),
|
|
|
|
'-//W3C//DTD HTML 4.01 Transitional//EN',
|
|
|
|
'http://www.w3.org/TR/html4/loose.dtd'
|
2007-05-15 00:31:53 +00:00
|
|
|
);
|
2007-05-14 00:14:21 +00:00
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
$this->doctypes->register(
|
2007-05-16 03:00:18 +00:00
|
|
|
'HTML 4.01 Strict', false,
|
2007-05-19 21:00:12 +00:00
|
|
|
array_merge($common, $non_xml),
|
2007-06-25 18:38:39 +00:00
|
|
|
array('Tidy_Strict', 'Tidy_Proprietary'),
|
|
|
|
array(),
|
|
|
|
'-//W3C//DTD HTML 4.01//EN',
|
|
|
|
'http://www.w3.org/TR/html4/strict.dtd'
|
2007-05-15 00:31:53 +00:00
|
|
|
);
|
2007-05-14 00:14:21 +00:00
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
$this->doctypes->register(
|
2007-05-16 03:00:18 +00:00
|
|
|
'XHTML 1.0 Transitional', true,
|
2007-05-19 21:00:12 +00:00
|
|
|
array_merge($common, $transitional, $xml, $non_xml),
|
2007-06-25 18:38:39 +00:00
|
|
|
array('Tidy_Transitional', 'Tidy_XHTML', 'Tidy_Proprietary'),
|
|
|
|
array(),
|
|
|
|
'-//W3C//DTD XHTML 1.0 Transitional//EN',
|
|
|
|
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
|
2007-05-15 00:31:53 +00:00
|
|
|
);
|
2007-05-14 00:14:21 +00:00
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
$this->doctypes->register(
|
2007-05-16 03:00:18 +00:00
|
|
|
'XHTML 1.0 Strict', true,
|
2007-05-19 21:00:12 +00:00
|
|
|
array_merge($common, $xml, $non_xml),
|
2007-06-25 18:38:39 +00:00
|
|
|
array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_XHTMLStrict', 'Tidy_Proprietary'),
|
|
|
|
array(),
|
|
|
|
'-//W3C//DTD XHTML 1.0 Strict//EN',
|
|
|
|
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
|
2007-05-15 00:31:53 +00:00
|
|
|
);
|
2007-05-14 00:14:21 +00:00
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
$this->doctypes->register(
|
2007-05-16 03:00:18 +00:00
|
|
|
'XHTML 1.1', true,
|
2007-08-02 22:44:42 +00:00
|
|
|
array_merge($common, $xml, array('Ruby')),
|
2007-07-11 20:06:15 +00:00
|
|
|
array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Proprietary', 'Tidy_XHTMLStrict'), // Tidy_XHTML1_1
|
2007-06-25 18:38:39 +00:00
|
|
|
array(),
|
|
|
|
'-//W3C//DTD XHTML 1.1//EN',
|
|
|
|
'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'
|
2007-05-15 00:31:53 +00:00
|
|
|
);
|
2007-05-14 00:14:21 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-05-14 02:24:21 +00:00
|
|
|
* Registers a module to the recognized module list, useful for
|
|
|
|
* overloading pre-existing modules.
|
2007-02-15 14:00:18 +00:00
|
|
|
* @param $module Mixed: string module name, with or without
|
|
|
|
* HTMLPurifier_HTMLModule prefix, or instance of
|
|
|
|
* subclass of HTMLPurifier_HTMLModule.
|
2007-04-21 02:19:18 +00:00
|
|
|
* @note This function will not call autoload, you must instantiate
|
|
|
|
* (and thus invoke) autoload outside the method.
|
2007-04-21 02:31:38 +00:00
|
|
|
* @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
|
|
|
|
* - Throw fatal error
|
|
|
|
* If your object name collides with an internal class, specify
|
2007-05-14 02:24:21 +00:00
|
|
|
* your module manually. All modules must have been included
|
|
|
|
* externally: registerModule will not perform inclusions for you!
|
2007-05-14 01:58:05 +00:00
|
|
|
* @warning If your module has the same name as an already loaded
|
|
|
|
* module, your module will overload the old one WITHOUT
|
|
|
|
* warning.
|
2007-02-15 14:00:18 +00:00
|
|
|
*/
|
2007-05-14 02:24:21 +00:00
|
|
|
function registerModule($module) {
|
2007-02-15 14:00:18 +00:00
|
|
|
if (is_string($module)) {
|
2007-05-14 02:24:21 +00:00
|
|
|
// attempt to load the module
|
2007-02-15 14:00:18 +00:00
|
|
|
$original_module = $module;
|
2007-04-21 02:31:38 +00:00
|
|
|
$ok = false;
|
|
|
|
foreach ($this->prefixes as $prefix) {
|
|
|
|
$module = $prefix . $original_module;
|
2007-05-05 20:04:34 +00:00
|
|
|
if ($this->_classExists($module)) {
|
2007-04-21 02:31:38 +00:00
|
|
|
$ok = true;
|
|
|
|
break;
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-21 02:31:38 +00:00
|
|
|
if (!$ok) {
|
|
|
|
$module = $original_module;
|
2007-05-05 20:04:34 +00:00
|
|
|
if (!$this->_classExists($module)) {
|
2007-04-21 02:31:38 +00:00
|
|
|
trigger_error($original_module . ' module does not exist',
|
|
|
|
E_USER_ERROR);
|
|
|
|
return;
|
|
|
|
}
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
|
|
|
$module = new $module();
|
|
|
|
}
|
2007-05-19 21:00:12 +00:00
|
|
|
if (empty($module->name)) {
|
|
|
|
trigger_error('Module instance of ' . get_class($module) . ' must have name');
|
|
|
|
return;
|
|
|
|
}
|
2007-05-14 02:24:21 +00:00
|
|
|
$this->registeredModules[$module->name] = $module;
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
|
|
|
|
2007-05-05 20:04:34 +00:00
|
|
|
/**
|
|
|
|
* Safely tests for class existence without invoking __autoload in PHP5
|
2007-05-14 01:58:05 +00:00
|
|
|
* or greater.
|
2007-05-05 20:04:34 +00:00
|
|
|
* @param $name String class name to test
|
2007-05-14 02:24:21 +00:00
|
|
|
* @note If any other class needs it, we'll need to stash in a
|
|
|
|
* conjectured "compatibility" class
|
2007-05-05 20:04:34 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function _classExists($name) {
|
|
|
|
static $is_php_4 = null;
|
|
|
|
if ($is_php_4 === null) {
|
|
|
|
$is_php_4 = version_compare(PHP_VERSION, '5', '<');
|
|
|
|
}
|
|
|
|
if ($is_php_4) {
|
|
|
|
return class_exists($name);
|
|
|
|
} else {
|
|
|
|
return class_exists($name, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-17 19:37:48 +00:00
|
|
|
/**
|
2007-05-14 02:24:21 +00:00
|
|
|
* Adds a module to the current doctype by first registering it,
|
|
|
|
* and then tacking it on to the active doctype
|
|
|
|
*/
|
|
|
|
function addModule($module) {
|
2007-05-15 02:33:19 +00:00
|
|
|
$this->registerModule($module);
|
|
|
|
if (is_object($module)) $module = $module->name;
|
|
|
|
$this->userModules[] = $module;
|
2007-05-14 02:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a class prefix that registerModule() will use to resolve a
|
2007-02-17 19:37:48 +00:00
|
|
|
* string name to a concrete class
|
|
|
|
*/
|
|
|
|
function addPrefix($prefix) {
|
2007-05-14 02:24:21 +00:00
|
|
|
$this->prefixes[] = $prefix;
|
2007-02-17 19:37:48 +00:00
|
|
|
}
|
|
|
|
|
2007-05-14 01:58:05 +00:00
|
|
|
/**
|
|
|
|
* Performs processing on modules, after being called you may
|
|
|
|
* use getElement() and getElements()
|
|
|
|
* @param $config Instance of HTMLPurifier_Config
|
|
|
|
*/
|
2007-02-15 14:00:18 +00:00
|
|
|
function setup($config) {
|
2007-02-18 05:29:19 +00:00
|
|
|
|
2007-05-15 01:17:10 +00:00
|
|
|
$this->trusted = $config->get('HTML', 'Trusted');
|
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
// generate
|
2007-05-23 03:27:36 +00:00
|
|
|
$this->doctype = $this->doctypes->make($config);
|
|
|
|
$modules = $this->doctype->modules;
|
2007-05-14 00:14:21 +00:00
|
|
|
|
2007-05-20 22:29:31 +00:00
|
|
|
// take out the default modules that aren't allowed
|
|
|
|
$lookup = $config->get('HTML', 'AllowedModules');
|
|
|
|
$special_cases = $config->get('HTML', 'CoreModules');
|
|
|
|
|
|
|
|
if (is_array($lookup)) {
|
|
|
|
foreach ($modules as $k => $m) {
|
|
|
|
if (isset($special_cases[$m])) continue;
|
|
|
|
if (!isset($lookup[$m])) unset($modules[$k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-15 02:33:19 +00:00
|
|
|
// merge in custom modules
|
|
|
|
$modules = array_merge($modules, $this->userModules);
|
|
|
|
|
2007-05-14 00:14:21 +00:00
|
|
|
foreach ($modules as $module) {
|
2007-05-16 03:00:18 +00:00
|
|
|
$this->processModule($module);
|
|
|
|
}
|
|
|
|
|
2007-05-23 03:27:36 +00:00
|
|
|
foreach ($this->doctype->tidyModules as $module) {
|
2007-05-16 03:00:18 +00:00
|
|
|
$this->processModule($module);
|
2007-05-19 21:00:12 +00:00
|
|
|
if (method_exists($this->modules[$module], 'construct')) {
|
|
|
|
$this->modules[$module]->construct($config);
|
|
|
|
}
|
2007-05-14 00:14:21 +00:00
|
|
|
}
|
|
|
|
|
2007-02-16 03:33:29 +00:00
|
|
|
// setup lookup table based on all valid modules
|
2007-05-14 02:24:21 +00:00
|
|
|
foreach ($this->modules as $module) {
|
2007-02-18 05:29:19 +00:00
|
|
|
foreach ($module->info as $name => $def) {
|
2007-02-17 22:17:14 +00:00
|
|
|
if (!isset($this->elementLookup[$name])) {
|
|
|
|
$this->elementLookup[$name] = array();
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
2007-02-17 22:17:14 +00:00
|
|
|
$this->elementLookup[$name][] = $module->name;
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-16 03:33:29 +00:00
|
|
|
// note the different choice
|
2007-02-15 14:00:18 +00:00
|
|
|
$this->contentSets = new HTMLPurifier_ContentSets(
|
2007-05-14 01:03:21 +00:00
|
|
|
// content set assembly deals with all possible modules,
|
|
|
|
// not just ones deemed to be "safe"
|
2007-05-14 02:24:21 +00:00
|
|
|
$this->modules
|
2007-02-16 03:33:29 +00:00
|
|
|
);
|
|
|
|
$this->attrCollections = new HTMLPurifier_AttrCollections(
|
|
|
|
$this->attrTypes,
|
2007-05-14 01:03:21 +00:00
|
|
|
// 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
|
2007-05-14 02:24:21 +00:00
|
|
|
$this->modules
|
2007-02-15 14:00:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-05-16 03:00:18 +00:00
|
|
|
/**
|
|
|
|
* Takes a module and adds it to the active module collection,
|
|
|
|
* registering it if necessary.
|
|
|
|
*/
|
|
|
|
function processModule($module) {
|
|
|
|
if (!isset($this->registeredModules[$module]) || is_object($module)) {
|
|
|
|
$this->registerModule($module);
|
|
|
|
}
|
|
|
|
$this->modules[$module] = $this->registeredModules[$module];
|
|
|
|
}
|
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
/**
|
2007-05-14 00:14:21 +00:00
|
|
|
* Retrieves merged element definitions.
|
2007-05-14 02:24:21 +00:00
|
|
|
* @return Array of HTMLPurifier_ElementDef
|
2007-02-15 14:00:18 +00:00
|
|
|
*/
|
2007-05-15 02:33:19 +00:00
|
|
|
function getElements() {
|
2007-02-15 14:00:18 +00:00
|
|
|
|
|
|
|
$elements = array();
|
2007-05-14 02:24:21 +00:00
|
|
|
foreach ($this->modules as $module) {
|
2007-05-05 20:04:34 +00:00
|
|
|
foreach ($module->info as $name => $v) {
|
|
|
|
if (isset($elements[$name])) continue;
|
2007-05-14 00:14:21 +00:00
|
|
|
// if element is not safe, don't use it
|
|
|
|
if (!$this->trusted && ($v->safe === false)) continue;
|
2007-05-15 02:33:19 +00:00
|
|
|
$elements[$name] = $this->getElement($name);
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-14 02:24:21 +00:00
|
|
|
// remove dud elements, this happens when an element that
|
|
|
|
// appeared to be safe actually wasn't
|
2007-05-14 00:14:21 +00:00
|
|
|
foreach ($elements as $n => $v) {
|
|
|
|
if ($v === false) unset($elements[$n]);
|
|
|
|
}
|
2007-02-17 17:10:28 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
return $elements;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-02-17 17:10:28 +00:00
|
|
|
/**
|
|
|
|
* Retrieves a single merged element definition
|
|
|
|
* @param $name Name of element
|
2007-05-14 01:58:05 +00:00
|
|
|
* @param $trusted Boolean trusted overriding parameter: set to true
|
|
|
|
* if you want the full version of an element
|
2007-05-14 02:24:21 +00:00
|
|
|
* @return Merged HTMLPurifier_ElementDef
|
2007-02-17 17:10:28 +00:00
|
|
|
*/
|
2007-05-15 02:33:19 +00:00
|
|
|
function getElement($name, $trusted = null) {
|
2007-02-15 14:00:18 +00:00
|
|
|
|
|
|
|
$def = false;
|
2007-05-14 01:58:05 +00:00
|
|
|
if ($trusted === null) $trusted = $this->trusted;
|
2007-02-15 14:00:18 +00:00
|
|
|
|
2007-05-14 02:24:21 +00:00
|
|
|
$modules = $this->modules;
|
2007-02-15 14:00:18 +00:00
|
|
|
|
2007-02-17 22:17:14 +00:00
|
|
|
if (!isset($this->elementLookup[$name])) {
|
2007-02-15 14:00:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-02-17 22:17:14 +00:00
|
|
|
foreach($this->elementLookup[$name] as $module_name) {
|
2007-02-15 14:00:18 +00:00
|
|
|
|
|
|
|
$module = $modules[$module_name];
|
2007-06-20 21:39:28 +00:00
|
|
|
|
|
|
|
// copy 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 = $module->info[$name]->copy();
|
2007-02-15 14:00:18 +00:00
|
|
|
|
2007-05-14 00:14:21 +00:00
|
|
|
// refuse to create/merge in a definition that is deemed unsafe
|
2007-05-14 01:58:05 +00:00
|
|
|
if (!$trusted && ($new_def->safe === false)) {
|
2007-05-14 00:14:21 +00:00
|
|
|
$def = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
if (!$def && $new_def->standalone) {
|
2007-05-14 00:14:21 +00:00
|
|
|
// element with unknown safety is not to be trusted.
|
|
|
|
// however, a merge-in definition with undefined safety
|
|
|
|
// is fine
|
2007-05-15 01:17:10 +00:00
|
|
|
if (!$trusted && !$new_def->safe) continue;
|
2007-02-15 14:00:18 +00:00
|
|
|
$def = $new_def;
|
|
|
|
} elseif ($def) {
|
|
|
|
$def->mergeIn($new_def);
|
|
|
|
} else {
|
2007-02-17 22:17:14 +00:00
|
|
|
// could "save it for another day":
|
2007-02-17 17:10:28 +00:00
|
|
|
// non-standalone definitions that don't have a standalone
|
|
|
|
// to merge into could be deferred to the end
|
2007-02-15 14:00:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attribute value expansions
|
|
|
|
$this->attrCollections->performInclusions($def->attr);
|
|
|
|
$this->attrCollections->expandIdentifiers($def->attr, $this->attrTypes);
|
|
|
|
|
|
|
|
// descendants_are_inline, for ChildDef_Chameleon
|
|
|
|
if (is_string($def->content_model) &&
|
|
|
|
strpos($def->content_model, 'Inline') !== false) {
|
|
|
|
if ($name != 'del' && $name != 'ins') {
|
|
|
|
// this is for you, ins/del
|
|
|
|
$def->descendants_are_inline = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->contentSets->generateChildDef($def, $module);
|
|
|
|
}
|
2007-06-20 21:39:28 +00:00
|
|
|
|
|
|
|
// add information on required attributes
|
|
|
|
foreach ($def->attr as $attr_name => $attr_def) {
|
|
|
|
if ($attr_def->required) {
|
|
|
|
$def->required_attr[] = $attr_name;
|
|
|
|
}
|
|
|
|
}
|
2007-02-15 14:00:18 +00:00
|
|
|
|
|
|
|
return $def;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-06-27 13:58:32 +00:00
|
|
|
|