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.
8 * @warning If you add new properties to this class, you MUST update
9 * the mergeIn() method.
11 class HTMLPurifier_ElementDef
15 * Does the definition work by itself, or is it created solely
16 * for the purpose of merging into another definition?
18 public $standalone = true;
21 * Associative array of attribute name to HTMLPurifier_AttrDef
22 * @note Before being processed by HTMLPurifier_AttrCollections
23 * when modules are finalized during
24 * HTMLPurifier_HTMLDefinition->setup(), this array may also
25 * contain an array at index 0 that indicates which attribute
26 * collections to load into the full array. It may also
27 * contain string indentifiers in lieu of HTMLPurifier_AttrDef,
28 * see HTMLPurifier_AttrTypes on how they are expanded during
29 * HTMLPurifier_HTMLDefinition->setup() processing.
31 public $attr = array();
34 * Indexed list of tag's HTMLPurifier_AttrTransform to be done before validation
36 public $attr_transform_pre = array();
39 * Indexed list of tag's HTMLPurifier_AttrTransform to be done after validation
41 public $attr_transform_post = array();
44 * HTMLPurifier_ChildDef of this tag.
49 * Abstract string representation of internal ChildDef rules. See
50 * HTMLPurifier_ContentSets for how this is parsed and then transformed
51 * into an HTMLPurifier_ChildDef.
52 * @warning This is a temporary variable that is not available after
53 * being processed by HTMLDefinition
55 public $content_model;
58 * Value of $child->type, used to determine which ChildDef to use,
59 * used in combination with $content_model.
60 * @warning This must be lowercase
61 * @warning This is a temporary variable that is not available after
62 * being processed by HTMLDefinition
64 public $content_model_type;
69 * Does the element have a content model (#PCDATA | Inline)*? This
70 * is important for chameleon ins and del processing in
71 * HTMLPurifier_ChildDef_Chameleon. Dynamically set: modules don't
72 * have to worry about this one.
74 public $descendants_are_inline = false;
77 * List of the names of required attributes this element has. Dynamically
78 * populated by HTMLPurifier_HTMLDefinition::getElement
80 public $required_attr = array();
83 * Lookup table of tags excluded from all descendants of this tag.
84 * @note SGML permits exclusions for all descendants, but this is
85 * not possible with DTDs or XML Schemas. W3C has elected to
86 * use complicated compositions of content_models to simulate
87 * exclusion for children, but we go the simpler, SGML-style
88 * route of flat-out exclusions, which correctly apply to
89 * all descendants and not just children. Note that the XHTML
90 * Modularization Abstract Modules are blithely unaware of such
93 public $excludes = array();
96 * This tag is explicitly auto-closed by the following tags.
98 public $autoclose = array();
101 * Whether or not this is a formatting element affected by the
102 * "Active Formatting Elements" algorithm.
107 * Low-level factory constructor for creating new standalone element defs
109 public static function create($content_model, $content_model_type, $attr) {
110 $def = new HTMLPurifier_ElementDef();
111 $def->content_model
= $content_model;
112 $def->content_model_type
= $content_model_type;
118 * Merges the values of another element definition into this one.
119 * Values from the new element def take precedence if a value is
122 public function mergeIn($def) {
124 // later keys takes precedence
125 foreach($def->attr
as $k => $v) {
127 // merge in the includes
128 // sorry, no way to override an include
129 foreach ($v as $v2) {
130 $this->attr
[0][] = $v2;
135 if (isset($this->attr
[$k])) unset($this->attr
[$k]);
138 $this->attr
[$k] = $v;
140 $this->_mergeAssocArray($this->attr_transform_pre
, $def->attr_transform_pre
);
141 $this->_mergeAssocArray($this->attr_transform_post
, $def->attr_transform_post
);
142 $this->_mergeAssocArray($this->excludes
, $def->excludes
);
144 if(!empty($def->content_model
)) {
145 $this->content_model
.= ' | ' . $def->content_model
;
146 $this->child
= false;
148 if(!empty($def->content_model_type
)) {
149 $this->content_model_type
= $def->content_model_type
;
150 $this->child
= false;
152 if(!is_null($def->child
)) $this->child
= $def->child
;
153 if(!is_null($def->formatting
)) $this->formatting
= $def->formatting
;
154 if($def->descendants_are_inline
) $this->descendants_are_inline
= $def->descendants_are_inline
;
159 * Merges one array into another, removes values which equal false
160 * @param $a1 Array by reference that is merged into
161 * @param $a2 Array that merges into $a1
163 private function _mergeAssocArray(&$a1, $a2) {
164 foreach ($a2 as $k => $v) {
166 if (isset($a1[$k])) unset($a1[$k]);
175 // vim: et sw=4 sts=4