ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
 generateChildDef (&$def, $module)
 Accepts a definition; generates and assigns a ChildDef for it.
 generateChildDefCallback ($matches)
 getChildDef ($def, $module)
 Instantiates a ChildDef based on content_model and content_model_type member variables in HTMLPurifier_ElementDef.

Data Fields

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

Protected Member Functions

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

Protected Attributes

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

Detailed Description

Todo:
Unit test

Definition at line 6 of file ContentSets.php.

Constructor & Destructor Documentation

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, $x, and convertToLookup().

{
if (!is_array($modules)) $modules = array($modules);
// populate content_sets based on module hints
// sorry, no way of overloading
foreach ($modules as $module_i => $module) {
foreach ($module->content_sets as $key => $value) {
$temp = $this->convertToLookup($value);
if (isset($this->lookup[$key])) {
// add it into the existing content set
$this->lookup[$key] = array_merge($this->lookup[$key], $temp);
} else {
$this->lookup[$key] = $temp;
}
}
}
$old_lookup = false;
while ($old_lookup !== $this->lookup) {
$old_lookup = $this->lookup;
foreach ($this->lookup as $i => $set) {
$add = array();
foreach ($set as $element => $x) {
if (isset($this->lookup[$element])) {
$add += $this->lookup[$element];
unset($this->lookup[$i][$element]);
}
}
$this->lookup[$i] += $add;
}
}
foreach ($this->lookup as $key => $lookup) {
$this->info[$key] = implode(' | ', array_keys($lookup));
}
$this->keys = array_keys($this->info);
$this->values = array_values($this->info);
}

+ Here is the call graph for this function:

Member Function Documentation

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().

{
$array = explode('|', str_replace(' ', '', $string));
$ret = array();
foreach ($array as $i => $k) {
$ret[$k] = true;
}
return $ret;
}

+ Here is the caller graph for this function:

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().

{
if (!empty($def->child)) return; // already done!
$content_model = $def->content_model;
if (is_string($content_model)) {
// Assume that $this->keys is alphanumeric
$def->content_model = preg_replace_callback(
'/\b(' . implode('|', $this->keys) . ')\b/',
array($this, 'generateChildDefCallback'),
$content_model
);
//$def->content_model = str_replace(
// $this->keys, $this->values, $content_model);
}
$def->child = $this->getChildDef($def, $module);
}

+ Here is the call graph for this function:

HTMLPurifier_ContentSets::generateChildDefCallback (   $matches)

Definition at line 92 of file ContentSets.php.

{
return $this->info[$matches[0]];
}
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().

{
$value = $def->content_model;
if (is_object($value)) {
trigger_error(
'Literal object child definitions should be stored in '.
'ElementDef->child not ElementDef->content_model',
E_USER_NOTICE
);
return $value;
}
switch ($def->content_model_type) {
case 'required':
return new HTMLPurifier_ChildDef_Required($value);
case 'optional':
return new HTMLPurifier_ChildDef_Optional($value);
case 'empty':
case 'custom':
return new HTMLPurifier_ChildDef_Custom($value);
}
// defer to its module
$return = false;
if ($module->defines_child_def) { // save a func call
$return = $module->getChildDef($def);
}
if ($return !== false) return $return;
// error-out
trigger_error(
'Could not determine which ChildDef class to instantiate',
E_USER_ERROR
);
return false;
}

+ Here is the caller graph for this function:

Field Documentation

HTMLPurifier_ContentSets::$info = array()

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

Definition at line 12 of file ContentSets.php.

HTMLPurifier_ContentSets::$keys = array()
protected

Synchronized list of defined content sets (keys of info)

Definition at line 23 of file ContentSets.php.

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().

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: