You are here

function redirect_parse_url in Redirect 7

Same name and namespace in other branches
  1. 7.2 redirect.module \redirect_parse_url()
6 calls to redirect_parse_url()
MigrateRedirectEntityHandler::complete in ./redirect.migrate.inc
Overrides complete().
RedirectTestHelper::addRedirect in ./redirect.test
Add an URL redirection
RedirectUnitTest::testLoadRedirectsBySource in ./redirect.test
Test redirect_load_by_source().
RedirectUnitTest::testParseURL in ./redirect.test
Test redirect_parse_url().
_redirect_extract_url_options in ./redirect.admin.inc
Extract the query and fragment parts out of an URL field.

... See full list

File

./redirect.module, line 1501

Code

function redirect_parse_url($url) {
  $original_url = $url;
  $is_external = url_is_external($url);
  if (!$is_external) {

    // Include trailing slashes in character trim list.
    $url = trim($url, " \t\n\r\0\v\\/");
  }
  else {

    // Use the default trim() $charlist parameter.
    $url = trim($url);
  }
  $parsed = parse_url($url);
  if (isset($parsed['fragment'])) {
    $url = substr($url, 0, -strlen($parsed['fragment']));
    $url = trim($url, '#');
  }

  // When Clean URLs are off, if a query component exists, it will be
  // separated from the path component by "&" rather than "?".
  if (variable_get('clean_url', 0) == 0 && strpos($url, '&')) {
    $parsed['path'] = substr($url, 0, strpos($url, '&'));
    $parsed['query'] = substr($url, strpos($url, '&') + 1);
  }
  if (isset($parsed['query'])) {
    $url = substr($url, 0, -strlen($parsed['query']));
    $url = trim($url, '?&');
    parse_str($parsed['query'], $parsed['query']);
  }

  // Convert absolute to relative.
  if (isset($parsed['scheme']) && isset($parsed['host'])) {
    $base_secure_url = rtrim($GLOBALS['base_secure_url'] . base_path(), '/');
    $base_insecure_url = rtrim($GLOBALS['base_insecure_url'] . base_path(), '/');
    if (strpos($url, $base_secure_url) === 0) {
      $url = str_replace($base_secure_url, '', $url);
      $parsed['https'] = TRUE;
    }
    elseif (strpos($url, $base_insecure_url) === 0) {
      $url = str_replace($base_insecure_url, '', $url);
    }
  }

  // At this point, a URL with a query or fragment may still have a trailing
  // slash. Trim the trailing slash from "internal" Drupal paths (and other
  // local paths).
  if (!$is_external) {
    $url = trim($url, '/');
  }

  // Convert to frontpage paths.
  if ($url == '<front>') {
    $url = '';
  }

  //$parsed['url'] = http_build_query($url, HTTP_URL_STRIP_QUERY | HTTP_URL_STRIP_FRAGMENT);
  $parsed['url'] = $url;

  // Allow modules to alter the parsed URL.
  drupal_alter('redirect_parse_url', $parsed, $original_url);
  return $parsed;
}