選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Optional.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. /**
  12. * @type bool
  13. */
  14. public $allow_empty = true;
  15. /**
  16. * @type string
  17. */
  18. public $type = 'optional';
  19. /**
  20. * @param array $children
  21. * @param HTMLPurifier_Config $config
  22. * @param HTMLPurifier_Context $context
  23. * @return array
  24. */
  25. public function validateChildren($children, $config, $context)
  26. {
  27. $result = parent::validateChildren($children, $config, $context);
  28. // we assume that $children is not modified
  29. if ($result === false) {
  30. if (empty($children)) {
  31. return true;
  32. } elseif ($this->whitespace) {
  33. return $children;
  34. } else {
  35. return array();
  36. }
  37. }
  38. return $result;
  39. }
  40. }
  41. // vim: et sw=4 sts=4