4 * Structure that stores an HTML element definition. Used by
5 * HTMLPurifier_HTMLDefinition and HTMLPurifier_HTMLModule.
6 * @note This class is inspected by HTMLPurifier_Printer_HTMLDefinition.
7 * Please update that class too.
9 class HTMLPurifier_ElementDef
13 * Does the definition work by itself, or is it created solely
14 * for the purpose of merging into another definition?
16 var $standalone = true;
19 * Associative array of attribute name to HTMLPurifier_AttrDef
20 * @note Before being processed by HTMLPurifier_AttrCollections
21 * when modules are finalized during
22 * HTMLPurifier_HTMLDefinition->setup(), this array may also
23 * contain an array at index 0 that indicates which attribute
24 * collections to load into the full array. It may also
25 * contain string indentifiers in lieu of HTMLPurifier_AttrDef,
26 * see HTMLPurifier_AttrTypes on how they are expanded during
27 * HTMLPurifier_HTMLDefinition->setup() processing.
33 * Indexed list of tag's HTMLPurifier_AttrTransform to be done before validation
36 var $attr_transform_pre = array();
39 * Indexed list of tag's HTMLPurifier_AttrTransform to be done after validation
42 var $attr_transform_post = array();
47 * HTMLPurifier_ChildDef of this tag.
53 * Abstract string representation of internal ChildDef rules. See
54 * HTMLPurifier_ContentSets for how this is parsed and then transformed
55 * into an HTMLPurifier_ChildDef.
56 * @warning This is a temporary variable that is not available after
57 * being processed by HTMLDefinition
63 * Value of $child->type, used to determine which ChildDef to use,
64 * used in combination with $content_model.
65 * @warning This must be lowercase
66 * @warning This is a temporary variable that is not available after
67 * being processed by HTMLDefinition
70 var $content_model_type;
75 * Does the element have a content model (#PCDATA | Inline)*? This
76 * is important for chameleon ins and del processing in
77 * HTMLPurifier_ChildDef_Chameleon. Dynamically set: modules don't
78 * have to worry about this one.
81 var $descendants_are_inline = false;
84 * List of the names of required attributes this element has. Dynamically
88 var $required_attr = array();
91 * Lookup table of tags excluded from all descendants of this tag.
92 * @note SGML permits exclusions for all descendants, but this is
93 * not possible with DTDs or XML Schemas. W3C has elected to
94 * use complicated compositions of content_models to simulate
95 * exclusion for children, but we go the simpler, SGML-style
96 * route of flat-out exclusions, which correctly apply to
97 * all descendants and not just children. Note that the XHTML
98 * Modularization Abstract Modules are blithely unaware of such
102 var $excludes = array();
105 * Is this element safe for untrusted users to use?
110 * Low-level factory constructor for creating new standalone element defs
113 function create($safe, $content_model, $content_model_type, $attr) {
114 $def = new HTMLPurifier_ElementDef();
115 $def->safe
= (bool) $safe;
116 $def->content_model
= $content_model;
117 $def->content_model_type
= $content_model_type;
123 * Merges the values of another element definition into this one.
124 * Values from the new element def take precedence if a value is
127 function mergeIn($def) {
129 // later keys takes precedence
130 foreach($def->attr
as $k => $v) {
132 // merge in the includes
133 // sorry, no way to override an include
134 foreach ($v as $v2) {
135 $this->attr
[0][] = $v2;
140 if (isset($this->attr
[$k])) unset($this->attr
[$k]);
143 $this->attr
[$k] = $v;
145 $this->_mergeAssocArray($this->attr_transform_pre
, $def->attr_transform_pre
);
146 $this->_mergeAssocArray($this->attr_transform_post
, $def->attr_transform_post
);
147 $this->_mergeAssocArray($this->excludes
, $def->excludes
);
149 if(!empty($def->content_model
)) {
150 $this->content_model
.= ' | ' . $def->content_model
;
151 $this->child
= false;
153 if(!empty($def->content_model_type
)) {
154 $this->content_model_type
= $def->content_model_type
;
155 $this->child
= false;
157 if(!is_null($def->child
)) $this->child
= $def->child
;
158 if($def->descendants_are_inline
) $this->descendants_are_inline
= $def->descendants_are_inline
;
159 if(!is_null($def->safe
)) $this->safe
= $def->safe
;
164 * Merges one array into another, removes values which equal false
165 * @param $a1 Array by reference that is merged into
166 * @param $a2 Array that merges into $a1
168 function _mergeAssocArray(&$a1, $a2) {
169 foreach ($a2 as $k => $v) {
171 if (isset($a1[$k])) unset($a1[$k]);
179 * Retrieves a copy of the element definition
182 return unserialize(serialize($this));