You are here

function _site_disclaimer_absolute_content_path in Site Disclaimer 6

Same name and namespace in other branches
  1. 7 site_disclaimer.admin.inc \_site_disclaimer_absolute_content_path()

Get the path of an URL (copied from _linkchecker_absolute_content_path() linkchecker.module).

Parameters

$url: The http/https URL to parse.

Return value

Full qualified URL with absolute path of the URL.

1 call to _site_disclaimer_absolute_content_path()
_site_disclaimer_extract_links in ./site_disclaimer.admin.inc
Extract links from content (copied and modified from _linkchecker_extract_links() linkchecker.module).

File

./site_disclaimer.admin.inc, line 438
Administration settings for Site Disclaimer module.

Code

function _site_disclaimer_absolute_content_path($url) {
  global $base_url;

  // Parse the URL and make sure we can handle the schema.
  $uri = @parse_url($url);
  if ($uri == FALSE) {
    return NULL;
  }
  if (!isset($uri['scheme'])) {
    return NULL;
  }

  // Break if the schema is not supported.
  if (!in_array($uri['scheme'], array(
    'http',
    'https',
  ))) {
    return NULL;
  }
  $scheme = isset($uri['scheme']) ? $uri['scheme'] . '://' : '';
  $user = isset($uri['user']) ? $uri['user'] . ($uri['pass'] ? ':' . $uri['pass'] : '') . '@' : '';
  $port = isset($uri['port']) ? $uri['port'] : 80;
  $host = $uri['host'] . ($port != 80 ? ':' . $port : '');
  $path = isset($uri['path']) ? $uri['path'] : '/';

  // Glue the URL variables.
  $absolute_url = $scheme . $user . $host . $path;

  // Modification to the logic of _linkchecker_absolute_content_path():
  // We want to honor website absolute_url so the relative links don't break when drupal is
  // installed in webserver's subdirectory, e.g. http://www.example.com/drupal/
  if (strpos($base_url . '/', $absolute_url) === 0) {
    return $base_url . '/';
  }

  // Find the last slash and remove all after the last slash to get the path.
  $last_slash = strrpos($absolute_url, '/');
  $absolute_content_url = drupal_substr($absolute_url, 0, $last_slash + 1);
  return $absolute_content_url;
}