You are here

function _bg_image_formatter_path_to_uri in Background Images Formatter 7.2

Converts a path to a uri relative to the public files directory.

Parameters

string $path: The path to convert. Can be an absolute or relative path. If the path contains the public files directory in it, it will be stripped before building the uri, since we're building a public:// uri.

Return value

string The path to the file as a uri.

1 call to _bg_image_formatter_path_to_uri()
bg_image_formatter_add_background_image_css in ./bg_image_formatter.helpers.inc
Function taken from the module 'bg_image'.

File

./bg_image_formatter.helpers.inc, line 142
Helper functions.

Code

function _bg_image_formatter_path_to_uri($path) {

  // Strip off the protocol and domain.
  $relative_path = parse_url($path, PHP_URL_PATH);

  // The public files directory (as configured).
  $file_public_path = '/' . variable_get('file_public_path', 'sites/default/files');

  // Remove the public path if the path starts with it.
  if (strpos($relative_path, $file_public_path) === 0) {
    $relative_path = str_replace($file_public_path, '', $relative_path);
    return file_build_uri($relative_path);
  }
  else {

    // If the public files directory isn't in the path, just return it as a uri.
    return file_build_uri($relative_path);
  }
}