ILIAS  release_4-4 Revision
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 seperators) 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
$modulesList of HTMLPurifier_HTMLModule

Definition at line 34 of file ContentSets.php.

References $lookup, and convertToLookup().

34  {
35  if (!is_array($modules)) $modules = array($modules);
36  // populate content_sets based on module hints
37  // sorry, no way of overloading
38  foreach ($modules as $module_i => $module) {
39  foreach ($module->content_sets as $key => $value) {
40  $temp = $this->convertToLookup($value);
41  if (isset($this->lookup[$key])) {
42  // add it into the existing content set
43  $this->lookup[$key] = array_merge($this->lookup[$key], $temp);
44  } else {
45  $this->lookup[$key] = $temp;
46  }
47  }
48  }
49  $old_lookup = false;
50  while ($old_lookup !== $this->lookup) {
51  $old_lookup = $this->lookup;
52  foreach ($this->lookup as $i => $set) {
53  $add = array();
54  foreach ($set as $element => $x) {
55  if (isset($this->lookup[$element])) {
56  $add += $this->lookup[$element];
57  unset($this->lookup[$i][$element]);
58  }
59  }
60  $this->lookup[$i] += $add;
61  }
62  }
63 
64  foreach ($this->lookup as $key => $lookup) {
65  $this->info[$key] = implode(' | ', array_keys($lookup));
66  }
67  $this->keys = array_keys($this->info);
68  $this->values = array_values($this->info);
69  }
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:18
+ 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
$stringList of elements
Returns
Lookup array of elements

Definition at line 144 of file ContentSets.php.

References $ret.

Referenced by __construct().

144  {
145  $array = explode('|', str_replace(' ', '', $string));
146  $ret = array();
147  foreach ($array as $i => $k) {
148  $ret[$k] = true;
149  }
150  return $ret;
151  }
+ 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
$defHTMLPurifier_ElementDef reference
$moduleModule that defined the ElementDef

Definition at line 76 of file ContentSets.php.

References getChildDef().

76  {
77  if (!empty($def->child)) return; // already done!
78  $content_model = $def->content_model;
79  if (is_string($content_model)) {
80  // Assume that $this->keys is alphanumeric
81  $def->content_model = preg_replace_callback(
82  '/\b(' . implode('|', $this->keys) . ')\b/',
83  array($this, 'generateChildDefCallback'),
84  $content_model
85  );
86  //$def->content_model = str_replace(
87  // $this->keys, $this->values, $content_model);
88  }
89  $def->child = $this->getChildDef($def, $module);
90  }
getChildDef($def, $module)
Instantiates a ChildDef based on content_model and content_model_type member variables in HTMLPurifie...
+ Here is the call graph for this function:

◆ generateChildDefCallback()

HTMLPurifier_ContentSets::generateChildDefCallback (   $matches)

Definition at line 92 of file ContentSets.php.

92  {
93  return $this->info[$matches[0]];
94  }

◆ 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
$defHTMLPurifier_ElementDef to have ChildDef extracted
Returns
HTMLPurifier_ChildDef corresponding to ElementDef

Definition at line 104 of file ContentSets.php.

Referenced by generateChildDef().

104  {
105  $value = $def->content_model;
106  if (is_object($value)) {
107  trigger_error(
108  'Literal object child definitions should be stored in '.
109  'ElementDef->child not ElementDef->content_model',
110  E_USER_NOTICE
111  );
112  return $value;
113  }
114  switch ($def->content_model_type) {
115  case 'required':
116  return new HTMLPurifier_ChildDef_Required($value);
117  case 'optional':
118  return new HTMLPurifier_ChildDef_Optional($value);
119  case 'empty':
120  return new HTMLPurifier_ChildDef_Empty();
121  case 'custom':
122  return new HTMLPurifier_ChildDef_Custom($value);
123  }
124  // defer to its module
125  $return = false;
126  if ($module->defines_child_def) { // save a func call
127  $return = $module->getChildDef($def);
128  }
129  if ($return !== false) return $return;
130  // error-out
131  trigger_error(
132  'Could not determine which ChildDef class to instantiate',
133  E_USER_ERROR
134  );
135  return false;
136  }
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 seperators) indexed by name.

Definition at line 12 of file ContentSets.php.

◆ $keys

HTMLPurifier_ContentSets::$keys = array()
protected

Synchronized list of defined content sets (keys of info)

Definition at line 23 of file ContentSets.php.

◆ $lookup

HTMLPurifier_ContentSets::$lookup = array()

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

Note
This is in HTMLPurifier_HTMLDefinition->info_content_sets

Definition at line 18 of file ContentSets.php.

Referenced by __construct().

◆ $values

HTMLPurifier_ContentSets::$values = array()
protected

Synchronized list of defined content values (values of info)

Definition at line 27 of file ContentSets.php.


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