File indexing completed on 2024-12-22 05:36:19

0001 <?php
0002 
0003 /**
0004  * Definition that uses different definitions depending on context.
0005  *
0006  * The del and ins tags are notable because they allow different types of
0007  * elements depending on whether or not they're in a block or inline context.
0008  * Chameleon allows this behavior to happen by using two different
0009  * definitions depending on context.  While this somewhat generalized,
0010  * it is specifically intended for those two tags.
0011  */
0012 class HTMLPurifier_ChildDef_Chameleon extends HTMLPurifier_ChildDef
0013 {
0014 
0015     /**
0016      * Instance of the definition object to use when inline. Usually stricter.
0017      * @type HTMLPurifier_ChildDef_Optional
0018      */
0019     public $inline;
0020 
0021     /**
0022      * Instance of the definition object to use when block.
0023      * @type HTMLPurifier_ChildDef_Optional
0024      */
0025     public $block;
0026 
0027     /**
0028      * @type string
0029      */
0030     public $type = 'chameleon';
0031 
0032     /**
0033      * @param array $inline List of elements to allow when inline.
0034      * @param array $block List of elements to allow when block.
0035      */
0036     public function __construct($inline, $block)
0037     {
0038         $this->inline = new HTMLPurifier_ChildDef_Optional($inline);
0039         $this->block = new HTMLPurifier_ChildDef_Optional($block);
0040         $this->elements = $this->block->elements;
0041     }
0042 
0043     /**
0044      * @param HTMLPurifier_Node[] $children
0045      * @param HTMLPurifier_Config $config
0046      * @param HTMLPurifier_Context $context
0047      * @return bool
0048      */
0049     public function validateChildren($children, $config, $context)
0050     {
0051         if ($context->get('IsInline') === false) {
0052             return $this->block->validateChildren(
0053                 $children,
0054                 $config,
0055                 $context
0056             );
0057         } else {
0058             return $this->inline->validateChildren(
0059                 $children,
0060                 $config,
0061                 $context
0062             );
0063         }
0064     }
0065 }
0066 
0067 // vim: et sw=4 sts=4