You are here

function _bg_image_path_to_uri in Background Images 7

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

Parameters

$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

The path to the file as a uri.

1 call to _bg_image_path_to_uri()
bg_image_add_background_image in ./bg_image.module
Adds a background image to the page using the css 'background' property.

File

./bg_image.module, line 624
Allows for customizable background images per page

Code

function _bg_image_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);
  }
}