ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
HTMLPurifier_AttrTransform_ImgRequired Class Reference

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. More...

+ Inheritance diagram for HTMLPurifier_AttrTransform_ImgRequired:
+ Collaboration diagram for HTMLPurifier_AttrTransform_ImgRequired:

Public Member Functions

 transform ($attr, $config, $context)
 
- Public Member Functions inherited from HTMLPurifier_AttrTransform
 transform ($attr, $config, $context)
 Abstract: makes changes to the attributes dependent on multiple values. More...
 
 prependCSS (&$attr, $css)
 Prepends CSS properties to the style attribute, creating the attribute if it doesn't exist. More...
 
 confiscateAttr (&$attr, $key)
 Retrieves and removes an attribute. More...
 

Detailed Description

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.

Definition at line 11 of file ImgRequired.php.

Member Function Documentation

◆ transform()

HTMLPurifier_AttrTransform_ImgRequired::transform (   $attr,
  $config,
  $context 
)
Parameters
array$attr
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
array

Definition at line 20 of file ImgRequired.php.

21  {
22  $src = true;
23  if (!isset($attr['src'])) {
24  if ($config->get('Core.RemoveInvalidImg')) {
25  return $attr;
26  }
27  $attr['src'] = $config->get('Attr.DefaultInvalidImage');
28  $src = false;
29  }
30 
31  if (!isset($attr['alt'])) {
32  if ($src) {
33  $alt = $config->get('Attr.DefaultImageAlt');
34  if ($alt === null) {
35  // truncate if the alt is too long
36  $attr['alt'] = substr(basename($attr['src']), 0, 40);
37  } else {
38  $attr['alt'] = $alt;
39  }
40  } else {
41  $attr['alt'] = $config->get('Attr.DefaultInvalidImageAlt');
42  }
43  }
44  return $attr;
45  }

The documentation for this class was generated from the following file: