You are here

public static function Blazy::buildUri in Blazy 7

Returns the URI from the given image URL, relevant for unmanaged files.

@todo recheck if any core function for this aside from file_build_uri().

1 call to Blazy::buildUri()
BlazyFilter::buildImageItem in src/Plugin/Filter/BlazyFilter.php

File

src/Blazy.php, line 105

Class

Blazy
Implements BlazyInterface.

Namespace

Drupal\blazy

Code

public static function buildUri($image_url) {
  if (!url_is_external($image_url) && ($path = drupal_parse_url($image_url)['path'])) {
    $normal_path = drupal_get_normal_path($path);
    $public_path = variable_get('file_public_path', 'sites/default/files');

    // Only concerns for the correct URI, not image URL which is already being
    // displayed via SRC attribute. Don't bother language prefixes for IMG.
    if ($public_path && strpos($normal_path, $public_path) !== FALSE) {
      $rel_path = str_replace($public_path, '', $normal_path);
      return file_build_uri($rel_path);
    }
  }
  return FALSE;
}