No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

61 líneas
1.9KB

  1. <?php
  2. /**
  3. * Processes an entire attribute array for corrections needing multiple values.
  4. *
  5. * Occasionally, a certain attribute will need to be removed and popped onto
  6. * another value. Instead of creating a complex return syntax for
  7. * HTMLPurifier_AttrDef, we just pass the whole attribute array to a
  8. * specialized object and have that do the special work. That is the
  9. * family of HTMLPurifier_AttrTransform.
  10. *
  11. * An attribute transformation can be assigned to run before or after
  12. * HTMLPurifier_AttrDef validation. See HTMLPurifier_HTMLDefinition for
  13. * more details.
  14. */
  15. abstract class HTMLPurifier_AttrTransform
  16. {
  17. /**
  18. * Abstract: makes changes to the attributes dependent on multiple values.
  19. *
  20. * @param array $attr Assoc array of attributes, usually from
  21. * HTMLPurifier_Token_Tag::$attr
  22. * @param HTMLPurifier_Config $config Mandatory HTMLPurifier_Config object.
  23. * @param HTMLPurifier_Context $context Mandatory HTMLPurifier_Context object
  24. * @return array Processed attribute array.
  25. */
  26. abstract public function transform($attr, $config, $context);
  27. /**
  28. * Prepends CSS properties to the style attribute, creating the
  29. * attribute if it doesn't exist.
  30. * @param array &$attr Attribute array to process (passed by reference)
  31. * @param string $css CSS to prepend
  32. */
  33. public function prependCSS(&$attr, $css)
  34. {
  35. $attr['style'] = isset($attr['style']) ? $attr['style'] : '';
  36. $attr['style'] = $css . $attr['style'];
  37. }
  38. /**
  39. * Retrieves and removes an attribute
  40. * @param array &$attr Attribute array to process (passed by reference)
  41. * @param mixed $key Key of attribute to confiscate
  42. * @return mixed
  43. */
  44. public function confiscateAttr(&$attr, $key)
  45. {
  46. if (!isset($attr[$key])) {
  47. return null;
  48. }
  49. $value = $attr[$key];
  50. unset($attr[$key]);
  51. return $value;
  52. }
  53. }
  54. // vim: et sw=4 sts=4