Whoops, forgot to edit WHATSNEW
[htmlpurifier.git] / library / HTMLPurifier / AttrTransform / ImgRequired.php
blob235ebb34b60ff22b403b6d03d764650c6dbe65e1
1 <?php
3 // must be called POST validation
5 /**
6 * Transform that supplies default values for the src and alt attributes
7 * in img tags, as well as prevents the img tag from being removed
8 * because of a missing alt tag. This needs to be registered as both
9 * a pre and post attribute transform.
11 class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform
14 /**
15 * @param array $attr
16 * @param HTMLPurifier_Config $config
17 * @param HTMLPurifier_Context $context
18 * @return array
20 public function transform($attr, $config, $context)
22 $src = true;
23 if (!isset($attr['src'])) {
24 if ($config->get('Core.RemoveInvalidImg')) {
25 return $attr;
27 $attr['src'] = $config->get('Attr.DefaultInvalidImage');
28 $src = false;
31 if (!isset($attr['alt'])) {
32 if ($src) {
33 $alt = $config->get('Attr.DefaultImageAlt');
34 if ($alt === null) {
35 $attr['alt'] = basename($attr['src']);
36 } else {
37 $attr['alt'] = $alt;
39 } else {
40 $attr['alt'] = $config->get('Attr.DefaultInvalidImageAlt');
43 return $attr;
47 // vim: et sw=4 sts=4