HTMLPurifier/HTMLModule.php Quellcode

HTMLModule.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
19 {
20 
21  // -- Overloadable ----------------------------------------------------
22 
27  public $name;
28 
34  public $elements = array();
35 
42  public $info = array();
43 
51  public $content_sets = array();
52 
62  public $attr_collections = array();
63 
68  public $info_tag_transform = array();
69 
74  public $info_attr_transform_pre = array();
75 
80  public $info_attr_transform_post = array();
81 
89  public $info_injector = array();
90 
98  public $defines_child_def = false;
99 
113  public $safe = true;
114 
123  public function getChildDef($def)
124  {
125  return false;
126  }
127 
128  // -- Convenience -----------------------------------------------------
129 
144  public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array())
145  {
146  $this->elements[] = $element;
147  // parse content_model
148  list($content_model_type, $content_model) = $this->parseContents($contents);
149  // merge in attribute inclusions
150  $this->mergeInAttrIncludes($attr, $attr_includes);
151  // add element to content sets
152  if ($type) {
153  $this->addElementToContentSet($element, $type);
154  }
155  // create element
156  $this->info[$element] = HTMLPurifier_ElementDef::create(
157  $content_model,
158  $content_model_type,
159  $attr
160  );
161  // literal object $contents means direct child manipulation
162  if (!is_string($contents)) {
163  $this->info[$element]->child = $contents;
164  }
165  return $this->info[$element];
166  }
167 
174  public function addBlankElement($element)
175  {
176  if (!isset($this->info[$element])) {
177  $this->elements[] = $element;
178  $this->info[$element] = new HTMLPurifier_ElementDef();
179  $this->info[$element]->standalone = false;
180  } else {
181  trigger_error("Definition for $element already exists in module, cannot redefine");
182  }
183  return $this->info[$element];
184  }
185 
192  public function addElementToContentSet($element, $type)
193  {
194  if (!isset($this->content_sets[$type])) {
195  $this->content_sets[$type] = '';
196  } else {
197  $this->content_sets[$type] .= ' | ';
198  }
199  $this->content_sets[$type] .= $element;
200  }
201 
212  public function parseContents($contents)
213  {
214  if (!is_string($contents)) {
215  return array(null, null);
216  } // defer
217  switch ($contents) {
218  // check for shorthand content model forms
219  case 'Empty':
220  return array('empty', '');
221  case 'Inline':
222  return array('optional', 'Inline | #PCDATA');
223  case 'Flow':
224  return array('optional', 'Flow | #PCDATA');
225  }
226  list($content_model_type, $content_model) = explode(':', $contents);
227  $content_model_type = strtolower(trim($content_model_type));
228  $content_model = trim($content_model);
229  return array($content_model_type, $content_model);
230  }
231 
238  public function mergeInAttrIncludes(&$attr, $attr_includes)
239  {
240  if (!is_array($attr_includes)) {
241  if (empty($attr_includes)) {
242  $attr_includes = array();
243  } else {
244  $attr_includes = array($attr_includes);
245  }
246  }
247  $attr[0] = $attr_includes;
248  }
249 
258  public function makeLookup($list)
259  {
260  if (is_string($list)) {
261  $list = func_get_args();
262  }
263  $ret = array();
264  foreach ($list as $value) {
265  if (is_null($value)) {
266  continue;
267  }
268  $ret[$value] = true;
269  }
270  return $ret;
271  }
272 
279  public function setup($config)
280  {
281  }
282 }
283 
284 // vim: et sw=4 sts=4




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.