You are here

public static function Blazy::sanitize in Blazy 7

2 calls to Blazy::sanitize()
BlazyManager::buildMedia in src/BlazyManager.php
Build out (Responsive) image.
BlazyManager::prepareImage in src/BlazyManager.php
Prepares the Blazy image as a structured array ready for ::renderer().

File

src/Blazy.php, line 248

Class

Blazy
Implements BlazyInterface.

Namespace

Drupal\blazy

Code

public static function sanitize(array $attributes = []) {
  $clean_attributes = [];
  $tags = [
    'href',
    'poster',
    'src',
    'about',
    'data',
    'action',
    'formaction',
  ];
  foreach ($attributes as $key => $value) {
    if (is_array($value)) {

      // Respects array item containing space delimited classes: aaa bbb ccc.
      $value = implode(' ', $value);
      $clean_attributes[$key] = array_map('drupal_clean_css_identifier', explode(' ', $value));
    }
    else {

      // Since Blazy is lazyloading known URLs, sanitize attributes which make
      // no sense to stick around within IMG or IFRAME tags relevant for UGC.
      $kid = substr($key, 0, 2) === 'on' || in_array($key, $tags);
      $key = $kid ? 'data-' . $key : $key;
      $clean_attributes[$key] = $kid ? drupal_clean_css_identifier($value) : check_plain($value);
    }
  }
  return $clean_attributes;
}