ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_ChildDef_Required Class Reference

Definition that allows a set of elements, but disallows empty children. More...

+ Inheritance diagram for HTMLPurifier_ChildDef_Required:
+ Collaboration diagram for HTMLPurifier_ChildDef_Required:

Public Member Functions

 __construct ($elements)
 validateChildren ($tokens_of_children, $config, $context)
 Validates nodes according to definition and returns modification.
- Public Member Functions inherited from HTMLPurifier_ChildDef
 getAllowedElements ($config)
 Get lookup of tag names that should not close this element automatically.

Data Fields

 $elements = array()
 Lookup table of allowed elements.
 $allow_empty = false
 $type = 'required'
- Data Fields inherited from HTMLPurifier_ChildDef
 $type
 Type of child definition, usually right-most part of class name lowercase.
 $allow_empty
 Bool that indicates whether or not an empty array of children is okay.
 $elements = array()
 Lookup array of all elements that this definition could possibly allow.

Protected Attributes

 $whitespace = false
 Whether or not the last passed node was all whitespace.

Detailed Description

Definition that allows a set of elements, but disallows empty children.

Definition at line 6 of file Required.php.

Constructor & Destructor Documentation

HTMLPurifier_ChildDef_Required::__construct (   $elements)
Parameters
$elementsList of allowed element names (lowercase).

Definition at line 20 of file Required.php.

References $elements.

{
if (is_string($elements)) {
$elements = str_replace(' ', '', $elements);
$elements = explode('|', $elements);
}
$keys = array_keys($elements);
if ($keys == array_keys($keys)) {
$elements = array_flip($elements);
foreach ($elements as $i => $x) {
$elements[$i] = true;
if (empty($i)) unset($elements[$i]); // remove blank
}
}
$this->elements = $elements;
}

Member Function Documentation

HTMLPurifier_ChildDef_Required::validateChildren (   $tokens_of_children,
  $config,
  $context 
)

Validates nodes according to definition and returns modification.

Parameters
$tokens_of_childrenArray of HTMLPurifier_Token
$configHTMLPurifier_Config object
$contextHTMLPurifier_Context object
Returns
bool true to leave nodes as is
bool false to remove parent node
array of replacement child tokens

Reimplemented from HTMLPurifier_ChildDef.

Reimplemented in HTMLPurifier_ChildDef_StrictBlockquote, and HTMLPurifier_ChildDef_Optional.

Definition at line 37 of file Required.php.

References $result.

{
// Flag for subclasses
$this->whitespace = false;
// if there are no tokens, delete parent node
if (empty($tokens_of_children)) return false;
// the new set of children
$result = array();
// current depth into the nest
$nesting = 0;
// whether or not we're deleting a node
$is_deleting = false;
// whether or not parsed character data is allowed
// this controls whether or not we silently drop a tag
// or generate escaped HTML from it
$pcdata_allowed = isset($this->elements['#PCDATA']);
// a little sanity check to make sure it's not ALL whitespace
$all_whitespace = true;
// some configuration
$escape_invalid_children = $config->get('Core.EscapeInvalidChildren');
// generator
$gen = new HTMLPurifier_Generator($config, $context);
foreach ($tokens_of_children as $token) {
if (!empty($token->is_whitespace)) {
$result[] = $token;
continue;
}
$all_whitespace = false; // phew, we're not talking about whitespace
$is_child = ($nesting == 0);
if ($token instanceof HTMLPurifier_Token_Start) {
$nesting++;
} elseif ($token instanceof HTMLPurifier_Token_End) {
$nesting--;
}
if ($is_child) {
$is_deleting = false;
if (!isset($this->elements[$token->name])) {
$is_deleting = true;
if ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text) {
$result[] = $token;
} elseif ($pcdata_allowed && $escape_invalid_children) {
$result[] = new HTMLPurifier_Token_Text(
$gen->generateFromToken($token)
);
}
continue;
}
}
if (!$is_deleting || ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text)) {
$result[] = $token;
} elseif ($pcdata_allowed && $escape_invalid_children) {
$result[] =
new HTMLPurifier_Token_Text(
$gen->generateFromToken($token)
);
} else {
// drop silently
}
}
if (empty($result)) return false;
if ($all_whitespace) {
$this->whitespace = true;
return false;
}
if ($tokens_of_children == $result) return true;
return $result;
}

Field Documentation

HTMLPurifier_ChildDef_Required::$allow_empty = false

Definition at line 35 of file Required.php.

HTMLPurifier_ChildDef_Required::$elements = array()

Lookup table of allowed elements.

Definition at line 12 of file Required.php.

Referenced by __construct(), and HTMLPurifier_ChildDef_StrictBlockquote\init().

HTMLPurifier_ChildDef_Required::$type = 'required'

Definition at line 36 of file Required.php.

HTMLPurifier_ChildDef_Required::$whitespace = false
protected

Whether or not the last passed node was all whitespace.

Definition at line 16 of file Required.php.


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