ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 ($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 ($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 bool More...
 
 $type = 'required'
 @type string More...
 
- Data Fields inherited from HTMLPurifier_ChildDef
 $type
 Type of child definition, usually right-most part of class name lowercase. More...
 
 $allow_empty
 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
array | string$elementsList of allowed element names (lowercase).

Definition at line 23 of file Required.php.

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

References $elements, and $x.

Member Function Documentation

◆ validateChildren()

HTMLPurifier_ChildDef_Required::validateChildren (   $children,
  $config,
  $context 
)
Parameters
array$children
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
array

Reimplemented from HTMLPurifier_ChildDef.

Reimplemented in HTMLPurifier_ChildDef_Optional, and HTMLPurifier_ChildDef_StrictBlockquote.

Definition at line 58 of file Required.php.

59 {
60 // Flag for subclasses
61 $this->whitespace = false;
62
63 // if there are no tokens, delete parent node
64 if (empty($children)) {
65 return false;
66 }
67
68 // the new set of children
69 $result = array();
70
71 // whether or not parsed character data is allowed
72 // this controls whether or not we silently drop a tag
73 // or generate escaped HTML from it
74 $pcdata_allowed = isset($this->elements['#PCDATA']);
75
76 // a little sanity check to make sure it's not ALL whitespace
77 $all_whitespace = true;
78
79 $stack = array_reverse($children);
80 while (!empty($stack)) {
81 $node = array_pop($stack);
82 if (!empty($node->is_whitespace)) {
83 $result[] = $node;
84 continue;
85 }
86 $all_whitespace = false; // phew, we're not talking about whitespace
87
88 if (!isset($this->elements[$node->name])) {
89 // special case text
90 // XXX One of these ought to be redundant or something
91 if ($pcdata_allowed && $node instanceof HTMLPurifier_Node_Text) {
92 $result[] = $node;
93 continue;
94 }
95 // spill the child contents in
96 // ToDo: Make configurable
97 if ($node instanceof HTMLPurifier_Node_Element) {
98 for ($i = count($node->children) - 1; $i >= 0; $i--) {
99 $stack[] = $node->children[$i];
100 }
101 continue;
102 }
103 continue;
104 }
105 $result[] = $node;
106 }
107 if (empty($result)) {
108 return false;
109 }
110 if ($all_whitespace) {
111 $this->whitespace = true;
112 return false;
113 }
114 return $result;
115 }
$result
Concrete element node class.
Definition: Element.php:7
Concrete text token class.
Definition: Text.php:13

References $result.

Field Documentation

◆ $allow_empty

HTMLPurifier_ChildDef_Required::$allow_empty = false

@type bool

Definition at line 45 of file Required.php.

◆ $elements

HTMLPurifier_ChildDef_Required::$elements = array()

Lookup table of allowed elements.

@type array

Definition at line 12 of file Required.php.

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

◆ $type

HTMLPurifier_ChildDef_Required::$type = 'required'

@type string

Definition at line 50 of file Required.php.

◆ $whitespace

HTMLPurifier_ChildDef_Required::$whitespace = false
protected

Whether or not the last passed node was all whitespace.

@type bool

Definition at line 18 of file Required.php.


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