ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules 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)
 
- Public Member Functions inherited from HTMLPurifier_ChildDef
 getAllowedElements ($config)
 Get lookup of tag names that should not close this element automatically. More...
 
 validateChildren ($tokens_of_children, $config, $context)
 Validates nodes according to definition and returns modification. More...
 

Data Fields

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

Protected Attributes

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

Detailed Description

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

Definition at line 6 of file Required.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 20 of file Required.php.

References $elements.

20  {
21  if (is_string($elements)) {
22  $elements = str_replace(' ', '', $elements);
23  $elements = explode('|', $elements);
24  }
25  $keys = array_keys($elements);
26  if ($keys == array_keys($keys)) {
27  $elements = array_flip($elements);
28  foreach ($elements as $i => $x) {
29  $elements[$i] = true;
30  if (empty($i)) unset($elements[$i]); // remove blank
31  }
32  }
33  $this->elements = $elements;
34  }
$elements
Lookup table of allowed elements.
Definition: Required.php:12

Member Function Documentation

◆ validateChildren()

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

Definition at line 37 of file Required.php.

References $result.

37  {
38  // Flag for subclasses
39  $this->whitespace = false;
40 
41  // if there are no tokens, delete parent node
42  if (empty($tokens_of_children)) return false;
43 
44  // the new set of children
45  $result = array();
46 
47  // current depth into the nest
48  $nesting = 0;
49 
50  // whether or not we're deleting a node
51  $is_deleting = false;
52 
53  // whether or not parsed character data is allowed
54  // this controls whether or not we silently drop a tag
55  // or generate escaped HTML from it
56  $pcdata_allowed = isset($this->elements['#PCDATA']);
57 
58  // a little sanity check to make sure it's not ALL whitespace
59  $all_whitespace = true;
60 
61  // some configuration
62  $escape_invalid_children = $config->get('Core.EscapeInvalidChildren');
63 
64  // generator
65  $gen = new HTMLPurifier_Generator($config, $context);
66 
67  foreach ($tokens_of_children as $token) {
68  if (!empty($token->is_whitespace)) {
69  $result[] = $token;
70  continue;
71  }
72  $all_whitespace = false; // phew, we're not talking about whitespace
73 
74  $is_child = ($nesting == 0);
75 
76  if ($token instanceof HTMLPurifier_Token_Start) {
77  $nesting++;
78  } elseif ($token instanceof HTMLPurifier_Token_End) {
79  $nesting--;
80  }
81 
82  if ($is_child) {
83  $is_deleting = false;
84  if (!isset($this->elements[$token->name])) {
85  $is_deleting = true;
86  if ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text) {
87  $result[] = $token;
88  } elseif ($pcdata_allowed && $escape_invalid_children) {
89  $result[] = new HTMLPurifier_Token_Text(
90  $gen->generateFromToken($token)
91  );
92  }
93  continue;
94  }
95  }
96  if (!$is_deleting || ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text)) {
97  $result[] = $token;
98  } elseif ($pcdata_allowed && $escape_invalid_children) {
99  $result[] =
100  new HTMLPurifier_Token_Text(
101  $gen->generateFromToken($token)
102  );
103  } else {
104  // drop silently
105  }
106  }
107  if (empty($result)) return false;
108  if ($all_whitespace) {
109  $this->whitespace = true;
110  return false;
111  }
112  if ($tokens_of_children == $result) return true;
113  return $result;
114  }
Concrete end token class.
Definition: End.php:10
$result
Generates HTML from tokens.
Definition: Generator.php:10
Concrete start token class.
Definition: Start.php:6
Concrete text token class.
Definition: Text.php:12

Field Documentation

◆ $allow_empty

HTMLPurifier_ChildDef_Required::$allow_empty = false

Definition at line 35 of file Required.php.

◆ $elements

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

◆ $type

HTMLPurifier_ChildDef_Required::$type = 'required'

Definition at line 36 of file Required.php.

◆ $whitespace

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: