You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1KB

  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