国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

55 lines
1.3KB

  1. <?php
  2. /**
  3. * Validates a Percentage as defined by the CSS spec.
  4. */
  5. class HTMLPurifier_AttrDef_CSS_Percentage extends HTMLPurifier_AttrDef
  6. {
  7. /**
  8. * Instance to defer number validation to.
  9. * @type HTMLPurifier_AttrDef_CSS_Number
  10. */
  11. protected $number_def;
  12. /**
  13. * @param bool $non_negative Whether to forbid negative values
  14. */
  15. public function __construct($non_negative = false)
  16. {
  17. $this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative);
  18. }
  19. /**
  20. * @param string $string
  21. * @param HTMLPurifier_Config $config
  22. * @param HTMLPurifier_Context $context
  23. * @return bool|string
  24. */
  25. public function validate($string, $config, $context)
  26. {
  27. $string = $this->parseCDATA($string);
  28. if ($string === '') {
  29. return false;
  30. }
  31. $length = strlen($string);
  32. if ($length === 1) {
  33. return false;
  34. }
  35. if ($string[$length - 1] !== '%') {
  36. return false;
  37. }
  38. $number = substr($string, 0, $length - 1);
  39. $number = $this->number_def->validate($number, $config, $context);
  40. if ($number === false) {
  41. return false;
  42. }
  43. return "$number%";
  44. }
  45. }
  46. // vim: et sw=4 sts=4