Optional.php 958 B

1234567891011121314151617181920212223242526
  1. <?php
  2. /**
  3. * Definition that allows a set of elements, and allows no children.
  4. * @note This is a hack to reuse code from HTMLPurifier_ChildDef_Required,
  5. * really, one shouldn't inherit from the other. Only altered behavior
  6. * is to overload a returned false with an array. Thus, it will never
  7. * return false.
  8. */
  9. class HTMLPurifier_ChildDef_Optional extends HTMLPurifier_ChildDef_Required
  10. {
  11. public $allow_empty = true;
  12. public $type = 'optional';
  13. public function validateChildren($tokens_of_children, $config, $context) {
  14. $result = parent::validateChildren($tokens_of_children, $config, $context);
  15. // we assume that $tokens_of_children is not modified
  16. if ($result === false) {
  17. if (empty($tokens_of_children)) return true;
  18. elseif ($this->whitespace) return $tokens_of_children;
  19. else return array();
  20. }
  21. return $result;
  22. }
  23. }
  24. // vim: et sw=4 sts=4