domain_init()
domain.module, line 39
Implements hook_init()
Inititalizes a global $_domain variable and set it based on the third-level domain used to access the page.
function domain_init() {
global $_domain, $conf;
$_domain = array();
// We lower case this, since EXAMPLE.com == example.com.
$_subdomain = strtolower(rtrim($_SERVER['HTTP_HOST']));
// Strip the www. off the subdomain, if required by the module settings.
$raw_domain = $_subdomain;
if (variable_get('domain_www', 0)) {
$_subdomain = str_replace('www.', '', $_subdomain);
}
// Lookup the active domain against our allowed hosts record.
$data = db_fetch_array(db_query("SELECT domain_id FROM {domain} WHERE subdomain = '%s'", $_subdomain));
// Get the domain data.
$_domain = domain_lookup($data['domain_id']);
// If return is -1, then the DNS didn't match anything, so use defaults.
if ($_domain == -1) {
$_domain = domain_default();
}
// If we stripped the www. send the user to the proper domain. This should only
// happen once, on an inbound link or typed URL, so the overhead is acceptable.
if ($raw_domain != $_subdomain) {
drupal_goto(domain_get_uri($_domain));
}
// For Domain User, we check the validity of accounts, so the 'valid' flag must be TRUE.
// If this check fails, we send users to the default site homepage.
if (!$_domain['valid'] && !user_access('administer domains')) {
$_domain = domain_default();
drupal_goto($_domain['path']);
}
// Set the site name to the domain-specific name.
$conf['site_name'] = $_domain['sitename'];
}