Length.php 984 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Class for handling width/height length attribute transformations to CSS
  4. */
  5. class HTMLPurifier_AttrTransform_Length extends HTMLPurifier_AttrTransform
  6. {
  7. /**
  8. * @type string
  9. */
  10. protected $name;
  11. /**
  12. * @type string
  13. */
  14. protected $cssName;
  15. public function __construct($name, $css_name = null)
  16. {
  17. $this->name = $name;
  18. $this->cssName = $css_name ? $css_name : $name;
  19. }
  20. /**
  21. * @param array $attr
  22. * @param HTMLPurifier_Config $config
  23. * @param HTMLPurifier_Context $context
  24. * @return array
  25. */
  26. public function transform($attr, $config, $context)
  27. {
  28. if (!isset($attr[$this->name])) {
  29. return $attr;
  30. }
  31. $length = $this->confiscateAttr($attr, $this->name);
  32. if (ctype_digit($length)) {
  33. $length .= 'px';
  34. }
  35. $this->prependCSS($attr, $this->cssName . ":$length;");
  36. return $attr;
  37. }
  38. }
  39. // vim: et sw=4 sts=4