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

Data Fields

 $type = 'custom'
 $allow_empty = false
 $dtd_regex
 Allowed child pattern as defined by the DTD.
- Data Fields inherited from HTMLPurifier_ChildDef
 $type
 Type of child definition, usually right-most part of class name lowercase.
 $allow_empty
 Bool that indicates whether or not an empty array of children is okay.
 $elements = array()
 Lookup array of all elements that this definition could possibly allow.

Protected Member Functions

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

Private Attributes

 $_pcre_regex
 PCRE regex derived from $dtd_regex.

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

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

{
$this->dtd_regex = $dtd_regex;
$this->_compileRegex();
}

+ Here is the call graph for this function:

Member Function Documentation

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

{
$raw = str_replace(' ', '', $this->dtd_regex);
if ($raw{0} != '(') {
$raw = "($raw)";
}
$el = '[#a-zA-Z0-9_.-]+';
$reg = $raw;
// COMPLICATED! AND MIGHT BE BUGGY! I HAVE NO CLUE WHAT I'M
// DOING! Seriously: if there's problems, please report them.
// collect all elements into the $elements array
preg_match_all("/$el/", $reg, $matches);
foreach ($matches[0] as $match) {
$this->elements[$match] = true;
}
// setup all elements as parentheticals with leading commas
$reg = preg_replace("/$el/", '(,\\0)', $reg);
// remove commas when they were not solicited
$reg = preg_replace("/([^,(|]\(+),/", '\\1', $reg);
// remove all non-paranthetical commas: they are handled by first regex
$reg = preg_replace("/,\(/", '(', $reg);
$this->_pcre_regex = $reg;
}

+ Here is the caller graph for this function:

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

Validates nodes according to definition and returns modification.

Parameters
$tokens_of_childrenArray of HTMLPurifier_Token
$configHTMLPurifier_Config object
$contextHTMLPurifier_Context object
Returns
bool true to leave nodes as is
bool false to remove parent node
array of replacement child tokens

Reimplemented from HTMLPurifier_ChildDef.

Definition at line 60 of file Custom.php.

References elseif().

{
$list_of_children = '';
$nesting = 0; // depth into the nest
foreach ($tokens_of_children as $token) {
if (!empty($token->is_whitespace)) continue;
$is_child = ($nesting == 0); // direct
if ($token instanceof HTMLPurifier_Token_Start) {
$nesting++;
} elseif ($token instanceof HTMLPurifier_Token_End) {
$nesting--;
}
if ($is_child) {
$list_of_children .= $token->name . ',';
}
}
// add leading comma to deal with stray comma declarations
$list_of_children = ',' . rtrim($list_of_children, ',');
$okay =
preg_match(
'/^,?'.$this->_pcre_regex.'$/',
$list_of_children
);
return (bool) $okay;
}

+ Here is the call graph for this function:

Field Documentation

HTMLPurifier_ChildDef_Custom::$_pcre_regex
private

PCRE regex derived from $dtd_regex.

Definition at line 21 of file Custom.php.

HTMLPurifier_ChildDef_Custom::$allow_empty = false

Definition at line 12 of file Custom.php.

HTMLPurifier_ChildDef_Custom::$dtd_regex

Allowed child pattern as defined by the DTD.

Definition at line 16 of file Custom.php.

Referenced by __construct().

HTMLPurifier_ChildDef_Custom::$type = 'custom'

Definition at line 11 of file Custom.php.


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