HTMLPurifier_ChildDef_Required::validateChildren PHP Method

validateChildren() public method

public validateChildren ( array $children, HTMLPurifier_Config $config, HTMLPurifier_Context $context ) : array
$children array
$config HTMLPurifier_Config
$context HTMLPurifier_Context
return array
    public function validateChildren($children, $config, $context)
    {
        // Flag for subclasses
        $this->whitespace = false;
        // if there are no tokens, delete parent node
        if (empty($children)) {
            return false;
        }
        // the new set of children
        $result = array();
        // whether or not parsed character data is allowed
        // this controls whether or not we silently drop a tag
        // or generate escaped HTML from it
        $pcdata_allowed = isset($this->elements['#PCDATA']);
        // a little sanity check to make sure it's not ALL whitespace
        $all_whitespace = true;
        $stack = array_reverse($children);
        while (!empty($stack)) {
            $node = array_pop($stack);
            if (!empty($node->is_whitespace)) {
                $result[] = $node;
                continue;
            }
            $all_whitespace = false;
            // phew, we're not talking about whitespace
            if (!isset($this->elements[$node->name])) {
                // special case text
                // XXX One of these ought to be redundant or something
                if ($pcdata_allowed && $node instanceof HTMLPurifier_Node_Text) {
                    $result[] = $node;
                    continue;
                }
                // spill the child contents in
                // ToDo: Make configurable
                if ($node instanceof HTMLPurifier_Node_Element) {
                    for ($i = count($node->children) - 1; $i >= 0; $i--) {
                        $stack[] = $node->children[$i];
                    }
                    continue;
                }
                continue;
            }
            $result[] = $node;
        }
        if (empty($result)) {
            return false;
        }
        if ($all_whitespace) {
            $this->whitespace = true;
            return false;
        }
        return $result;
    }

Usage Example

Exemplo n.º 1
0
 function validateChildren($tokens_of_children, $config, &$context)
 {
     $result = parent::validateChildren($tokens_of_children, $config, $context);
     if ($result === false) {
         return array();
     }
     return $result;
 }
All Usage Examples Of HTMLPurifier_ChildDef_Required::validateChildren
HTMLPurifier_ChildDef_Required