3 require_once 'HTMLPurifier/ChildDef.php';
6 * Custom validation class, accepts DTD child definitions
8 * @warning Currently this class is an all or nothing proposition, that is,
9 * it will only give a bool return value.
10 * @note This class is currently not used by any code, although it is unit
13 class HTMLPurifier_ChildDef_Custom
extends HTMLPurifier_ChildDef
16 var $allow_empty = false;
18 * Allowed child pattern as defined by the DTD
22 * PCRE regex derived from $dtd_regex
27 * @param $dtd_regex Allowed child pattern from the DTD
29 function HTMLPurifier_ChildDef_Custom($dtd_regex) {
30 $this->dtd_regex
= $dtd_regex;
31 $this->_compileRegex();
34 * Compiles the PCRE regex from a DTD regex ($dtd_regex to $_pcre_regex)
36 function _compileRegex() {
37 $raw = str_replace(' ', '', $this->dtd_regex
);
41 $reg = str_replace(',', ',?', $raw);
42 $reg = preg_replace('/([#a-zA-Z0-9_.-]+)/', '(,?\\0)', $reg);
43 $this->_pcre_regex
= $reg;
45 function validateChildren($tokens_of_children, $config, &$context) {
46 $list_of_children = '';
47 $nesting = 0; // depth into the nest
48 foreach ($tokens_of_children as $token) {
49 if (!empty($token->is_whitespace
)) continue;
51 $is_child = ($nesting == 0); // direct
53 if ($token->type
== 'start') {
55 } elseif ($token->type
== 'end') {
60 $list_of_children .= $token->name
. ',';
63 $list_of_children = rtrim($list_of_children, ',');
67 '/^'.$this->_pcre_regex
.'$/',