ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
HTMLPurifier_HTMLModule Class Reference

Represents an XHTML 1.1 module, with information on elements, tags and attributes. More...

+ Inheritance diagram for HTMLPurifier_HTMLModule:
+ Collaboration diagram for HTMLPurifier_HTMLModule:

Public Member Functions

 getChildDef ($def)
 Retrieves a proper HTMLPurifier_ChildDef subclass based on content_model and content_model_type member variables of the HTMLPurifier_ElementDef class. More...
 
 addElement ($element, $type, $contents, $attr_includes=array(), $attr=array())
 Convenience function that sets up a new element. More...
 
 addBlankElement ($element)
 Convenience function that creates a totally blank, non-standalone element. More...
 
 addElementToContentSet ($element, $type)
 Convenience function that registers an element to a content set. More...
 
 parseContents ($contents)
 Convenience function that transforms single-string contents into separate content model and content model type. More...
 
 mergeInAttrIncludes (&$attr, $attr_includes)
 Convenience function that merges a list of attribute includes into an attribute array. More...
 
 makeLookup ($list)
 Convenience function that generates a lookup table with boolean true as value. More...
 
 setup ($config)
 Lazy load construction of the module after determining whether or not it's needed, and also when a finalized configuration object is available. More...
 

Data Fields

 $name
 Short unique string identifier of the module. More...
 
 $elements = array()
 Informally, a list of elements this module changes. More...
 
 $info = array()
 Associative array of element names to element definitions. More...
 
 $content_sets = array()
 Associative array of content set names to content set additions. More...
 
 $attr_collections = array()
 Associative array of attribute collection names to attribute collection additions. More...
 
 $info_tag_transform = array()
 Associative array of deprecated tag name to HTMLPurifier_TagTransform. More...
 
 $info_attr_transform_pre = array()
 List of HTMLPurifier_AttrTransform to be performed before validation. More...
 
 $info_attr_transform_post = array()
 List of HTMLPurifier_AttrTransform to be performed after validation. More...
 
 $info_injector = array()
 List of HTMLPurifier_Injector to be performed during well-formedness fixing. More...
 
 $defines_child_def = false
 Boolean flag that indicates whether or not getChildDef is implemented. More...
 
 $safe = true
 Boolean flag whether or not this module is safe. More...
 

Detailed Description

Represents an XHTML 1.1 module, with information on elements, tags and attributes.

Note
Even though this is technically XHTML 1.1, it is also used for regular HTML parsing. We are using modulization as a convenient way to represent the internals of HTMLDefinition, and our implementation is by no means conforming and does not directly use the normative DTDs or XML schemas.
The public variables in a module should almost directly correspond to the variables in HTMLPurifier_HTMLDefinition. However, the prefix info carries no special meaning in these objects (include it anyway if that's the correspondence though).
Todo:
Consider making some member functions protected

Definition at line 18 of file HTMLModule.php.

Member Function Documentation

◆ addBlankElement()

HTMLPurifier_HTMLModule::addBlankElement (   $element)

Convenience function that creates a totally blank, non-standalone element.

Parameters
string$elementName of element to create
Returns
HTMLPurifier_ElementDef Created element

Definition at line 174 of file HTMLModule.php.

References info().

Referenced by HTMLPurifier_HTMLModule_Tidy\populate(), HTMLPurifier_HTMLModule_Name\setup(), HTMLPurifier_HTMLModule_Target\setup(), HTMLPurifier_HTMLModule_TargetNoopener\setup(), HTMLPurifier_HTMLModule_TargetNoreferrer\setup(), HTMLPurifier_HTMLModule_TargetBlank\setup(), HTMLPurifier_HTMLModule_Nofollow\setup(), and HTMLPurifier_HTMLModule_Legacy\setup().

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  }
Structure that stores an HTML element definition.
Definition: ElementDef.php:11
info()
Definition: info.php:2
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addElement()

HTMLPurifier_HTMLModule::addElement (   $element,
  $type,
  $contents,
  $attr_includes = array(),
  $attr = array() 
)

Convenience function that sets up a new element.

Parameters
string$elementName of element to add
string | bool$typeWhat content set should element be registered to? Set as false to skip this step.
string | HTMLPurifier_ChildDef$contentsAllowed children in form of: "$content_model_type: $content_model"
array | string$attr_includesWhat attribute collections to register to element?
array$attrWhat unique attributes does the element define?
See also
HTMLPurifier_ElementDef:: for in-depth descriptions of these parameters.
Returns
HTMLPurifier_ElementDef Created element definition object, so you can set advanced parameters

Definition at line 144 of file HTMLModule.php.

References $type, addElementToContentSet(), HTMLPurifier_ElementDef\create(), info(), mergeInAttrIncludes(), and parseContents().

Referenced by HTMLPurifier_HTMLModule_SafeEmbed\setup(), HTMLPurifier_HTMLModule_Tables\setup(), HTMLPurifier_HTMLModule_Hypertext\setup(), HTMLPurifier_HTMLModule_SafeScripting\setup(), HTMLPurifier_HTMLModule_Proprietary\setup(), HTMLPurifier_HTMLModule_Ruby\setup(), HTMLPurifier_HTMLModule_Edit\setup(), HTMLPurifier_HTMLModule_Image\setup(), HTMLPurifier_HTMLModule_SafeObject\setup(), HTMLPurifier_HTMLModule_Object\setup(), HTMLPurifier_HTMLModule_Presentation\setup(), HTMLPurifier_HTMLModule_Bdo\setup(), HTMLPurifier_HTMLModule_Iframe\setup(), HTMLPurifier_HTMLModule_Legacy\setup(), HTMLPurifier_HTMLModule_Forms\setup(), HTMLPurifier_HTMLModule_List\setup(), and HTMLPurifier_HTMLModule_Text\setup().

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  }
$type
addElementToContentSet($element, $type)
Convenience function that registers an element to a content set.
Definition: HTMLModule.php:192
mergeInAttrIncludes(&$attr, $attr_includes)
Convenience function that merges a list of attribute includes into an attribute array.
Definition: HTMLModule.php:238
parseContents($contents)
Convenience function that transforms single-string contents into separate content model and content m...
Definition: HTMLModule.php:212
info()
Definition: info.php:2
static create($content_model, $content_model_type, $attr)
Low-level factory constructor for creating new standalone element defs.
Definition: ElementDef.php:138
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addElementToContentSet()

HTMLPurifier_HTMLModule::addElementToContentSet (   $element,
  $type 
)

Convenience function that registers an element to a content set.

Parameters
string$elementElement to register
string$typeName content set (warning: case sensitive, usually upper-case first letter)

Definition at line 192 of file HTMLModule.php.

References $type.

Referenced by addElement().

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  }
$type
+ Here is the caller graph for this function:

◆ getChildDef()

HTMLPurifier_HTMLModule::getChildDef (   $def)

Retrieves a proper HTMLPurifier_ChildDef subclass based on content_model and content_model_type member variables of the HTMLPurifier_ElementDef class.

There is a similar function in HTMLPurifier_HTMLDefinition.

Parameters
HTMLPurifier_ElementDef$def
Returns
HTMLPurifier_ChildDef subclass

Definition at line 123 of file HTMLModule.php.

124  {
125  return false;
126  }

◆ makeLookup()

HTMLPurifier_HTMLModule::makeLookup (   $list)

Convenience function that generates a lookup table with boolean true as value.

Parameters
string$listList of values to turn into a lookup
Note
You can also pass an arbitrary number of arguments in place of the regular argument
Returns
array array equivalent of list

Definition at line 258 of file HTMLModule.php.

References $list, and $ret.

Referenced by HTMLPurifier_HTMLModule_Forms\setup(), and HTMLPurifier_HTMLModule_Text\setup().

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  }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
$ret
Definition: parser.php:6
+ Here is the caller graph for this function:

◆ mergeInAttrIncludes()

HTMLPurifier_HTMLModule::mergeInAttrIncludes ( $attr,
  $attr_includes 
)

Convenience function that merges a list of attribute includes into an attribute array.

Parameters
array$attrReference to attr array to modify
array$attr_includesArray of includes / string include to merge in

Definition at line 238 of file HTMLModule.php.

Referenced by addElement().

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  }
+ Here is the caller graph for this function:

◆ parseContents()

HTMLPurifier_HTMLModule::parseContents (   $contents)

Convenience function that transforms single-string contents into separate content model and content model type.

Parameters
string$contentsAllowed children in form of: "$content_model_type: $content_model"
Returns
array
Note
If contents is an object, an array of two nulls will be returned, and the callee needs to take the original $contents and use it directly.

Definition at line 212 of file HTMLModule.php.

Referenced by addElement().

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  }
+ Here is the caller graph for this function:

◆ setup()

HTMLPurifier_HTMLModule::setup (   $config)

Lazy load construction of the module after determining whether or not it's needed, and also when a finalized configuration object is available.

Parameters
HTMLPurifier_Config$config

Definition at line 279 of file HTMLModule.php.

280  {
281  }

Field Documentation

◆ $attr_collections

HTMLPurifier_HTMLModule::$attr_collections = array()

Associative array of attribute collection names to attribute collection additions.

More rarely used for adding attributes to the global collections. Example is the StyleAttribute module adding the style attribute to the Core. Corresponds to HTMLDefinition's attr_collections->info, since the object's data is only info, with extra behavior associated with it. array

Definition at line 62 of file HTMLModule.php.

◆ $content_sets

HTMLPurifier_HTMLModule::$content_sets = array()

Associative array of content set names to content set additions.

This is commonly used to, say, add an A element to the Inline content set. This corresponds to an internal variable $content_sets and NOT info_content_sets member variable of HTMLDefinition. array

Definition at line 51 of file HTMLModule.php.

◆ $defines_child_def

HTMLPurifier_HTMLModule::$defines_child_def = false

Boolean flag that indicates whether or not getChildDef is implemented.

For optimization reasons: may save a call to a function. Be sure to set it if you do implement getChildDef(), otherwise it will have no effect! bool

Definition at line 98 of file HTMLModule.php.

◆ $elements

HTMLPurifier_HTMLModule::$elements = array()

Informally, a list of elements this module changes.

Not used in any significant way. array

Definition at line 34 of file HTMLModule.php.

Referenced by HTMLPurifier_HTMLModule_Name\setup(), and HTMLPurifier_HTMLModule_Target\setup().

◆ $info

HTMLPurifier_HTMLModule::$info = array()

Associative array of element names to element definitions.

Some definitions may be incomplete, to be merged in later with the full definition. array

Definition at line 42 of file HTMLModule.php.

◆ $info_attr_transform_post

HTMLPurifier_HTMLModule::$info_attr_transform_post = array()

List of HTMLPurifier_AttrTransform to be performed after validation.

array

Definition at line 80 of file HTMLModule.php.

◆ $info_attr_transform_pre

HTMLPurifier_HTMLModule::$info_attr_transform_pre = array()

List of HTMLPurifier_AttrTransform to be performed before validation.

array

Definition at line 74 of file HTMLModule.php.

◆ $info_injector

HTMLPurifier_HTMLModule::$info_injector = array()

List of HTMLPurifier_Injector to be performed during well-formedness fixing.

An injector will only be invoked if all of it's pre-requisites are met; if an injector fails setup, there will be no error; it will simply be silently disabled. array

Definition at line 89 of file HTMLModule.php.

◆ $info_tag_transform

HTMLPurifier_HTMLModule::$info_tag_transform = array()

Associative array of deprecated tag name to HTMLPurifier_TagTransform.

array

Definition at line 68 of file HTMLModule.php.

◆ $name

HTMLPurifier_HTMLModule::$name

Short unique string identifier of the module.

string

Definition at line 27 of file HTMLModule.php.

Referenced by HTMLPurifier_HTMLModule_Tidy\getFixType(), HTMLPurifier_HTMLModule_Tidy\populate(), and HTMLPurifier_HTMLModule_Tidy\setup().

◆ $safe

HTMLPurifier_HTMLModule::$safe = true

Boolean flag whether or not this module is safe.

If it is not safe, all of its members are unsafe. Modules are safe by default (this might be slightly dangerous, but it doesn't make much sense to force HTML Purifier, which is based off of safe HTML, to explicitly say, "This is safe," even though there are modules which are "unsafe")

bool

Note
Previously, safety could be applied at an element level granularity. We've removed this ability, so in order to add "unsafe" elements or attributes, a dedicated module with this property set to false must be used.

Definition at line 113 of file HTMLModule.php.


The documentation for this class was generated from the following file: