ILIAS  release_4-4 Revision
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 ($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

 $type = 'custom'
 
 $allow_empty = false
 
 $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
 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 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 25 of file Custom.php.

References $dtd_regex, and _compileRegex().

25  {
26  $this->dtd_regex = $dtd_regex;
27  $this->_compileRegex();
28  }
$dtd_regex
Allowed child pattern as defined by the DTD.
Definition: Custom.php:16
_compileRegex()
Compiles the PCRE regex from a DTD regex ($dtd_regex to $_pcre_regex)
Definition: Custom.php:32
+ 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 32 of file Custom.php.

Referenced by __construct().

32  {
33  $raw = str_replace(' ', '', $this->dtd_regex);
34  if ($raw{0} != '(') {
35  $raw = "($raw)";
36  }
37  $el = '[#a-zA-Z0-9_.-]+';
38  $reg = $raw;
39 
40  // COMPLICATED! AND MIGHT BE BUGGY! I HAVE NO CLUE WHAT I'M
41  // DOING! Seriously: if there's problems, please report them.
42 
43  // collect all elements into the $elements array
44  preg_match_all("/$el/", $reg, $matches);
45  foreach ($matches[0] as $match) {
46  $this->elements[$match] = true;
47  }
48 
49  // setup all elements as parentheticals with leading commas
50  $reg = preg_replace("/$el/", '(,\\0)', $reg);
51 
52  // remove commas when they were not solicited
53  $reg = preg_replace("/([^,(|]\(+),/", '\\1', $reg);
54 
55  // remove all non-paranthetical commas: they are handled by first regex
56  $reg = preg_replace("/,\(/", '(', $reg);
57 
58  $this->_pcre_regex = $reg;
59  }
+ Here is the caller graph for this function:

◆ validateChildren()

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

Definition at line 60 of file Custom.php.

60  {
61  $list_of_children = '';
62  $nesting = 0; // depth into the nest
63  foreach ($tokens_of_children as $token) {
64  if (!empty($token->is_whitespace)) continue;
65 
66  $is_child = ($nesting == 0); // direct
67 
68  if ($token instanceof HTMLPurifier_Token_Start) {
69  $nesting++;
70  } elseif ($token instanceof HTMLPurifier_Token_End) {
71  $nesting--;
72  }
73 
74  if ($is_child) {
75  $list_of_children .= $token->name . ',';
76  }
77  }
78  // add leading comma to deal with stray comma declarations
79  $list_of_children = ',' . rtrim($list_of_children, ',');
80  $okay =
81  preg_match(
82  '/^,?'.$this->_pcre_regex.'$/',
83  $list_of_children
84  );
85 
86  return (bool) $okay;
87  }
Concrete end token class.
Definition: End.php:10
Concrete start token class.
Definition: Start.php:6

Field Documentation

◆ $_pcre_regex

HTMLPurifier_ChildDef_Custom::$_pcre_regex
private

PCRE regex derived from $dtd_regex.

Definition at line 21 of file Custom.php.

◆ $allow_empty

HTMLPurifier_ChildDef_Custom::$allow_empty = false

Definition at line 12 of file Custom.php.

◆ $dtd_regex

HTMLPurifier_ChildDef_Custom::$dtd_regex

Allowed child pattern as defined by the DTD.

Definition at line 16 of file Custom.php.

Referenced by __construct().

◆ $type

HTMLPurifier_ChildDef_Custom::$type = 'custom'

Definition at line 11 of file Custom.php.


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