AlphaValue.php 562 B

123456789101112131415161718192021
  1. <?php
  2. class HTMLPurifier_AttrDef_CSS_AlphaValue extends HTMLPurifier_AttrDef_CSS_Number
  3. {
  4. public function __construct() {
  5. parent::__construct(false); // opacity is non-negative, but we will clamp it
  6. }
  7. public function validate($number, $config, $context) {
  8. $result = parent::validate($number, $config, $context);
  9. if ($result === false) return $result;
  10. $float = (float) $result;
  11. if ($float < 0.0) $result = '0';
  12. if ($float > 1.0) $result = '1';
  13. return $result;
  14. }
  15. }
  16. // vim: et sw=4 sts=4