BoolToCSS.php 867 B

123456789101112131415161718192021222324252627282930313233343536
  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. * Name of boolean attribute that is trigger
  8. */
  9. protected $attr;
  10. /**
  11. * CSS declarations to add to style, needs trailing semicolon
  12. */
  13. protected $css;
  14. /**
  15. * @param $attr string attribute name to convert from
  16. * @param $css string CSS declarations to add to style (needs semicolon)
  17. */
  18. public function __construct($attr, $css) {
  19. $this->attr = $attr;
  20. $this->css = $css;
  21. }
  22. public function transform($attr, $config, $context) {
  23. if (!isset($attr[$this->attr])) return $attr;
  24. unset($attr[$this->attr]);
  25. $this->prependCSS($attr, $this->css);
  26. return $attr;
  27. }
  28. }
  29. // vim: et sw=4 sts=4