You are here

function redirect_url in Redirect 7

Same name and namespace in other branches
  1. 7.2 redirect.module \redirect_url()

Build the URL of a redirect for display purposes only.

9 calls to redirect_url()
drush_redirect_create_redirect in ./redirect.drush.inc
Command callback. Validates and adds a redirect.
redirect_edit_form in ./redirect.admin.inc
Form builder to add or edit an URL redirect.
redirect_handler_field_redirect_redirect::render in views/redirect_handler_field_redirect_redirect.inc
Render the field.
redirect_handler_field_redirect_source::render in views/redirect_handler_field_redirect_source.inc
Render the field.
redirect_list_form in ./redirect.admin.inc
@file Administrative page callbacks for the redirect module.

... See full list

File

./redirect.module, line 1417

Code

function redirect_url($path, array $options = array(), $clean_url = NULL) {
  if (!isset($clean_url)) {
    $clean_url = variable_get('clean_url', 0);
  }
  if ($path == '') {
    $path = '<front>';
  }
  if (!isset($options['alter']) || !empty($options['alter'])) {
    drupal_alter('redirect_url', $path, $options);
  }

  // The base_url might be rewritten from the language rewrite in domain mode.
  if (!isset($options['base_url'])) {
    if (isset($options['https']) && variable_get('https', FALSE)) {
      if ($options['https'] === TRUE) {
        $options['base_url'] = $GLOBALS['base_secure_url'];
        $options['absolute'] = TRUE;
      }
      elseif ($options['https'] === FALSE) {
        $options['base_url'] = $GLOBALS['base_insecure_url'];
        $options['absolute'] = TRUE;
      }
    }
    else {
      $options['base_url'] = $GLOBALS['base_url'];
    }
  }
  if (empty($options['absolute']) || url_is_external($path)) {
    $url = $path;
  }
  else {
    $url = $options['base_url'] . base_path() . $path;
  }
  if (isset($options['query'])) {
    $url .= $clean_url ? '?' : '&';
    $url .= drupal_http_build_query($options['query']);
  }
  if (isset($options['fragment'])) {
    $url .= '#' . $options['fragment'];
  }
  $url = str_replace($GLOBALS['base_url'] . '/', '', $url);
  return $url;
}