You are here

function image_resize_filter_pathinfo in Image Resize Filter 8

Same name and namespace in other branches
  1. 6 image_resize_filter.module \image_resize_filter_pathinfo()
  2. 7 image_resize_filter.module \image_resize_filter_pathinfo()

Utility function to return path information.

1 call to image_resize_filter_pathinfo()
FilterImageResize::getImages in src/Plugin/Filter/FilterImageResize.php
Locate all images in a piece of text that need replacing.

File

./image_resize_filter.module, line 284
Contains image_resize_filter.module.

Code

function image_resize_filter_pathinfo($uri) {
  $info = pathinfo($uri);
  $info['extension'] = substr($uri, strrpos($uri, '.') + 1);
  $info['basename'] = basename($uri);
  $info['filename'] = basename($uri, '.' . $info['extension']);

  // Once Drupal 8.7.x is unsupported remove this IF statement.
  if (floatval(\Drupal::VERSION) >= 8.800000000000001) {
    $info['scheme'] = \Drupal::service('stream_wrapper_manager')
      ->getScheme($uri);
  }
  else {
    $info['scheme'] = \Drupal::service('file_system')
      ->uriScheme($uri);
  }
  $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
  $stream_wrappers = $stream_wrapper_manager
    ->getWrappers();
  if (empty($info['scheme'])) {
    foreach ($stream_wrappers as $scheme => $stream_wrapper) {
      $scheme_base_path = $stream_wrapper_manager
        ->getViaScheme($scheme)
        ->getDirectoryPath();
      $matches = array();
      if (preg_match('/^' . preg_quote($scheme_base_path, '/') . '\\/?(.*)/', $info['dirname'], $matches)) {
        $info['scheme'] = $scheme;
        $info['dirname'] = $scheme . '://' . $matches[1];
        break;
      }
    }
  }
  return $info;
}