You are here

private static function Redirects::fixMissingScheme in Hook Update Deploy Tools 7

Same name and namespace in other branches
  1. 8 src/Redirects.php \HookUpdateDeployTools\Redirects::fixMissingScheme()

Adds in a scheme if it is missing.

Parameters

string $url: The url to fix the scheme on. (by reference)

array $parsed_url: The fully parsed url (by reference).

1 call to Redirects::fixMissingScheme()
Redirects::parseCompleteUrl in src/Redirects.php
Parses the url and creates some variations needed for redirects.

File

src/Redirects.php, line 403

Class

Redirects
Public methods for importing redirects.

Namespace

HookUpdateDeployTools

Code

private static function fixMissingScheme(&$url, &$parsed_url) {

  // Check for URL scheme.  If the scheme is missing, the host will be too,
  // but may have been incorrectly pushed into the path.
  if (empty($parsed_url['scheme'])) {

    // Means it may not be a full domain or is just missing a scheme.
    $tld_check = array(
      '.com',
      '.edu',
      '.gov',
      '.net',
      '.org',
      '.us',
    );

    // See if it resembles a full url.
    foreach ($tld_check as $tld) {
      if (!empty($parsed_url['path']) && stripos($parsed_url['path'], $tld) > 1) {

        // Seems to contain a domain name but is missing scheme so add it.
        // Assuming http is safer than assuming https.
        $url = 'http://' . $url;

        // Remake it with the newly formed url.
        $parsed_url = parse_url($url);
      }
    }
  }
}