Release 1.6.1, merged in 931 to HEAD.
[htmlpurifier.git] / library / HTMLPurifier / ElementDef.php
blob73c94abe1382d960dd2f8f1cdf57ecb2912c5f81
1 <?php
3 /**
4 * Structure that stores an HTML element definition. Used by
5 * HTMLPurifier_HTMLDefinition and HTMLPurifier_HTMLModule.
6 */
7 class HTMLPurifier_ElementDef
10 /**
11 * Does the definition work by itself, or is it created solely
12 * for the purpose of merging into another definition?
14 var $standalone = true;
16 /**
17 * Associative array of attribute name to HTMLPurifier_AttrDef
18 * @note Before being processed by HTMLPurifier_AttrCollections
19 * when modules are finalized during
20 * HTMLPurifier_HTMLDefinition->setup(), this array may also
21 * contain an array at index 0 that indicates which attribute
22 * collections to load into the full array. It may also
23 * contain string indentifiers in lieu of HTMLPurifier_AttrDef,
24 * see HTMLPurifier_AttrTypes on how they are expanded during
25 * HTMLPurifier_HTMLDefinition->setup() processing.
26 * @public
28 var $attr = array();
30 /**
31 * Indexed list of tag's HTMLPurifier_AttrTransform to be done before validation
32 * @public
34 var $attr_transform_pre = array();
36 /**
37 * Indexed list of tag's HTMLPurifier_AttrTransform to be done after validation
38 * @public
40 var $attr_transform_post = array();
44 /**
45 * HTMLPurifier_ChildDef of this tag.
46 * @public
48 var $child;
50 /**
51 * Abstract string representation of internal ChildDef rules. See
52 * HTMLPurifier_ContentSets for how this is parsed and then transformed
53 * into an HTMLPurifier_ChildDef.
54 * @public
56 var $content_model;
58 /**
59 * Value of $child->type, used to determine which ChildDef to use,
60 * used in combination with $content_model.
61 * @public
63 var $content_model_type;
67 /**
68 * Lookup table of tags that close this tag. Used during parsing
69 * to make sure we don't attempt to nest unclosed tags.
70 * @public
72 var $auto_close = array();
74 /**
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.
79 * @public
81 var $descendants_are_inline;
83 /**
84 * Lookup table of tags excluded from all descendants of this tag.
85 * @public
87 var $excludes = array();
89 /**
90 * Merges the values of another element definition into this one.
91 * Values from the new element def take precedence if a value is
92 * not mergeable.
94 function mergeIn($def) {
96 // later keys takes precedence
97 foreach($def->attr as $k => $v) {
98 if ($k === 0) {
99 // merge in the includes
100 // sorry, no way to override an include
101 foreach ($v as $v2) {
102 $def->attr[0][] = $v2;
104 continue;
106 $this->attr[$k] = $v;
108 foreach($def->attr_transform_pre as $k => $v) $this->attr_transform_pre[$k] = $v;
109 foreach($def->attr_transform_post as $k => $v) $this->attr_transform_post[$k] = $v;
110 foreach($def->auto_close as $k => $v) $this->auto_close[$k] = $v;
111 foreach($def->excludes as $k => $v) $this->excludes[$k] = $v;
113 if(!is_null($def->child)) $this->child = $def->child;
114 if(!empty($def->content_model)) $this->content_model .= ' | ' . $def->content_model;
115 if(!empty($def->content_model_type)) $this->content_model_type = $def->content_model_type;
116 if(!is_null($def->descendants_are_inline)) $this->descendants_are_inline = $def->descendants_are_inline;