2006-08-14 23:11:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// must be called POST validation
|
|
|
|
|
2006-08-20 21:55:28 +00:00
|
|
|
/**
|
2007-06-20 21:39:28 +00:00
|
|
|
* Transform that supplies default values for the src and alt attributes
|
|
|
|
* in img tags, as well as prevents the img tag from being removed
|
|
|
|
* because of a missing alt tag. This needs to be registered as both
|
|
|
|
* a pre and post attribute transform.
|
2006-08-20 21:55:28 +00:00
|
|
|
*/
|
2006-08-14 23:11:28 +00:00
|
|
|
class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform
|
|
|
|
{
|
|
|
|
|
2008-01-05 00:10:43 +00:00
|
|
|
public function transform($attr, $config, $context) {
|
2006-08-14 23:11:28 +00:00
|
|
|
|
|
|
|
$src = true;
|
2006-08-17 20:29:34 +00:00
|
|
|
if (!isset($attr['src'])) {
|
2007-06-20 21:39:28 +00:00
|
|
|
if ($config->get('Core', 'RemoveInvalidImg')) return $attr;
|
2006-08-17 20:29:34 +00:00
|
|
|
$attr['src'] = $config->get('Attr', 'DefaultInvalidImage');
|
2006-08-14 23:11:28 +00:00
|
|
|
$src = false;
|
|
|
|
}
|
|
|
|
|
2006-08-17 20:29:34 +00:00
|
|
|
if (!isset($attr['alt'])) {
|
2006-08-14 23:11:28 +00:00
|
|
|
if ($src) {
|
2008-10-06 18:51:03 +00:00
|
|
|
$alt = $config->get('Attr', 'DefaultImageAlt');
|
|
|
|
if ($alt === null) {
|
|
|
|
$attr['alt'] = basename($attr['src']);
|
|
|
|
} else {
|
|
|
|
$attr['alt'] = $alt;
|
|
|
|
}
|
2006-08-14 23:11:28 +00:00
|
|
|
} else {
|
2006-08-17 20:29:34 +00:00
|
|
|
$attr['alt'] = $config->get('Attr', 'DefaultInvalidImageAlt');
|
2006-08-14 23:11:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-17 20:29:34 +00:00
|
|
|
return $attr;
|
2006-08-14 23:11:28 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|