You are here

function boost_parse_url in Boost 7

parse_url that takes into account the base_path

Parameters

$url: Full URL

$b_path: Base Path

1 call to boost_parse_url()
boost_transform_url in ./boost.module
Given a URL give back eveything we know.

File

./boost.module, line 550
Caches generated output as a static file to be served directly from the webserver.

Code

function boost_parse_url($url = NULL, $b_path = NULL) {
  global $base_root, $base_path;

  // Set defaults.
  if ($url === NULL) {
    $url = $base_root . request_uri();
  }
  if ($b_path == NULL) {
    $b_path = $base_path;
  }

  // Parse url.
  $parts = parse_url($url);
  if (empty($parts['host']) || empty($parts['path'])) {
    return FALSE;
  }
  if (!isset($parts['query'])) {
    $parts['query'] = '';
  }
  $parts['path'] = $parts['full_path'] = urldecode(preg_replace('/^' . preg_quote($b_path, '/') . '/i', '', $parts['path']));
  $parts['base_path'] = $b_path;
  $parts['query_array'] = array();
  parse_str($parts['query'], $parts['query_array']);

  // Check if language prefix for urls is enabled.
  if (drupal_multilingual() && variable_get('locale_language_negotiation_url_part') == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) {

    // Get languages grouped by status and select only the enabled ones.
    $languages = language_list('enabled');
    $languages = $languages[1];
    list($language, $parts['path']) = language_url_split_prefix($parts['path'], $languages);
  }

  // Get page number and info from the query string.
  if (!empty($parts['query_array'])) {
    $query = array();
    foreach ($parts['query_array'] as $key => $val) {
      if ($key !== 'q' && $key !== 'destination' && $key !== 'page' && !empty($val)) {
        $query[$key] = $val;
      }
      if ($key === 'page' && is_numeric($val)) {
        $parts['page_number'] = $val;
      }
    }
    ksort($query);
    $parts['query_extra'] = str_replace('&', '&', urldecode(http_build_query($query)));
  }

  // Get fully decoded URL.
  $decoded1 = urldecode($parts['base_path'] . $parts['path'] . variable_get('boost_char', BOOST_CHAR) . $parts['query']);
  $decoded2 = urldecode($decoded1);
  while ($decoded1 != $decoded2) {
    $decoded1 = urldecode($decoded2);
    $decoded2 = urldecode($decoded1);
  }
  $decoded = $decoded2;
  unset($decoded2, $decoded1);
  $parts['url_full'] = $parts['host'] . $parts['base_path'] . $parts['path'] . variable_get('boost_char', BOOST_CHAR) . $parts['query'];
  $parts['url'] = $url;
  $parts['url_decoded'] = $decoded;
  return $parts;
}