You are here

function _extlink_extra_encode_url_parts in External Links Extra 8

Encodes all parts of an URL.

Parameters

string $url: The URL that needs to be encoded.

Return value

string The encoded URL.

1 call to _extlink_extra_encode_url_parts()
extlink_extra_preprocess_extlink_extra_leaving in ./extlink_extra.module
Implements hook_preprocess_HOOK for extlink_extra_leaving.

File

./extlink_extra.module, line 168

Code

function _extlink_extra_encode_url_parts($url) {

  // Parse the URL so that we can encode all parts.
  $parts = UrlHelper::parse($url);

  // Unfortunately UrlHelper::parse() considers the scheme and the host to be
  // part of the path so we need to split them ourselves.
  $parts = parse_url($parts['path']) + $parts;

  // Encode the URL parts to make sure Drupal considers to URL to be valid when
  // there are spaces in the path. We don't want to encode slashes in the path
  // so we split the path before encoding all parts.
  $parts['path'] = explode('/', $parts['path']);
  array_walk_recursive($parts, '_extlink_extra_encode_url_part');
  $parts['path'] = implode('/', $parts['path']);

  // Return a full URL constructed from the parts.
  return _extlink_extra_http_build_url($parts);
}