Chameleon.php 1.9 KB

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