Support flashvars.
[htmlpurifier.git] / library / HTMLPurifier / ElementDef.php
blobaede2c3bb49b25af997901918600751415bc03cd
1 <?php
3 /**
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
14 /**
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;
20 /**
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();
33 /**
34 * Indexed list of tag's HTMLPurifier_AttrTransform to be done before validation
36 public $attr_transform_pre = array();
38 /**
39 * Indexed list of tag's HTMLPurifier_AttrTransform to be done after validation
41 public $attr_transform_post = array();
43 /**
44 * HTMLPurifier_ChildDef of this tag.
46 public $child;
48 /**
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;
57 /**
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;
68 /**
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;
76 /**
77 * List of the names of required attributes this element has. Dynamically
78 * populated by HTMLPurifier_HTMLDefinition::getElement
80 public $required_attr = array();
82 /**
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
91 * distinctions.
93 public $excludes = array();
95 /**
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.
104 public $formatting;
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;
113 $def->attr = $attr;
114 return $def;
118 * Merges the values of another element definition into this one.
119 * Values from the new element def take precedence if a value is
120 * not mergeable.
122 public function mergeIn($def) {
124 // later keys takes precedence
125 foreach($def->attr as $k => $v) {
126 if ($k === 0) {
127 // merge in the includes
128 // sorry, no way to override an include
129 foreach ($v as $v2) {
130 $this->attr[0][] = $v2;
132 continue;
134 if ($v === false) {
135 if (isset($this->attr[$k])) unset($this->attr[$k]);
136 continue;
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 =
146 str_replace("#SUPER", $this->content_model, $def->content_model);
147 $this->child = false;
149 if(!empty($def->content_model_type)) {
150 $this->content_model_type = $def->content_model_type;
151 $this->child = false;
153 if(!is_null($def->child)) $this->child = $def->child;
154 if(!is_null($def->formatting)) $this->formatting = $def->formatting;
155 if($def->descendants_are_inline) $this->descendants_are_inline = $def->descendants_are_inline;
160 * Merges one array into another, removes values which equal false
161 * @param $a1 Array by reference that is merged into
162 * @param $a2 Array that merges into $a1
164 private function _mergeAssocArray(&$a1, $a2) {
165 foreach ($a2 as $k => $v) {
166 if ($v === false) {
167 if (isset($a1[$k])) unset($a1[$k]);
168 continue;
170 $a1[$k] = $v;
176 // vim: et sw=4 sts=4