AlphaValue.php 793 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. class HTMLPurifier_AttrDef_CSS_AlphaValue extends HTMLPurifier_AttrDef_CSS_Number
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct(false); // opacity is non-negative, but we will clamp it
  7. }
  8. /**
  9. * @param string $number
  10. * @param HTMLPurifier_Config $config
  11. * @param HTMLPurifier_Context $context
  12. * @return string
  13. */
  14. public function validate($number, $config, $context)
  15. {
  16. $result = parent::validate($number, $config, $context);
  17. if ($result === false) {
  18. return $result;
  19. }
  20. $float = (float)$result;
  21. if ($float < 0.0) {
  22. $result = '0';
  23. }
  24. if ($float > 1.0) {
  25. $result = '1';
  26. }
  27. return $result;
  28. }
  29. }
  30. // vim: et sw=4 sts=4