Border.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Validates the border property as defined by CSS.
  4. */
  5. class HTMLPurifier_AttrDef_CSS_Border extends HTMLPurifier_AttrDef
  6. {
  7. /**
  8. * Local copy of properties this property is shorthand for.
  9. * @type HTMLPurifier_AttrDef[]
  10. */
  11. protected $info = array();
  12. /**
  13. * @param HTMLPurifier_Config $config
  14. */
  15. public function __construct($config)
  16. {
  17. $def = $config->getCSSDefinition();
  18. $this->info['border-width'] = $def->info['border-width'];
  19. $this->info['border-style'] = $def->info['border-style'];
  20. $this->info['border-top-color'] = $def->info['border-top-color'];
  21. }
  22. /**
  23. * @param string $string
  24. * @param HTMLPurifier_Config $config
  25. * @param HTMLPurifier_Context $context
  26. * @return bool|string
  27. */
  28. public function validate($string, $config, $context)
  29. {
  30. $string = $this->parseCDATA($string);
  31. $string = $this->mungeRgb($string);
  32. $bits = explode(' ', $string);
  33. $done = array(); // segments we've finished
  34. $ret = ''; // return value
  35. foreach ($bits as $bit) {
  36. foreach ($this->info as $propname => $validator) {
  37. if (isset($done[$propname])) {
  38. continue;
  39. }
  40. $r = $validator->validate($bit, $config, $context);
  41. if ($r !== false) {
  42. $ret .= $r . ' ';
  43. $done[$propname] = true;
  44. break;
  45. }
  46. }
  47. }
  48. return rtrim($ret);
  49. }
  50. }
  51. // vim: et sw=4 sts=4