2007-02-04 23:17:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Structure that stores an HTML element definition. Used by
|
|
|
|
* HTMLPurifier_HTMLDefinition and HTMLPurifier_HTMLModule.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_ElementDef
|
|
|
|
{
|
|
|
|
|
2007-02-10 23:35:21 +00:00
|
|
|
/**
|
|
|
|
* Does the definition work by itself, or is it created solely
|
|
|
|
* for the purpose of merging into another definition?
|
|
|
|
*/
|
|
|
|
var $standalone = true;
|
|
|
|
|
2007-02-04 23:17:13 +00:00
|
|
|
/**
|
|
|
|
* Associative array of attribute name to HTMLPurifier_AttrDef
|
2007-02-09 03:19:43 +00:00
|
|
|
* @note Before being processed by HTMLPurifier_AttrCollections
|
|
|
|
* when modules are finalized during
|
|
|
|
* HTMLPurifier_HTMLDefinition->setup(), this array may also
|
|
|
|
* contain an array at index 0 that indicates which attribute
|
|
|
|
* collections to load into the full array. It may also
|
|
|
|
* contain string indentifiers in lieu of HTMLPurifier_AttrDef,
|
|
|
|
* see HTMLPurifier_AttrTypes on how they are expanded during
|
|
|
|
* HTMLPurifier_HTMLDefinition->setup() processing.
|
2007-02-04 23:17:13 +00:00
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $attr = array();
|
|
|
|
|
|
|
|
/**
|
2007-02-10 23:35:21 +00:00
|
|
|
* Indexed list of tag's HTMLPurifier_AttrTransform to be done before validation
|
2007-02-04 23:17:13 +00:00
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $attr_transform_pre = array();
|
|
|
|
|
|
|
|
/**
|
2007-02-10 23:35:21 +00:00
|
|
|
* Indexed list of tag's HTMLPurifier_AttrTransform to be done after validation
|
2007-02-04 23:17:13 +00:00
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $attr_transform_post = array();
|
|
|
|
|
2007-02-09 03:19:43 +00:00
|
|
|
|
2007-02-04 23:17:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HTMLPurifier_ChildDef of this tag.
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $child;
|
|
|
|
|
|
|
|
/**
|
2007-02-09 03:19:43 +00:00
|
|
|
* Abstract string representation of internal ChildDef rules. See
|
|
|
|
* HTMLPurifier_ContentSets for how this is parsed and then transformed
|
|
|
|
* into an HTMLPurifier_ChildDef.
|
2007-02-04 23:17:13 +00:00
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $content_model;
|
|
|
|
|
|
|
|
/**
|
2007-02-09 03:19:43 +00:00
|
|
|
* Value of $child->type, used to determine which ChildDef to use,
|
|
|
|
* used in combination with $content_model.
|
2007-05-07 01:51:26 +00:00
|
|
|
* @warning This must be lowercase
|
2007-02-04 23:17:13 +00:00
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $content_model_type;
|
|
|
|
|
2007-02-09 03:19:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup table of tags that close this tag. Used during parsing
|
|
|
|
* to make sure we don't attempt to nest unclosed tags.
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $auto_close = array();
|
|
|
|
|
2007-02-04 23:17:13 +00:00
|
|
|
/**
|
|
|
|
* Does the element have a content model (#PCDATA | Inline)*? This
|
2007-02-09 03:19:43 +00:00
|
|
|
* is important for chameleon ins and del processing in
|
2007-02-18 05:29:19 +00:00
|
|
|
* HTMLPurifier_ChildDef_Chameleon. Dynamically set: modules don't
|
|
|
|
* have to worry about this one.
|
2007-02-04 23:17:13 +00:00
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $descendants_are_inline;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup table of tags excluded from all descendants of this tag.
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $excludes = array();
|
|
|
|
|
2007-05-07 01:51:26 +00:00
|
|
|
/**
|
|
|
|
* Is this element safe for untrusted users to use?
|
|
|
|
*/
|
|
|
|
var $safe = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory constructor for creating new standalone element defs
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
function create($safe, $content_model, $content_model_type, $attr) {
|
|
|
|
$def = new HTMLPurifier_ElementDef();
|
|
|
|
$def->safe = (bool) $safe;
|
|
|
|
$def->content_model = $content_model;
|
|
|
|
$def->content_model_type = $content_model_type;
|
|
|
|
$def->attr = $attr;
|
|
|
|
return $def;
|
|
|
|
}
|
|
|
|
|
2007-02-10 23:35:21 +00:00
|
|
|
/**
|
|
|
|
* Merges the values of another element definition into this one.
|
|
|
|
* Values from the new element def take precedence if a value is
|
|
|
|
* not mergeable.
|
|
|
|
*/
|
|
|
|
function mergeIn($def) {
|
|
|
|
|
|
|
|
// later keys takes precedence
|
2007-02-11 01:52:56 +00:00
|
|
|
foreach($def->attr as $k => $v) {
|
2007-05-05 20:04:34 +00:00
|
|
|
if ($k === 0) {
|
2007-02-11 01:52:56 +00:00
|
|
|
// merge in the includes
|
|
|
|
// sorry, no way to override an include
|
|
|
|
foreach ($v as $v2) {
|
2007-05-07 00:38:23 +00:00
|
|
|
$this->attr[0][] = $v2;
|
2007-02-11 01:52:56 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2007-05-07 00:38:23 +00:00
|
|
|
if ($v === false) {
|
|
|
|
if (isset($this->attr[$k])) unset($this->attr[$k]);
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-11 01:52:56 +00:00
|
|
|
$this->attr[$k] = $v;
|
|
|
|
}
|
2007-05-07 00:38:23 +00:00
|
|
|
$this->_mergeAssocArray($this->attr_transform_pre, $def->attr_transform_pre);
|
|
|
|
$this->_mergeAssocArray($this->attr_transform_post, $def->attr_transform_post);
|
|
|
|
$this->_mergeAssocArray($this->auto_close, $def->auto_close);
|
|
|
|
$this->_mergeAssocArray($this->excludes, $def->excludes);
|
2007-02-10 23:35:21 +00:00
|
|
|
|
|
|
|
if(!is_null($def->child)) $this->child = $def->child;
|
|
|
|
if(!empty($def->content_model)) $this->content_model .= ' | ' . $def->content_model;
|
|
|
|
if(!empty($def->content_model_type)) $this->content_model_type = $def->content_model_type;
|
|
|
|
if(!is_null($def->descendants_are_inline)) $this->descendants_are_inline = $def->descendants_are_inline;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-05-07 00:38:23 +00:00
|
|
|
/**
|
|
|
|
* Merges one array into another, removes values which equal false
|
|
|
|
* @param $a1 Array by reference that is merged into
|
|
|
|
* @param $a2 Array that merges into $a1
|
|
|
|
*/
|
|
|
|
function _mergeAssocArray(&$a1, $a2) {
|
|
|
|
foreach ($a2 as $k => $v) {
|
|
|
|
if ($v === false) {
|
|
|
|
if (isset($a1[$k])) unset($a1[$k]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$a1[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-04 23:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|