domain_init()Implement hook_init().
Inititalizes a global $_domain variable if necessary (usually that's done in domain_bootstrap.inc) and loads information on current domain.
Also handles www stripping, checks the validity of user domains and updates $conf['site_name'].
./domain.module, line 55
<?php
function domain_init() {
global $_domain, $conf;
if (!is_array($_domain)) {
$_domain = array();
}
// Error handling in case the module is not installed correctly.
if (empty($_domain)) {
$_domain['error'] = '-1';
}
// If $_domain['error'] is present, then set a message and stop.
if (!isset($error) && isset($_domain['error'])) {
$error = 'Domain access failed to load during phase: '. $_domain['error'] .'. Please check your settings.php file and site configuration.';
// Do not show on form submissions, when enabling the module.
if (empty($_POST)) {
// Show a warning to admin users.
if (user_access('administer domains')) {
drupal_set_message($error, 'error');
}
watchdog('Domain Access', $error, NULL, WATCHDOG_ERROR);
}
return;
}
// End of the error handling routine.
// If coming from a node save, make sure we are on an accessible domain.
domain_node_save_redirect();
// Strip the www. off the domain, if required by the module settings.
$www_replaced = FALSE;
if (variable_get('domain_www', 0) && strpos($_domain['subdomain'], 'www.') !== FALSE) {
$_domain['subdomain'] = str_replace('www.', '', $_domain['subdomain']);
$www_replaced = TRUE;
}
// Add information from domain_lookup but keep existing values (domain_id and subdomain)
$domain = domain_lookup($_domain['domain_id']);
$_domain = array_merge($domain, $_domain);
// Set the initial domain record, for later reference. See http://drupal.org/node/706490.
domain_initial_domain($_domain);
// If we have replaced 'www.' in the url, redirect to the clean domain.
if ($www_replaced) {
drupal_goto(domain_get_uri($_domain));
}
// For Domain User, we check the validity of accounts, so the 'valid' flag must be TRUE.
if (empty($_domain['valid'])) {
domain_invalid_domain_requested();
}
// Set the site name to the domain-specific name.
$conf['site_name'] = $_domain['sitename'];
// Properly load custom_url_rewrite_outbound().
// See http://drupal.org/node/529026
include_once(drupal_get_path('module', 'domain') .'/settings_custom_url.inc');
}
?>