You are here

function _responsive_favicons_normalise_path in Responsive Favicons 7

Same name and namespace in other branches
  1. 8 responsive_favicons.module \_responsive_favicons_normalise_path()

Help to normalise the path to the icons.

Parameters

$file_path: The filename of the icon.

Return value

string The full relative path to the icon within public files.

2 calls to _responsive_favicons_normalise_path()
responsive_favicons_config_page_submit in ./responsive_favicons.admin.inc
Implements additional submit logic for responsive_favicons_settings_form().
_responsive_favicons_validate_tags in ./responsive_favicons.module
Helper function to check whether responsive favicon files exist and are readable. This function also strips any pasted content that is not a link or a meta tag.

File

./responsive_favicons.module, line 237
Responsive favicons module file.

Code

function _responsive_favicons_normalise_path($file_path) {
  global $base_path;

  // Remove absolute URLs.
  if (url_is_external($file_path)) {
    $file_path = str_replace($base_path, '', $file_path);
  }

  // There appears to be no sane way of getting a relative path to a file, so
  // this is the best for now.
  // @see https://www.drupal.org/node/837794#comment-9124435
  $wrapper = file_stream_wrapper_get_instance_by_uri('public://');
  if ($wrapper instanceof DrupalLocalStreamWrapper) {
    $relative_path = $wrapper
      ->getDirectoryPath() . '/' . variable_get('responsive_favicons_path', 'favicons') . $file_path;
  }
  return $base_path . $relative_path;
}