ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HTMLPurifier_ChildDef_Custom Class Reference

Custom validation class, accepts DTD child definitions. More...

+ Inheritance diagram for HTMLPurifier_ChildDef_Custom:
+ Collaboration diagram for HTMLPurifier_ChildDef_Custom:

Public Member Functions

 __construct ($dtd_regex)
 
 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

 $type = 'custom'
 @type string More...
 
 $allow_empty = false
 @type bool More...
 
 $dtd_regex
 Allowed child pattern as defined by the DTD. 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 Member Functions

 _compileRegex ()
 Compiles the PCRE regex from a DTD regex ($dtd_regex to $_pcre_regex) More...
 

Private Attributes

 $_pcre_regex
 PCRE regex derived from $dtd_regex. More...
 

Detailed Description

Custom validation class, accepts DTD child definitions.

Warning
Currently this class is an all or nothing proposition, that is, it will only give a bool return value.

Definition at line 9 of file Custom.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_ChildDef_Custom::__construct (   $dtd_regex)
Parameters
$dtd_regexAllowed child pattern from the DTD

Definition at line 36 of file Custom.php.

37 {
38 $this->dtd_regex = $dtd_regex;
39 $this->_compileRegex();
40 }
_compileRegex()
Compiles the PCRE regex from a DTD regex ($dtd_regex to $_pcre_regex)
Definition: Custom.php:45
$dtd_regex
Allowed child pattern as defined by the DTD.
Definition: Custom.php:25

References $dtd_regex, and _compileRegex().

+ Here is the call graph for this function:

Member Function Documentation

◆ _compileRegex()

HTMLPurifier_ChildDef_Custom::_compileRegex ( )
protected

Compiles the PCRE regex from a DTD regex ($dtd_regex to $_pcre_regex)

Definition at line 45 of file Custom.php.

46 {
47 $raw = str_replace(' ', '', $this->dtd_regex);
48 if ($raw{0} != '(') {
49 $raw = "($raw)";
50 }
51 $el = '[#a-zA-Z0-9_.-]+';
52 $reg = $raw;
53
54 // COMPLICATED! AND MIGHT BE BUGGY! I HAVE NO CLUE WHAT I'M
55 // DOING! Seriously: if there's problems, please report them.
56
57 // collect all elements into the $elements array
58 preg_match_all("/$el/", $reg, $matches);
59 foreach ($matches[0] as $match) {
60 $this->elements[$match] = true;
61 }
62
63 // setup all elements as parentheticals with leading commas
64 $reg = preg_replace("/$el/", '(,\\0)', $reg);
65
66 // remove commas when they were not solicited
67 $reg = preg_replace("/([^,(|]\‍(+),/", '\\1', $reg);
68
69 // remove all non-paranthetical commas: they are handled by first regex
70 $reg = preg_replace("/,\‍(/", '(', $reg);
71
72 $this->_pcre_regex = $reg;
73 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ validateChildren()

HTMLPurifier_ChildDef_Custom::validateChildren (   $children,
  $config,
  $context 
)
Parameters
HTMLPurifier_Node[]$children
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool

Reimplemented from HTMLPurifier_ChildDef.

Definition at line 81 of file Custom.php.

82 {
83 $list_of_children = '';
84 $nesting = 0; // depth into the nest
85 foreach ($children as $node) {
86 if (!empty($node->is_whitespace)) {
87 continue;
88 }
89 $list_of_children .= $node->name . ',';
90 }
91 // add leading comma to deal with stray comma declarations
92 $list_of_children = ',' . rtrim($list_of_children, ',');
93 $okay =
94 preg_match(
95 '/^,?' . $this->_pcre_regex . '$/',
96 $list_of_children
97 );
98 return (bool)$okay;
99 }

Field Documentation

◆ $_pcre_regex

HTMLPurifier_ChildDef_Custom::$_pcre_regex
private

PCRE regex derived from $dtd_regex.

@type string

Definition at line 31 of file Custom.php.

◆ $allow_empty

HTMLPurifier_ChildDef_Custom::$allow_empty = false

@type bool

Definition at line 19 of file Custom.php.

◆ $dtd_regex

HTMLPurifier_ChildDef_Custom::$dtd_regex

Allowed child pattern as defined by the DTD.

@type string

Definition at line 25 of file Custom.php.

Referenced by __construct().

◆ $type

HTMLPurifier_ChildDef_Custom::$type = 'custom'

@type string

Definition at line 14 of file Custom.php.


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