Border.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. */
  10. protected $info = array();
  11. public function __construct($config) {
  12. $def = $config->getCSSDefinition();
  13. $this->info['border-width'] = $def->info['border-width'];
  14. $this->info['border-style'] = $def->info['border-style'];
  15. $this->info['border-top-color'] = $def->info['border-top-color'];
  16. }
  17. public function validate($string, $config, $context) {
  18. $string = $this->parseCDATA($string);
  19. $string = $this->mungeRgb($string);
  20. $bits = explode(' ', $string);
  21. $done = array(); // segments we've finished
  22. $ret = ''; // return value
  23. foreach ($bits as $bit) {
  24. foreach ($this->info as $propname => $validator) {
  25. if (isset($done[$propname])) continue;
  26. $r = $validator->validate($bit, $config, $context);
  27. if ($r !== false) {
  28. $ret .= $r . ' ';
  29. $done[$propname] = true;
  30. break;
  31. }
  32. }
  33. }
  34. return rtrim($ret);
  35. }
  36. }
  37. // vim: et sw=4 sts=4