mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-02 20:27:40 +02:00
Remove trailing whitespace.
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
@@ -3,20 +3,20 @@
|
||||
/**
|
||||
* Definition of the purified HTML that describes allowed children,
|
||||
* attributes, and many other things.
|
||||
*
|
||||
*
|
||||
* Conventions:
|
||||
*
|
||||
*
|
||||
* All member variables that are prefixed with info
|
||||
* (including the main $info array) are used by HTML Purifier internals
|
||||
* and should not be directly edited when customizing the HTMLDefinition.
|
||||
* They can usually be set via configuration directives or custom
|
||||
* modules.
|
||||
*
|
||||
*
|
||||
* On the other hand, member variables without the info prefix are used
|
||||
* internally by the HTMLDefinition and MUST NOT be used by other HTML
|
||||
* Purifier internals. Many of them, however, are public, and may be
|
||||
* edited by userspace code to tweak the behavior of HTMLDefinition.
|
||||
*
|
||||
*
|
||||
* @note This class is inspected by Printer_HTMLDefinition; please
|
||||
* update that class if things here change.
|
||||
*
|
||||
@@ -25,71 +25,71 @@
|
||||
*/
|
||||
class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
{
|
||||
|
||||
|
||||
// FULLY-PUBLIC VARIABLES ---------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Associative array of element names to HTMLPurifier_ElementDef
|
||||
*/
|
||||
public $info = array();
|
||||
|
||||
|
||||
/**
|
||||
* Associative array of global attribute name to attribute definition.
|
||||
*/
|
||||
public $info_global_attr = array();
|
||||
|
||||
|
||||
/**
|
||||
* String name of parent element HTML will be going into.
|
||||
*/
|
||||
public $info_parent = 'div';
|
||||
|
||||
|
||||
/**
|
||||
* Definition for parent element, allows parent element to be a
|
||||
* tag that's not allowed inside the HTML fragment.
|
||||
*/
|
||||
public $info_parent_def;
|
||||
|
||||
|
||||
/**
|
||||
* String name of element used to wrap inline elements in block context
|
||||
* @note This is rarely used except for BLOCKQUOTEs in strict mode
|
||||
*/
|
||||
public $info_block_wrapper = 'p';
|
||||
|
||||
|
||||
/**
|
||||
* Associative array of deprecated tag name to HTMLPurifier_TagTransform
|
||||
*/
|
||||
public $info_tag_transform = array();
|
||||
|
||||
|
||||
/**
|
||||
* Indexed list of HTMLPurifier_AttrTransform to be performed before validation.
|
||||
*/
|
||||
public $info_attr_transform_pre = array();
|
||||
|
||||
|
||||
/**
|
||||
* Indexed list of HTMLPurifier_AttrTransform to be performed after validation.
|
||||
*/
|
||||
public $info_attr_transform_post = array();
|
||||
|
||||
|
||||
/**
|
||||
* Nested lookup array of content set name (Block, Inline) to
|
||||
* element name to whether or not it belongs in that content set.
|
||||
*/
|
||||
public $info_content_sets = array();
|
||||
|
||||
|
||||
/**
|
||||
* Indexed list of HTMLPurifier_Injector to be used.
|
||||
*/
|
||||
public $info_injector = array();
|
||||
|
||||
|
||||
/**
|
||||
* Doctype object
|
||||
*/
|
||||
public $doctype;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// RAW CUSTOMIZATION STUFF --------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Adds a custom attribute to a pre-existing element
|
||||
* @note This is strictly convenience, and does not have a corresponding
|
||||
@@ -108,10 +108,10 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
}
|
||||
$element->attr[$attr_name] = $def;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a custom element to your HTML definition
|
||||
* @note See HTMLPurifier_HTMLModule::addElement for detailed
|
||||
* @note See HTMLPurifier_HTMLModule::addElement for detailed
|
||||
* parameter and return value descriptions.
|
||||
*/
|
||||
public function addElement($element_name, $type, $contents, $attr_collections, $attributes) {
|
||||
@@ -121,7 +121,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
$element = $module->addElement($element_name, $type, $contents, $attr_collections, $attributes);
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a blank element to your HTML definition, for overriding
|
||||
* existing behavior
|
||||
@@ -133,7 +133,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
$element = $module->addBlankElement($element_name);
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a reference to the anonymous module, so you can
|
||||
* bust out advanced features without having to make your own
|
||||
@@ -146,39 +146,39 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
}
|
||||
return $this->_anonModule;
|
||||
}
|
||||
|
||||
|
||||
private $_anonModule;
|
||||
|
||||
|
||||
|
||||
|
||||
// PUBLIC BUT INTERNAL VARIABLES --------------------------------------
|
||||
|
||||
|
||||
public $type = 'HTML';
|
||||
public $manager; /**< Instance of HTMLPurifier_HTMLModuleManager */
|
||||
|
||||
|
||||
/**
|
||||
* Performs low-cost, preliminary initialization.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->manager = new HTMLPurifier_HTMLModuleManager();
|
||||
}
|
||||
|
||||
|
||||
protected function doSetup($config) {
|
||||
$this->processModules($config);
|
||||
$this->setupConfigStuff($config);
|
||||
unset($this->manager);
|
||||
|
||||
|
||||
// cleanup some of the element definitions
|
||||
foreach ($this->info as $k => $v) {
|
||||
unset($this->info[$k]->content_model);
|
||||
unset($this->info[$k]->content_model_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract out the information from the manager
|
||||
*/
|
||||
protected function processModules($config) {
|
||||
|
||||
|
||||
if ($this->_anonModule) {
|
||||
// for user specific changes
|
||||
// this is late-loaded so we don't have to deal with PHP4
|
||||
@@ -186,10 +186,10 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
$this->manager->addModule($this->_anonModule);
|
||||
unset($this->_anonModule);
|
||||
}
|
||||
|
||||
|
||||
$this->manager->setup($config);
|
||||
$this->doctype = $this->manager->doctype;
|
||||
|
||||
|
||||
foreach ($this->manager->modules as $module) {
|
||||
foreach($module->info_tag_transform as $k => $v) {
|
||||
if ($v === false) unset($this->info_tag_transform[$k]);
|
||||
@@ -208,17 +208,17 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
else $this->info_injector[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->info = $this->manager->getElements();
|
||||
$this->info_content_sets = $this->manager->contentSets->lookup;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets up stuff based on config. We need a better way of doing this.
|
||||
*/
|
||||
protected function setupConfigStuff($config) {
|
||||
|
||||
|
||||
$block_wrapper = $config->get('HTML', 'BlockWrapper');
|
||||
if (isset($this->info_content_sets['Block'][$block_wrapper])) {
|
||||
$this->info_block_wrapper = $block_wrapper;
|
||||
@@ -226,7 +226,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
trigger_error('Cannot use non-block element as block wrapper',
|
||||
E_USER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
$parent = $config->get('HTML', 'Parent');
|
||||
$def = $this->manager->getElement($parent, true);
|
||||
if ($def) {
|
||||
@@ -237,23 +237,23 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
E_USER_ERROR);
|
||||
$this->info_parent_def = $this->manager->getElement($this->info_parent, true);
|
||||
}
|
||||
|
||||
|
||||
// support template text
|
||||
$support = "(for information on implementing this, see the ".
|
||||
"support forums) ";
|
||||
|
||||
|
||||
// setup allowed elements -----------------------------------------
|
||||
|
||||
|
||||
$allowed_elements = $config->get('HTML', 'AllowedElements');
|
||||
$allowed_attributes = $config->get('HTML', 'AllowedAttributes'); // retrieve early
|
||||
|
||||
|
||||
if (!is_array($allowed_elements) && !is_array($allowed_attributes)) {
|
||||
$allowed = $config->get('HTML', 'Allowed');
|
||||
if (is_string($allowed)) {
|
||||
list($allowed_elements, $allowed_attributes) = $this->parseTinyMCEAllowedList($allowed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (is_array($allowed_elements)) {
|
||||
foreach ($this->info as $name => $d) {
|
||||
if(!isset($allowed_elements[$name])) unset($this->info[$name]);
|
||||
@@ -265,12 +265,12 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
trigger_error("Element '$element' is not supported $support", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// setup allowed attributes ---------------------------------------
|
||||
|
||||
|
||||
$allowed_attributes_mutable = $allowed_attributes; // by copy!
|
||||
if (is_array($allowed_attributes)) {
|
||||
|
||||
|
||||
// This actually doesn't do anything, since we went away from
|
||||
// global attributes. It's possible that userland code uses
|
||||
// it, but HTMLModuleManager doesn't!
|
||||
@@ -287,7 +287,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
}
|
||||
if ($delete) unset($this->info_global_attr[$attr]);
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->info as $tag => $info) {
|
||||
foreach ($info->attr as $attr => $x) {
|
||||
$keys = array("$tag@$attr", $attr, "*@$attr", "$tag.$attr", "*.$attr");
|
||||
@@ -329,14 +329,14 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// setup forbidden elements ---------------------------------------
|
||||
|
||||
|
||||
$forbidden_elements = $config->get('HTML', 'ForbiddenElements');
|
||||
$forbidden_attributes = $config->get('HTML', 'ForbiddenAttributes');
|
||||
|
||||
|
||||
foreach ($this->info as $tag => $info) {
|
||||
if (isset($forbidden_elements[$tag])) {
|
||||
unset($this->info[$tag]);
|
||||
@@ -364,7 +364,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
trigger_error("Error with $key: *.attr syntax not supported for HTML.ForbiddenAttributes; use attr instead", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// setup injectors -----------------------------------------------------
|
||||
foreach ($this->info_injector as $i => $injector) {
|
||||
if ($injector->checkNeeded($config) !== false) {
|
||||
@@ -374,7 +374,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses a TinyMCE-flavored Allowed Elements and Attributes list into
|
||||
* separate lists for processing. Format is element[attr1|attr2],element2...
|
||||
@@ -385,12 +385,12 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
* @todo Give this its own class, probably static interface
|
||||
*/
|
||||
public function parseTinyMCEAllowedList($list) {
|
||||
|
||||
|
||||
$list = str_replace(array(' ', "\t"), '', $list);
|
||||
|
||||
|
||||
$elements = array();
|
||||
$attributes = array();
|
||||
|
||||
|
||||
$chunks = preg_split('/(,|[\n\r]+)/', $list);
|
||||
foreach ($chunks as $chunk) {
|
||||
if (empty($chunk)) continue;
|
||||
@@ -409,12 +409,12 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
$attributes["$element.$key"] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return array($elements, $attributes);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user