AlphaValue.php 793 B

12345678910111213141516171819202122232425262728293031323334
  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