ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
)

Definition at line 14 of file ImgRequired.php.

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

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