ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ElementDef.php
Go to the documentation of this file.
1 <?php
2 
12 {
18  public $standalone = true;
19 
32  public $attr = array();
33 
34  // XXX: Design note: currently, it's not possible to override
35  // previously defined AttrTransforms without messing around with
36  // the final generated config. This is by design; a previous version
37  // used an associated list of attr_transform, but it was extremely
38  // easy to accidentally override other attribute transforms by
39  // forgetting to specify an index (and just using 0.) While we
40  // could check this by checking the index number and complaining,
41  // there is a second problem which is that it is not at all easy to
42  // tell when something is getting overridden. Combine this with a
43  // codebase where this isn't really being used, and it's perfect for
44  // nuking.
45 
50  public $attr_transform_pre = array();
51 
56  public $attr_transform_post = array();
57 
62  public $child;
63 
73 
83 
91  public $descendants_are_inline = false;
92 
98  public $required_attr = array();
99 
112  public $excludes = array();
113 
118  public $autoclose = array();
119 
126  public $wrap;
127 
133  public $formatting;
134 
138  public static function create($content_model, $content_model_type, $attr)
139  {
140  $def = new HTMLPurifier_ElementDef();
141  $def->content_model = $content_model;
142  $def->content_model_type = $content_model_type;
143  $def->attr = $attr;
144  return $def;
145  }
146 
153  public function mergeIn($def)
154  {
155  // later keys takes precedence
156  foreach ($def->attr as $k => $v) {
157  if ($k === 0) {
158  // merge in the includes
159  // sorry, no way to override an include
160  foreach ($v as $v2) {
161  $this->attr[0][] = $v2;
162  }
163  continue;
164  }
165  if ($v === false) {
166  if (isset($this->attr[$k])) {
167  unset($this->attr[$k]);
168  }
169  continue;
170  }
171  $this->attr[$k] = $v;
172  }
173  $this->_mergeAssocArray($this->excludes, $def->excludes);
174  $this->attr_transform_pre = array_merge($this->attr_transform_pre, $def->attr_transform_pre);
175  $this->attr_transform_post = array_merge($this->attr_transform_post, $def->attr_transform_post);
176 
177  if (!empty($def->content_model)) {
178  $this->content_model =
179  str_replace("#SUPER", $this->content_model, $def->content_model);
180  $this->child = false;
181  }
182  if (!empty($def->content_model_type)) {
183  $this->content_model_type = $def->content_model_type;
184  $this->child = false;
185  }
186  if (!is_null($def->child)) {
187  $this->child = $def->child;
188  }
189  if (!is_null($def->formatting)) {
190  $this->formatting = $def->formatting;
191  }
192  if ($def->descendants_are_inline) {
193  $this->descendants_are_inline = $def->descendants_are_inline;
194  }
195  }
196 
202  private function _mergeAssocArray(&$a1, $a2)
203  {
204  foreach ($a2 as $k => $v) {
205  if ($v === false) {
206  if (isset($a1[$k])) {
207  unset($a1[$k]);
208  }
209  continue;
210  }
211  $a1[$k] = $v;
212  }
213  }
214 }
215 
216 // vim: et sw=4 sts=4