Release 4.9.2
[htmlpurifier.git] / library / HTMLPurifier / ChildDef / Chameleon.php
blob7439be26b644d80fdce002890cb87a2228b11997
1 <?php
3 /**
4 * Definition that uses different definitions depending on context.
6 * The del and ins tags are notable because they allow different types of
7 * elements depending on whether or not they're in a block or inline context.
8 * Chameleon allows this behavior to happen by using two different
9 * definitions depending on context. While this somewhat generalized,
10 * it is specifically intended for those two tags.
12 class HTMLPurifier_ChildDef_Chameleon extends HTMLPurifier_ChildDef
15 /**
16 * Instance of the definition object to use when inline. Usually stricter.
17 * @type HTMLPurifier_ChildDef_Optional
19 public $inline;
21 /**
22 * Instance of the definition object to use when block.
23 * @type HTMLPurifier_ChildDef_Optional
25 public $block;
27 /**
28 * @type string
30 public $type = 'chameleon';
32 /**
33 * @param array $inline List of elements to allow when inline.
34 * @param array $block List of elements to allow when block.
36 public function __construct($inline, $block)
38 $this->inline = new HTMLPurifier_ChildDef_Optional($inline);
39 $this->block = new HTMLPurifier_ChildDef_Optional($block);
40 $this->elements = $this->block->elements;
43 /**
44 * @param HTMLPurifier_Node[] $children
45 * @param HTMLPurifier_Config $config
46 * @param HTMLPurifier_Context $context
47 * @return bool
49 public function validateChildren($children, $config, $context)
51 if ($context->get('IsInline') === false) {
52 return $this->block->validateChildren(
53 $children,
54 $config,
55 $context
57 } else {
58 return $this->inline->validateChildren(
59 $children,
60 $config,
61 $context
67 // vim: et sw=4 sts=4