ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
HTMLPurifier_ContentSets Class Reference
+ Collaboration diagram for HTMLPurifier_ContentSets:

Public Member Functions

 __construct ($modules)
 Merges in module's content sets, expands identifiers in the content sets and populates the keys, values and lookup member variables. More...
 
 generateChildDef (&$def, $module)
 Accepts a definition; generates and assigns a ChildDef for it. More...
 
 generateChildDefCallback ($matches)
 
 getChildDef ($def, $module)
 Instantiates a ChildDef based on content_model and content_model_type member variables in HTMLPurifier_ElementDef. More...
 

Data Fields

 $info = array()
 List of content set strings (pipe separators) indexed by name. More...
 
 $lookup = array()
 List of content set lookups (element => true) indexed by name. More...
 

Protected Member Functions

 convertToLookup ($string)
 Converts a string list of elements separated by pipes into a lookup array. More...
 

Protected Attributes

 $keys = array()
 Synchronized list of defined content sets (keys of info). More...
 
 $values = array()
 Synchronized list of defined content values (values of info). More...
 

Detailed Description

Todo:
Unit test

Definition at line 6 of file ContentSets.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_ContentSets::__construct (   $modules)

Merges in module's content sets, expands identifiers in the content sets and populates the keys, values and lookup member variables.

Parameters
HTMLPurifier_HTMLModule[]$modules List of HTMLPurifier_HTMLModule

Definition at line 38 of file ContentSets.php.

References $lookup, $x, array, and convertToLookup().

39  {
40  if (!is_array($modules)) {
41  $modules = array($modules);
42  }
43  // populate content_sets based on module hints
44  // sorry, no way of overloading
45  foreach ($modules as $module) {
46  foreach ($module->content_sets as $key => $value) {
47  $temp = $this->convertToLookup($value);
48  if (isset($this->lookup[$key])) {
49  // add it into the existing content set
50  $this->lookup[$key] = array_merge($this->lookup[$key], $temp);
51  } else {
52  $this->lookup[$key] = $temp;
53  }
54  }
55  }
56  $old_lookup = false;
57  while ($old_lookup !== $this->lookup) {
58  $old_lookup = $this->lookup;
59  foreach ($this->lookup as $i => $set) {
60  $add = array();
61  foreach ($set as $element => $x) {
62  if (isset($this->lookup[$element])) {
63  $add += $this->lookup[$element];
64  unset($this->lookup[$i][$element]);
65  }
66  }
67  $this->lookup[$i] += $add;
68  }
69  }
70 
71  foreach ($this->lookup as $key => $lookup) {
72  $this->info[$key] = implode(' | ', array_keys($lookup));
73  }
74  $this->keys = array_keys($this->info);
75  $this->values = array_values($this->info);
76  }
$x
Definition: example_009.php:98
convertToLookup($string)
Converts a string list of elements separated by pipes into a lookup array.
$lookup
List of content set lookups (element => true) indexed by name.
Definition: ContentSets.php:20
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Member Function Documentation

◆ convertToLookup()

HTMLPurifier_ContentSets::convertToLookup (   $string)
protected

Converts a string list of elements separated by pipes into a lookup array.

Parameters
string$stringList of elements
Returns
array Lookup array of elements

Definition at line 159 of file ContentSets.php.

References $ret, and array.

Referenced by __construct().

160  {
161  $array = explode('|', str_replace(' ', '', $string));
162  $ret = array();
163  foreach ($array as $k) {
164  $ret[$k] = true;
165  }
166  return $ret;
167  }
Create styles array
The data for the language used.
$ret
Definition: parser.php:6
+ Here is the caller graph for this function:

◆ generateChildDef()

HTMLPurifier_ContentSets::generateChildDef ( $def,
  $module 
)

Accepts a definition; generates and assigns a ChildDef for it.

Parameters
HTMLPurifier_ElementDef$defHTMLPurifier_ElementDef reference
HTMLPurifier_HTMLModule$moduleModule that defined the ElementDef

Definition at line 83 of file ContentSets.php.

References array, and getChildDef().

84  {
85  if (!empty($def->child)) { // already done!
86  return;
87  }
88  $content_model = $def->content_model;
89  if (is_string($content_model)) {
90  // Assume that $this->keys is alphanumeric
91  $def->content_model = preg_replace_callback(
92  '/\b(' . implode('|', $this->keys) . ')\b/',
93  array($this, 'generateChildDefCallback'),
94  $content_model
95  );
96  //$def->content_model = str_replace(
97  // $this->keys, $this->values, $content_model);
98  }
99  $def->child = $this->getChildDef($def, $module);
100  }
getChildDef($def, $module)
Instantiates a ChildDef based on content_model and content_model_type member variables in HTMLPurifie...
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ generateChildDefCallback()

HTMLPurifier_ContentSets::generateChildDefCallback (   $matches)

Definition at line 102 of file ContentSets.php.

103  {
104  return $this->info[$matches[0]];
105  }

◆ getChildDef()

HTMLPurifier_ContentSets::getChildDef (   $def,
  $module 
)

Instantiates a ChildDef based on content_model and content_model_type member variables in HTMLPurifier_ElementDef.

Note
This will also defer to modules for custom HTMLPurifier_ChildDef subclasses that need content set expansion
Parameters
HTMLPurifier_ElementDef$defHTMLPurifier_ElementDef to have ChildDef extracted
HTMLPurifier_HTMLModule$moduleModule that defined the ElementDef
Returns
HTMLPurifier_ChildDef corresponding to ElementDef

Definition at line 116 of file ContentSets.php.

Referenced by generateChildDef().

117  {
118  $value = $def->content_model;
119  if (is_object($value)) {
120  trigger_error(
121  'Literal object child definitions should be stored in '.
122  'ElementDef->child not ElementDef->content_model',
123  E_USER_NOTICE
124  );
125  return $value;
126  }
127  switch ($def->content_model_type) {
128  case 'required':
129  return new HTMLPurifier_ChildDef_Required($value);
130  case 'optional':
131  return new HTMLPurifier_ChildDef_Optional($value);
132  case 'empty':
133  return new HTMLPurifier_ChildDef_Empty();
134  case 'custom':
135  return new HTMLPurifier_ChildDef_Custom($value);
136  }
137  // defer to its module
138  $return = false;
139  if ($module->defines_child_def) { // save a func call
140  $return = $module->getChildDef($def);
141  }
142  if ($return !== false) {
143  return $return;
144  }
145  // error-out
146  trigger_error(
147  'Could not determine which ChildDef class to instantiate',
148  E_USER_ERROR
149  );
150  return false;
151  }
Definition that allows a set of elements, but disallows empty children.
Definition: Required.php:6
Definition that disallows all elements.
Definition: Empty.php:10
Custom validation class, accepts DTD child definitions.
Definition: Custom.php:9
Definition that allows a set of elements, and allows no children.
Definition: Optional.php:10
+ Here is the caller graph for this function:

Field Documentation

◆ $info

HTMLPurifier_ContentSets::$info = array()

List of content set strings (pipe separators) indexed by name.

array

Definition at line 13 of file ContentSets.php.

◆ $keys

HTMLPurifier_ContentSets::$keys = array()
protected

Synchronized list of defined content sets (keys of info).

array

Definition at line 26 of file ContentSets.php.

◆ $lookup

HTMLPurifier_ContentSets::$lookup = array()

List of content set lookups (element => true) indexed by name.

array

Note
This is in HTMLPurifier_HTMLDefinition->info_content_sets

Definition at line 20 of file ContentSets.php.

Referenced by __construct().

◆ $values

HTMLPurifier_ContentSets::$values = array()
protected

Synchronized list of defined content values (values of info).

array

Definition at line 31 of file ContentSets.php.


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