2007-02-15 14:00:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_HTMLModuleManager
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
/**
|
2007-05-15 00:31:53 +00:00
|
|
|
* Instance of HTMLPurifier_DoctypeRegistry
|
2007-02-15 14:00:18 +00:00
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public $doctypes;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-23 03:27:36 +00:00
|
|
|
/**
|
|
|
|
* Instance of current doctype
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public $doctype;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-15 00:31:53 +00:00
|
|
|
/**
|
|
|
|
* Instance of HTMLPurifier_AttrTypes
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public $attrTypes;
|
2008-12-06 07:28:20 +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-11-25 02:24:39 +00:00
|
|
|
public $modules = array();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-14 00:14:21 +00:00
|
|
|
/**
|
2008-12-06 07:28:20 +00:00
|
|
|
* Array of recognized HTMLPurifier_Module instances, indexed by
|
2007-05-14 02:24:21 +00:00
|
|
|
* 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-11-25 02:24:39 +00:00
|
|
|
public $registeredModules = array();
|
2008-12-06 07:28:20 +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.
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public $userModules = array();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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-11-25 02:24:39 +00:00
|
|
|
public $elementLookup = array();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-14 02:24:21 +00:00
|
|
|
/** List of prefixes we should use for registering small names */
|
2007-11-25 02:24:39 +00:00
|
|
|
public $prefixes = array('HTMLPurifier_HTMLModule_');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-11-25 02:24:39 +00:00
|
|
|
public $contentSets; /**< Instance of HTMLPurifier_ContentSets */
|
|
|
|
public $attrCollections; /**< Instance of HTMLPurifier_AttrCollections */
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-14 00:14:21 +00:00
|
|
|
/** If set to true, unsafe elements and attributes will be allowed */
|
2007-11-25 02:24:39 +00:00
|
|
|
public $trusted = false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-11-29 04:29:51 +00:00
|
|
|
public function __construct() {
|
2008-12-06 07:28:20 +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();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 23:28:52 +00:00
|
|
|
// setup basic modules
|
2007-05-14 00:14:21 +00:00
|
|
|
$common = array(
|
|
|
|
'CommonAttributes', 'Text', 'Hypertext', 'List',
|
|
|
|
'Presentation', 'Edit', 'Bdo', 'Tables', 'Image',
|
2008-08-15 22:57:44 +00:00
|
|
|
'StyleAttribute',
|
|
|
|
// Unsafe:
|
Implement Iframe module, and provide %HTML.SafeIframe and %URI.SafeIframeRegexp for untrusted usage.
The purpose of this addition is twofold. In trusted mode, iframes are
now unconditionally allowed.
However, many online video providers (YouTube, Vimeo) and other web
applications (Google Maps, Google Calendar, etc) provide embed code in
iframe format, which is useful functionality in untrusted mode.
You can specify iframes as trusted elements with %HTML.SafeIframe;
however, you need to additionally specify a whitelist mechanism such as
%URI.SafeIframeRegexp to say what iframe embeds are OK (by default
everything is rejected).
Note: As iframes are invalid in strict doctypes, you will not be able to
use them there.
We also added an always_load parameter to URIFilters in order to support
the strange nature of the SafeIframe URIFilter (it always needs to be
loaded, due to the inability of accessing the %HTML.SafeIframe directive
to see if it's needed!) We expect this URIFilter can expand in the future
to offer more complex validation mechanisms.
Signed-off-by: Bradley M. Froehle <brad.froehle@gmail.com>
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
2011-02-14 01:47:01 +00:00
|
|
|
'Scripting', 'Object', 'Forms',
|
2008-08-15 22:57:44 +00:00
|
|
|
// Sorta legacy, but present in strict:
|
2008-12-06 07:28:20 +00:00
|
|
|
'Name',
|
2007-05-14 00:14:21 +00:00
|
|
|
);
|
Implement Iframe module, and provide %HTML.SafeIframe and %URI.SafeIframeRegexp for untrusted usage.
The purpose of this addition is twofold. In trusted mode, iframes are
now unconditionally allowed.
However, many online video providers (YouTube, Vimeo) and other web
applications (Google Maps, Google Calendar, etc) provide embed code in
iframe format, which is useful functionality in untrusted mode.
You can specify iframes as trusted elements with %HTML.SafeIframe;
however, you need to additionally specify a whitelist mechanism such as
%URI.SafeIframeRegexp to say what iframe embeds are OK (by default
everything is rejected).
Note: As iframes are invalid in strict doctypes, you will not be able to
use them there.
We also added an always_load parameter to URIFilters in order to support
the strange nature of the SafeIframe URIFilter (it always needs to be
loaded, due to the inability of accessing the %HTML.SafeIframe directive
to see if it's needed!) We expect this URIFilter can expand in the future
to offer more complex validation mechanisms.
Signed-off-by: Bradley M. Froehle <brad.froehle@gmail.com>
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
2011-02-14 01:47:01 +00:00
|
|
|
$transitional = array('Legacy', 'Target', 'Iframe');
|
2007-05-19 21:00:12 +00:00
|
|
|
$xml = array('XMLCommonAttributes');
|
|
|
|
$non_xml = array('NonXMLCommonAttributes');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 23:28:52 +00:00
|
|
|
// setup basic doctypes
|
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
|
|
|
);
|
2008-12-06 07:28:20 +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),
|
2008-06-27 19:44:27 +00:00
|
|
|
array('Tidy_Strict', 'Tidy_Proprietary', 'Tidy_Name'),
|
2007-06-25 18:38:39 +00:00
|
|
|
array(),
|
|
|
|
'-//W3C//DTD HTML 4.01//EN',
|
|
|
|
'http://www.w3.org/TR/html4/strict.dtd'
|
2007-05-15 00:31:53 +00:00
|
|
|
);
|
2008-12-06 07:28:20 +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),
|
2008-06-27 19:44:27 +00:00
|
|
|
array('Tidy_Transitional', 'Tidy_XHTML', 'Tidy_Proprietary', 'Tidy_Name'),
|
2007-06-25 18:38:39 +00:00
|
|
|
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
|
|
|
);
|
2008-12-06 07:28:20 +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),
|
2008-06-27 19:44:27 +00:00
|
|
|
array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Strict', 'Tidy_Proprietary', 'Tidy_Name'),
|
2007-06-25 18:38:39 +00:00
|
|
|
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
|
|
|
);
|
2008-12-06 07:28:20 +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,
|
Implement Iframe module, and provide %HTML.SafeIframe and %URI.SafeIframeRegexp for untrusted usage.
The purpose of this addition is twofold. In trusted mode, iframes are
now unconditionally allowed.
However, many online video providers (YouTube, Vimeo) and other web
applications (Google Maps, Google Calendar, etc) provide embed code in
iframe format, which is useful functionality in untrusted mode.
You can specify iframes as trusted elements with %HTML.SafeIframe;
however, you need to additionally specify a whitelist mechanism such as
%URI.SafeIframeRegexp to say what iframe embeds are OK (by default
everything is rejected).
Note: As iframes are invalid in strict doctypes, you will not be able to
use them there.
We also added an always_load parameter to URIFilters in order to support
the strange nature of the SafeIframe URIFilter (it always needs to be
loaded, due to the inability of accessing the %HTML.SafeIframe directive
to see if it's needed!) We expect this URIFilter can expand in the future
to offer more complex validation mechanisms.
Signed-off-by: Bradley M. Froehle <brad.froehle@gmail.com>
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
2011-02-14 01:47:01 +00:00
|
|
|
// Iframe is a real XHTML 1.1 module, despite being
|
|
|
|
// "transitional"!
|
|
|
|
array_merge($common, $xml, array('Ruby', 'Iframe')),
|
2008-06-27 19:44:27 +00:00
|
|
|
array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Proprietary', 'Tidy_Strict', 'Tidy_Name'), // 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
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +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.
|
2008-04-21 23:28:52 +00:00
|
|
|
* @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.
|
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-02-15 14:00:18 +00:00
|
|
|
*/
|
2008-04-21 23:28:52 +00:00
|
|
|
public function registerModule($module, $overload = false) {
|
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;
|
2008-02-10 21:34:52 +00:00
|
|
|
if (class_exists($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;
|
2008-02-10 21:34:52 +00:00
|
|
|
if (!class_exists($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;
|
|
|
|
}
|
2008-04-21 23:28:52 +00:00
|
|
|
if (!$overload && isset($this->registeredModules[$module->name])) {
|
|
|
|
trigger_error('Overloading ' . $module->name . ' without explicit overload parameter', E_USER_WARNING);
|
|
|
|
}
|
2007-05-14 02:24:21 +00:00
|
|
|
$this->registeredModules[$module->name] = $module;
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public 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
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public function addPrefix($prefix) {
|
2007-05-14 02:24:21 +00:00
|
|
|
$this->prefixes[] = $prefix;
|
2007-02-17 19:37:48 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +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-11-25 02:24:39 +00:00
|
|
|
public function setup($config) {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->trusted = $config->get('HTML.Trusted');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-20 22:29:31 +00:00
|
|
|
// take out the default modules that aren't allowed
|
2009-02-20 00:17:49 +00:00
|
|
|
$lookup = $config->get('HTML.AllowedModules');
|
|
|
|
$special_cases = $config->get('HTML.CoreModules');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-20 22:29:31 +00:00
|
|
|
if (is_array($lookup)) {
|
|
|
|
foreach ($modules as $k => $m) {
|
|
|
|
if (isset($special_cases[$m])) continue;
|
|
|
|
if (!isset($lookup[$m])) unset($modules[$k]);
|
|
|
|
}
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2010-09-28 16:01:57 +00:00
|
|
|
// custom modules
|
2009-02-20 00:17:49 +00:00
|
|
|
if ($config->get('HTML.Proprietary')) {
|
2008-02-20 00:53:09 +00:00
|
|
|
$modules[] = 'Proprietary';
|
|
|
|
}
|
2009-02-20 00:17:49 +00:00
|
|
|
if ($config->get('HTML.SafeObject')) {
|
2008-06-10 01:18:03 +00:00
|
|
|
$modules[] = 'SafeObject';
|
|
|
|
}
|
2009-02-20 00:17:49 +00:00
|
|
|
if ($config->get('HTML.SafeEmbed')) {
|
2008-06-10 01:18:03 +00:00
|
|
|
$modules[] = 'SafeEmbed';
|
|
|
|
}
|
2010-09-28 16:01:57 +00:00
|
|
|
if ($config->get('HTML.Nofollow')) {
|
|
|
|
$modules[] = 'Nofollow';
|
|
|
|
}
|
2011-12-25 09:27:25 +00:00
|
|
|
if ($config->get('HTML.TargetBlank')) {
|
|
|
|
$modules[] = 'TargetBlank';
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-08-31 23:06:25 +00:00
|
|
|
// merge in custom modules
|
|
|
|
$modules = array_merge($modules, $this->userModules);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-14 00:14:21 +00:00
|
|
|
foreach ($modules as $module) {
|
2007-05-16 03:00:18 +00:00
|
|
|
$this->processModule($module);
|
2008-05-22 04:34:19 +00:00
|
|
|
$this->modules[$module]->setup($config);
|
2007-05-16 03:00:18 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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);
|
2008-05-22 04:34:19 +00:00
|
|
|
$this->modules[$module]->setup($config);
|
2007-05-14 00:14:21 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-09 01:23:05 +00:00
|
|
|
// prepare any injectors
|
|
|
|
foreach ($this->modules as $module) {
|
|
|
|
$n = array();
|
|
|
|
foreach ($module->info_injector as $i => $injector) {
|
|
|
|
if (!is_object($injector)) {
|
|
|
|
$class = "HTMLPurifier_Injector_$injector";
|
|
|
|
$injector = new $class;
|
|
|
|
}
|
|
|
|
$n[$injector->name] = $injector;
|
|
|
|
}
|
|
|
|
$module->info_injector = $n;
|
|
|
|
}
|
2008-12-06 07:28:20 +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
|
|
|
}
|
|
|
|
}
|
2008-12-06 07:28:20 +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
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +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.
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public function processModule($module) {
|
2007-05-16 03:00:18 +00:00
|
|
|
if (!isset($this->registeredModules[$module]) || is_object($module)) {
|
|
|
|
$this->registerModule($module);
|
|
|
|
}
|
|
|
|
$this->modules[$module] = $this->registeredModules[$module];
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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-11-25 02:24:39 +00:00
|
|
|
public function getElements() {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
$elements = array();
|
2007-05-14 02:24:21 +00:00
|
|
|
foreach ($this->modules as $module) {
|
2008-04-21 23:28:52 +00:00
|
|
|
if (!$this->trusted && !$module->safe) continue;
|
2007-05-05 20:04:34 +00:00
|
|
|
foreach ($module->info as $name => $v) {
|
|
|
|
if (isset($elements[$name])) continue;
|
2007-05-15 02:33:19 +00:00
|
|
|
$elements[$name] = $this->getElement($name);
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-06 07:28:20 +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]);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
return $elements;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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
|
2008-04-21 23:28:52 +00:00
|
|
|
* @note You may notice that modules are getting iterated over twice (once
|
|
|
|
* in getElements() and once here). This
|
2008-12-06 07:28:20 +00:00
|
|
|
* is because
|
2007-02-17 17:10:28 +00:00
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public function getElement($name, $trusted = null) {
|
2008-12-06 07:28:20 +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;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 23:28:52 +00:00
|
|
|
// setup global state variables
|
|
|
|
$def = false;
|
|
|
|
if ($trusted === null) $trusted = $this->trusted;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 23:28:52 +00:00
|
|
|
// iterate through each module that has registered itself to this
|
|
|
|
// element
|
2007-02-17 22:17:14 +00:00
|
|
|
foreach($this->elementLookup[$name] as $module_name) {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 23:28:52 +00:00
|
|
|
$module = $this->modules[$module_name];
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 23:28:52 +00:00
|
|
|
// 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) {
|
2007-05-14 00:14:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 23:28:52 +00:00
|
|
|
// 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];
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
if (!$def && $new_def->standalone) {
|
|
|
|
$def = $new_def;
|
|
|
|
} elseif ($def) {
|
2008-04-21 23:28:52 +00:00
|
|
|
// This will occur even if $new_def is standalone. In practice,
|
|
|
|
// this will usually result in a full replacement.
|
2007-02-15 14:00:18 +00:00
|
|
|
$def->mergeIn($new_def);
|
|
|
|
} else {
|
2008-04-21 23:28:52 +00:00
|
|
|
// :TODO:
|
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;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
// attribute value expansions
|
|
|
|
$this->attrCollections->performInclusions($def->attr);
|
|
|
|
$this->attrCollections->expandIdentifiers($def->attr, $this->attrTypes);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
$this->contentSets->generateChildDef($def, $module);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-27 19:44:27 +00:00
|
|
|
// This can occur if there is a blank definition, but no base to
|
|
|
|
// mix it in with
|
|
|
|
if (!$def) return false;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
return $def;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-02-15 14:00:18 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|