3 // must be called POST validation
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
16 * @param HTMLPurifier_Config $config
17 * @param HTMLPurifier_Context $context
20 public function transform($attr, $config, $context)
23 if (!isset($attr['src'])) {
24 if ($config->get('Core.RemoveInvalidImg')) {
27 $attr['src'] = $config->get('Attr.DefaultInvalidImage');
31 if (!isset($attr['alt'])) {
33 $alt = $config->get('Attr.DefaultImageAlt');
35 // truncate if the alt is too long
36 $attr['alt'] = substr(basename($attr['src']), 0, 40);
41 $attr['alt'] = $config->get('Attr.DefaultInvalidImageAlt');