2006-08-14 23:11:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/AttrTransform.php';
|
|
|
|
|
|
|
|
// must be called POST validation
|
|
|
|
|
2006-09-16 22:36:58 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
2006-08-27 18:49:16 +00:00
|
|
|
'Attr', 'DefaultInvalidImage', '', 'string',
|
2006-08-14 23:11:28 +00:00
|
|
|
'This is the default image an img tag will be pointed to if it does '.
|
|
|
|
'not have a valid src attribute. In future versions, we may allow the '.
|
|
|
|
'image tag to be removed completely, but due to design issues, this is '.
|
|
|
|
'not possible right now.'
|
|
|
|
);
|
|
|
|
|
2006-09-16 22:36:58 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
2006-08-27 18:49:16 +00:00
|
|
|
'Attr', 'DefaultInvalidImageAlt', 'Invalid image', 'string',
|
2006-08-14 23:11:28 +00:00
|
|
|
'This is the content of the alt tag of an invalid image if the user '.
|
|
|
|
'had not previously specified an alt attribute. It has no effect when the '.
|
|
|
|
'image is valid but there was no alt attribute present.'
|
|
|
|
);
|
|
|
|
|
2006-08-20 21:55:28 +00:00
|
|
|
/**
|
|
|
|
* Post-transform that ensures the required attrs of img (alt and src) are set
|
|
|
|
*/
|
2006-08-14 23:11:28 +00:00
|
|
|
class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform
|
|
|
|
{
|
|
|
|
|
2007-01-16 22:22:08 +00:00
|
|
|
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'])) {
|
|
|
|
$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) {
|
2006-08-17 20:29:34 +00:00
|
|
|
$attr['alt'] = basename($attr['src']);
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|