Length.php 706 B

123456789101112131415161718192021222324252627
  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. protected $name;
  8. protected $cssName;
  9. public function __construct($name, $css_name = null) {
  10. $this->name = $name;
  11. $this->cssName = $css_name ? $css_name : $name;
  12. }
  13. public function transform($attr, $config, $context) {
  14. if (!isset($attr[$this->name])) return $attr;
  15. $length = $this->confiscateAttr($attr, $this->name);
  16. if(ctype_digit($length)) $length .= 'px';
  17. $this->prependCSS($attr, $this->cssName . ":$length;");
  18. return $attr;
  19. }
  20. }
  21. // vim: et sw=4 sts=4