You are here

function hosting_alias_hosting_automatic_aliases_alter in Hosting 7.3

Same name and namespace in other branches
  1. 7.4 alias/hosting_alias.module \hosting_alias_hosting_automatic_aliases_alter()

Implements hook_hosting_automatic_aliases_alter().

Generate automatic 'www' or bare domain aliases.

See also

hosting_alias_hosting_automatic_aliases().

File

alias/hosting_alias.module, line 565
Allow sites to have domain aliases that they can be accessed with.

Code

function hosting_alias_hosting_automatic_aliases_alter(&$aliases, $context) {
  $url = $context['url'];
  if (!preg_match('/^www\\./', $url) && variable_get('hosting_alias_automatic_www', FALSE)) {
    $auto_alias = "www." . $url;

    // Lookup DNS, only add if we get an IP back.
    if (gethostbyname($auto_alias) != $auto_alias) {
      $aliases[] = $auto_alias;
    }
  }
  elseif (preg_match('/^www\\./', $url) && variable_get('hosting_alias_automatic_no_www', FALSE)) {
    $auto_alias = str_replace("www.", "", $url);

    // Lookup DNS, only add if we get an IP back.
    if (gethostbyname($auto_alias) != $auto_alias) {
      $aliases[] = $auto_alias;
    }
  }
}