ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLModule.php
Go to the documentation of this file.
1 <?php
2 
19 {
20 
21  // -- Overloadable ----------------------------------------------------
22 
26  public $name;
27 
32  public $elements = array();
33 
39  public $info = array();
40 
47  public $content_sets = array();
48 
57  public $attr_collections = array();
58 
62  public $info_tag_transform = array();
63 
67  public $info_attr_transform_pre = array();
68 
72  public $info_attr_transform_post = array();
73 
80  public $info_injector = array();
81 
88  public $defines_child_def = false;
89 
102  public $safe = true;
103 
112  public function getChildDef($def) {return false;}
113 
114  // -- Convenience -----------------------------------------------------
115 
130  public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) {
131  $this->elements[] = $element;
132  // parse content_model
133  list($content_model_type, $content_model) = $this->parseContents($contents);
134  // merge in attribute inclusions
135  $this->mergeInAttrIncludes($attr, $attr_includes);
136  // add element to content sets
137  if ($type) $this->addElementToContentSet($element, $type);
138  // create element
139  $this->info[$element] = HTMLPurifier_ElementDef::create(
140  $content_model, $content_model_type, $attr
141  );
142  // literal object $contents means direct child manipulation
143  if (!is_string($contents)) $this->info[$element]->child = $contents;
144  return $this->info[$element];
145  }
146 
153  public function addBlankElement($element) {
154  if (!isset($this->info[$element])) {
155  $this->elements[] = $element;
156  $this->info[$element] = new HTMLPurifier_ElementDef();
157  $this->info[$element]->standalone = false;
158  } else {
159  trigger_error("Definition for $element already exists in module, cannot redefine");
160  }
161  return $this->info[$element];
162  }
163 
170  public function addElementToContentSet($element, $type) {
171  if (!isset($this->content_sets[$type])) $this->content_sets[$type] = '';
172  else $this->content_sets[$type] .= ' | ';
173  $this->content_sets[$type] .= $element;
174  }
175 
185  public function parseContents($contents) {
186  if (!is_string($contents)) return array(null, null); // defer
187  switch ($contents) {
188  // check for shorthand content model forms
189  case 'Empty':
190  return array('empty', '');
191  case 'Inline':
192  return array('optional', 'Inline | #PCDATA');
193  case 'Flow':
194  return array('optional', 'Flow | #PCDATA');
195  }
196  list($content_model_type, $content_model) = explode(':', $contents);
197  $content_model_type = strtolower(trim($content_model_type));
198  $content_model = trim($content_model);
199  return array($content_model_type, $content_model);
200  }
201 
208  public function mergeInAttrIncludes(&$attr, $attr_includes) {
209  if (!is_array($attr_includes)) {
210  if (empty($attr_includes)) $attr_includes = array();
211  else $attr_includes = array($attr_includes);
212  }
213  $attr[0] = $attr_includes;
214  }
215 
224  public function makeLookup($list) {
225  if (is_string($list)) $list = func_get_args();
226  $ret = array();
227  foreach ($list as $value) {
228  if (is_null($value)) continue;
229  $ret[$value] = true;
230  }
231  return $ret;
232  }
233 
240  public function setup($config) {}
241 
242 }
243 
244 // vim: et sw=4 sts=4