You are here

public static function SiteimproveUtils::rewriteDomain in Siteimprove 7

Rewrite domain in a URL.

Parameters

string $url: The full URL to a page.

2 calls to SiteimproveUtils::rewriteDomain()
SiteimproveUtils::includeJs in includes/SiteimproveUtils.php
Include all Siteimprove js scripts.
SiteimproveUtils::setSessionUrl in includes/SiteimproveUtils.php
Save URL in session.

File

includes/SiteimproveUtils.php, line 104
Utils for Siteimprove Plugin.

Class

SiteimproveUtils
Class SiteimproveUtils.

Code

public static function rewriteDomain($url) {
  $frontend_domain = variable_get('siteimprove_frontend_domain');
  $rewritten_url = $url;

  // Rewrite domain.
  if (!empty($frontend_domain)) {
    $url_parts = parse_url($url);

    // Search string.
    $search = $url_parts['scheme'] . '://' . $url_parts['host'];
    $search = !empty($url_parts['port']) ? $search . ':' . $url_parts['port'] : $search;

    // Replace string.
    $replace = $url_parts['scheme'] . '://' . $frontend_domain;

    // URL with rewritten domain.
    $rewritten_url = str_replace($search, $replace, $url);
  }

  // Let other modules alter the rewritten URL.
  $original_url = $url;
  drupal_alter('siteimprove_frontend_url', $rewritten_url, $original_url);
  return $rewritten_url;
}