Chameleon.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. */
  16. public $inline;
  17. /**
  18. * Instance of the definition object to use when block.
  19. */
  20. public $block;
  21. public $type = 'chameleon';
  22. /**
  23. * @param $inline List of elements to allow when inline.
  24. * @param $block List of elements to allow when block.
  25. */
  26. public function __construct($inline, $block) {
  27. $this->inline = new HTMLPurifier_ChildDef_Optional($inline);
  28. $this->block = new HTMLPurifier_ChildDef_Optional($block);
  29. $this->elements = $this->block->elements;
  30. }
  31. public function validateChildren($tokens_of_children, $config, $context) {
  32. if ($context->get('IsInline') === false) {
  33. return $this->block->validateChildren(
  34. $tokens_of_children, $config, $context);
  35. } else {
  36. return $this->inline->validateChildren(
  37. $tokens_of_children, $config, $context);
  38. }
  39. }
  40. }
  41. // vim: et sw=4 sts=4