Image.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. public $name = 'Image';
  10. public function setup($config) {
  11. $max = $config->get('HTML.MaxImgLength');
  12. $img = $this->addElement(
  13. 'img', 'Inline', 'Empty', 'Common',
  14. array(
  15. 'alt*' => 'Text',
  16. // According to the spec, it's Length, but percents can
  17. // be abused, so we allow only Pixels.
  18. 'height' => 'Pixels#' . $max,
  19. 'width' => 'Pixels#' . $max,
  20. 'longdesc' => 'URI',
  21. 'src*' => new HTMLPurifier_AttrDef_URI(true), // embedded
  22. )
  23. );
  24. if ($max === null || $config->get('HTML.Trusted')) {
  25. $img->attr['height'] =
  26. $img->attr['width'] = 'Length';
  27. }
  28. // kind of strange, but splitting things up would be inefficient
  29. $img->attr_transform_pre[] =
  30. $img->attr_transform_post[] =
  31. new HTMLPurifier_AttrTransform_ImgRequired();
  32. }
  33. }
  34. // vim: et sw=4 sts=4