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.

50 lines
1.4KB

  1. <?php
  2. /**
  3. * XHTML 1.1 Image Module provides basic image embedding.
  4. * @note There is specialized code for removing empty images in
  5. * HTMLPurifier_Strategy_RemoveForeignElements
  6. */
  7. class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule
  8. {
  9. /**
  10. * @type string
  11. */
  12. public $name = 'Image';
  13. /**
  14. * @param HTMLPurifier_Config $config
  15. */
  16. public function setup($config)
  17. {
  18. $max = $config->get('HTML.MaxImgLength');
  19. $img = $this->addElement(
  20. 'img',
  21. 'Inline',
  22. 'Empty',
  23. 'Common',
  24. array(
  25. 'alt*' => 'Text',
  26. // According to the spec, it's Length, but percents can
  27. // be abused, so we allow only Pixels.
  28. 'height' => 'Pixels#' . $max,
  29. 'width' => 'Pixels#' . $max,
  30. 'longdesc' => 'URI',
  31. 'src*' => new HTMLPurifier_AttrDef_URI(true), // embedded
  32. )
  33. );
  34. if ($max === null || $config->get('HTML.Trusted')) {
  35. $img->attr['height'] =
  36. $img->attr['width'] = 'Length';
  37. }
  38. // kind of strange, but splitting things up would be inefficient
  39. $img->attr_transform_pre[] =
  40. $img->attr_transform_post[] =
  41. new HTMLPurifier_AttrTransform_ImgRequired();
  42. }
  43. }
  44. // vim: et sw=4 sts=4