ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HTMLModule.php
Go to the documentation of this file.
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
Structure that stores an HTML element definition.
Definition: ElementDef.php:12
static create($content_model, $content_model_type, $attr)
Low-level factory constructor for creating new standalone element defs.
Definition: ElementDef.php:138
Represents an XHTML 1.1 module, with information on elements, tags and attributes.
Definition: HTMLModule.php:19
$name
Short unique string identifier of the module.
Definition: HTMLModule.php:27
getChildDef($def)
Retrieves a proper HTMLPurifier_ChildDef subclass based on content_model and content_model_type membe...
Definition: HTMLModule.php:123
$safe
Boolean flag whether or not this module is safe.
Definition: HTMLModule.php:113
makeLookup($list)
Convenience function that generates a lookup table with boolean true as value.
Definition: HTMLModule.php:258
addElementToContentSet($element, $type)
Convenience function that registers an element to a content set.
Definition: HTMLModule.php:192
addBlankElement($element)
Convenience function that creates a totally blank, non-standalone element.
Definition: HTMLModule.php:174
$elements
Informally, a list of elements this module changes.
Definition: HTMLModule.php:34
mergeInAttrIncludes(&$attr, $attr_includes)
Convenience function that merges a list of attribute includes into an attribute array.
Definition: HTMLModule.php:238
$info_injector
List of HTMLPurifier_Injector to be performed during well-formedness fixing.
Definition: HTMLModule.php:89
$defines_child_def
Boolean flag that indicates whether or not getChildDef is implemented.
Definition: HTMLModule.php:98
$attr_collections
Associative array of attribute collection names to attribute collection additions.
Definition: HTMLModule.php:62
$info_attr_transform_pre
List of HTMLPurifier_AttrTransform to be performed before validation.
Definition: HTMLModule.php:74
$info
Associative array of element names to element definitions.
Definition: HTMLModule.php:42
$content_sets
Associative array of content set names to content set additions.
Definition: HTMLModule.php:51
$info_tag_transform
Associative array of deprecated tag name to HTMLPurifier_TagTransform.
Definition: HTMLModule.php:68
setup($config)
Lazy load construction of the module after determining whether or not it's needed,...
Definition: HTMLModule.php:279
parseContents($contents)
Convenience function that transforms single-string contents into separate content model and content m...
Definition: HTMLModule.php:212
$info_attr_transform_post
List of HTMLPurifier_AttrTransform to be performed after validation.
Definition: HTMLModule.php:80
addElement($element, $type, $contents, $attr_includes=array(), $attr=array())
Convenience function that sets up a new element.
Definition: HTMLModule.php:144