BoolToCSS.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Pre-transform that changes converts a boolean attribute to fixed CSS
  4. */
  5. class HTMLPurifier_AttrTransform_BoolToCSS extends HTMLPurifier_AttrTransform
  6. {
  7. /**
  8. * Name of boolean attribute that is trigger.
  9. * @type string
  10. */
  11. protected $attr;
  12. /**
  13. * CSS declarations to add to style, needs trailing semicolon.
  14. * @type string
  15. */
  16. protected $css;
  17. /**
  18. * @param string $attr attribute name to convert from
  19. * @param string $css CSS declarations to add to style (needs semicolon)
  20. */
  21. public function __construct($attr, $css)
  22. {
  23. $this->attr = $attr;
  24. $this->css = $css;
  25. }
  26. /**
  27. * @param array $attr
  28. * @param HTMLPurifier_Config $config
  29. * @param HTMLPurifier_Context $context
  30. * @return array
  31. */
  32. public function transform($attr, $config, $context)
  33. {
  34. if (!isset($attr[$this->attr])) {
  35. return $attr;
  36. }
  37. unset($attr[$this->attr]);
  38. $this->prependCSS($attr, $this->css);
  39. return $attr;
  40. }
  41. }
  42. // vim: et sw=4 sts=4