HTMLPurifier 4.4.0
|
00001 <?php 00002 00003 // must be called POST validation 00004 00011 class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform 00012 { 00013 00014 public function transform($attr, $config, $context) { 00015 00016 $src = true; 00017 if (!isset($attr['src'])) { 00018 if ($config->get('Core.RemoveInvalidImg')) return $attr; 00019 $attr['src'] = $config->get('Attr.DefaultInvalidImage'); 00020 $src = false; 00021 } 00022 00023 if (!isset($attr['alt'])) { 00024 if ($src) { 00025 $alt = $config->get('Attr.DefaultImageAlt'); 00026 if ($alt === null) { 00027 // truncate if the alt is too long 00028 $attr['alt'] = substr(basename($attr['src']),0,40); 00029 } else { 00030 $attr['alt'] = $alt; 00031 } 00032 } else { 00033 $attr['alt'] = $config->get('Attr.DefaultInvalidImageAlt'); 00034 } 00035 } 00036 00037 return $attr; 00038 00039 } 00040 00041 } 00042 00043 // vim: et sw=4 sts=4