You are here

function _stage_file_proxy_image_style_path_original in Stage File Proxy 7

Helper to retrieves original path for a styled image.

Parameters

string $uri: A uri or path (may be prefixed with scheme).

bool $style_only: Indicates if, the function should only return paths retrieved from style paths. Defaults to TRUE.

Return value

bool|mixed|string A file URI pointing to the given original image. If $style_only is set to TRUE and $uri is no style-path, FALSE is returned.

1 call to _stage_file_proxy_image_style_path_original()
stage_file_proxy_process_file_uri in ./stage_file_proxy.module
Checks to see if a file should be downloaded from the origin site.

File

./stage_file_proxy.module, line 65
Stage File Proxy Module.

Code

function _stage_file_proxy_image_style_path_original($uri, $style_only = TRUE) {
  $scheme = file_uri_scheme($uri);
  if ($scheme) {
    $path = parse_url(file_uri_target($uri), PHP_URL_PATH);
  }
  else {
    $path = parse_url($uri, PHP_URL_PATH);
    $scheme = file_default_scheme();
  }

  // It is a styles path, so we extract the different parts.
  if (strpos($path, 'styles') === 0) {

    // Then the path is like styles/[style_name]/[schema]/[original_path].
    return preg_replace('/styles\\/.+\\/(.+)\\/(.+)/U', '$1://$2', $path);
  }
  elseif ($style_only == FALSE) {
    return "{$scheme}://{$path}";
  }
  else {
    return FALSE;
  }
}