diff -urpN domain-HEAD\domain.module domain\domain.module
--- domain-HEAD\domain.module	Fri Jul 25 16:22:01 2008
+++ domain\domain.module	Tue Jul 29 17:22:32 2008
@@ -32,35 +32,33 @@ define('DOMAIN_EDITOR_RULE', FALSE);
 define('DOMAIN_SITE_GRANT', TRUE);
 
 /**
- * Implements hook_init()
+ * Implementation of hook_init().
  *
- * Inititalizes a global $_domain variable and set it based on the
- * third-level domain used to access the page.
+ * 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'].
  */
 function domain_init() {
   global $_domain, $conf;
-  $_domain = array();
-  // We lower case this, since EXAMPLE.com == example.com.
-  $_subdomain = strtolower(rtrim($_SERVER['HTTP_HOST']));
+
+  // if $_domain is empty start domain bootstrap (by including settings.inc)
+  if (!is_array($_domain) || !isset($_domain['domain_id'])) {
+    require_once drupal_get_path('module', 'domain') .'/settings.inc';
+  }
 
   // Strip the www. off the subdomain, if required by the module settings.
-  $raw_domain = $_subdomain;
-  if (variable_get('domain_www', 0)) {
+  if (variable_get('domain_www', 0) && ($www_replaced = strpos($_subdomain, 'www.')) !== FALSE) {
     $_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();
-  }
+  // add information from domain_lookup but keep existing values (domain_id and subdomain)
+  $domain = domain_lookup($_domain['domain_id']);
+  $_domain = array_merge($domain, $_domain);
 
-  // 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) {
+  // If we have replaced 'www.' in the url, redirect to the clean domain.
+  if ($www_replaced !== FALSE) {
     drupal_goto(domain_get_uri($_domain));
   }
 
@@ -70,6 +68,7 @@ function domain_init() {
     $_domain = domain_default();
     drupal_goto($_domain['path']);
   }
+
   // Set the site name to the domain-specific name.
   $conf['site_name'] = $_domain['sitename'];
 }
@@ -369,14 +368,6 @@ function domain_cron() {
     $domains = domain_domains();
     // Run the hook for each active domain.
     foreach ($domains as $domain) {
-      // Set the domain-specific variables
-      if (function_exists('_domain_conf_load')) {
-        _domain_conf_load($domain);
-      }
-      // Set the global table prefix
-      if (function_exists('_domain_prefix_load')) {
-        _domain_prefix_load($domain);
-      }
       // Set the global to the current $domain.
       $_domain = $domain;
       foreach ($modules as $module) {
@@ -1219,6 +1210,9 @@ function domain_grant_all($reset= FALSE)
  * Implements hook_domaininstall()
  */
 function domain_domaininstall() {
+  // Cleanup list of bootstrap modules (remove disabled ones)
+  domain_bootstrap_modules_cleanup();
+
   // Check to see if the hook_url_alter() patch is installed.
   if (url('domain_access_test_path') != url('domain_access_path_test')) {
     drupal_set_message(t('The <em>custom_url_rewrite_outbound()</em> function is not installed.  Some features are not available. See the <em>custom_url_rewrite_outbound()</em> section of <a href="!url">INSTALL.txt</a>', array('!url' => base_path() . drupal_get_path('module', 'domain') .'/INSTALL.txt')));
diff -urpN domain-HEAD\domain_bootstrap.inc domain\domain_bootstrap.inc
--- domain-HEAD\domain_bootstrap.inc	Thu Jan 01 01:00:00 1970
+++ domain\domain_bootstrap.inc	Fri Jul 18 13:09:00 2008
@@ -0,0 +1,400 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Domain bootstrap file.
+ *
+ * The domain bootstrap process is initiated in domain/settings.inc which is
+ * (supposed to be) included in the user's settings.php and therefore initiated
+ * during drupal's first bootstrap phase (DRUPAL_BOOTSTRAP_CONFIGURATION).
+ *
+ * The purpose of this is to allow domain-based modules to modify basic drupal
+ * systems like the variable or database/prefix system - before they are used by
+ * any other modules.
+ *
+ * @ingroup domain
+ */
+
+/**
+ * Domain bootstrap phase 1: makes sure that database is initialised and
+ * loads all necessary module files.
+ */
+define('DOMAIN_BOOTSTRAP_INIT', 0);
+
+/**
+ * Domain bootstrap phase 2: resolves host and does a lookup in the {domain}
+ * table. Also invokes hook "hook_domain_bootstrap_lookup".
+ */
+define('DOMAIN_BOOTSTRAP_DOMAINNAME_RESOLVE', 1);
+
+/**
+ * Domain bootstrap phase 3: invokes bootstrap hook "hook_domain_bootstrap_full".
+ */
+define('DOMAIN_BOOTSTRAP_FULL', 2);
+
+/**
+ * Domain module bootstrap: calls all bootstrap phases.
+ *
+ * @todo
+ * Change handling of bootstrap errors (atm it uses die() to send a msg
+ * and exit the script; watchdog is not initialised yet and cannot be used.
+ * Maybe php:trigger_error() is an option?
+ */
+function domain_bootstrap() {
+  $phases = array(DOMAIN_BOOTSTRAP_INIT, DOMAIN_BOOTSTRAP_DOMAINNAME_RESOLVE, DOMAIN_BOOTSTRAP_FULL);
+  foreach ($phases as $phase) {
+    if (!_domain_bootstrap($phase)) {
+      die('Domain Module: Error during domain_bootstrap(), Phase '.$phase);
+    }
+  }
+}
+
+/**
+ * Calls individuell bootstrap phases.
+ *
+ * @param $phase
+ * The domain bootstrap phase to call.
+ *
+ * @return
+ * Returns TRUE if the bootstrap phase was successful and FALSE otherwise.
+ */
+function _domain_bootstrap($phase) {
+  global $_domain;
+  switch ($phase) {
+  case DOMAIN_BOOTSTRAP_INIT:
+    // make sure database is loaded
+    _drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
+
+    // load bootstrap modules
+    _domain_bootstrap_modules_load();
+    // if essential core module file has not been loaded, bootstrap fails.
+    if (!function_exists('domain_load')) {
+      return FALSE;
+    }
+
+    break;
+
+  case DOMAIN_BOOTSTRAP_DOMAINNAME_RESOLVE:
+    // get domain_id
+    $_domain = domain_resolve_host();
+    // if we don't have a valid domain id now, we can't really go on, bootstrap fails.
+    if (empty($_domain) || !is_numeric($_domain['domain_id'])) {
+      return FALSE;
+    }
+    break;
+
+  case DOMAIN_BOOTSTRAP_FULL:
+    _domain_bootstrap_invoke_all('full', $_domain);
+    break;
+  }
+  return TRUE;
+}
+
+/**
+ * Registers a module so it is loaded during domain_bootstrap and invoked
+ * domain_bootstrap hooks on.
+ *
+ * This function should be called from within hook_enable() implementations.
+ *
+ * @param $name
+ * The name of the module that is registered.
+ * @param $weight
+ * The weight of the module as an integer number. The default value is the
+ * respective value from the {system} table. Optional.
+ */
+function domain_bootstrap_register($name, $weight=NULL) {
+  // load old list of modules
+  $modules = _domain_bootstrap_modules_get();
+
+  // if $weight is not an integer load the weight from the {system} table.
+  if (!is_integer($weight)) {
+    $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = '%s'", $name));
+  }
+
+  // update/add the module and its weight:
+  $modules[$weight.'-'.$name] = $name;
+
+  // and store the new list of modules.
+  _domain_bootstrap_modules_set($modules);
+}
+
+/**
+ * Removes a module so is is not loaded during domain_bootstrap anymore.
+ *
+ * This function should be called from within hook_disable() implementations.
+ *
+ * @param $name
+ * The name of the module that is un-registered.
+ */
+function domain_bootstrap_unregister($name) {
+  $modules = _domain_bootstrap_modules_get();
+  if (is_array($modules)) {
+    foreach($modules as $k => $v){
+      if ($v == $name) {
+        unset($modules[$k]);
+      }
+    }
+  }
+  _domain_bootstrap_modules_set($modules);
+}
+
+/**
+ * Returns a list of modules which are loaded during domain_bootstrap phases and
+ * called respective hooks on.
+ *
+ * The domain module is always in the list of modules and has weight -99 so it
+ * should usually be first one as well.
+ *
+ * @param $reset
+ * If set to TRUE the cached list of modules is updated with the value from the
+ * {variable} table again. Default value is FALSE. Optional.
+ *
+ * @return
+ * An array of module names.
+ */
+function domain_bootstrap_modules($reset = FALSE) {
+  static $modules = NULL;
+
+  // if parameter is not given but $bootstrap_modules empty load modules from db
+  if ($reset || is_null($modules)) {
+    $modules = _domain_bootstrap_modules_get();
+    if (!is_array($modules)) {
+      $modules = Array();
+    }
+    if (!in_array('domain', $modules)) {
+      $modules['-99-domain'] = 'domain';
+    }
+    ksort($modules);
+  }
+
+  return $modules;
+}
+
+/**
+ * Tries to load all domain bootstrap modules (see _domain_bootstrap_modules()).
+ */
+function _domain_bootstrap_modules_load() {
+  $modules = domain_bootstrap_modules();
+
+  foreach ($modules as $module) {
+    drupal_load('module', $module);
+  }
+}
+
+/**
+ * Retrieves the value of the variable 'domain_bootstrap_modules' from the
+ * {variable} table. This function does not use Drupal's variable system.
+ *
+ * @return
+ * An array containing module names. (The keys are combined from module weight
+ * and module name and used for sorting during domain_bootstrap_modules().)
+ */
+function _domain_bootstrap_modules_get() {
+  $key = 'domain_bootstrap_modules';
+  $conf[$key] = unserialize(db_result(db_query("SELECT value FROM {variable} WHERE name = '%s'", $key)));
+  return $conf[$key];
+}
+
+/**
+ * Set variable 'domain_bootstrap_modules' to given value.
+ *
+ * This function does not use drupal's variable system.
+ *
+ * @param $modules
+ * An array containing module names. The keys should be of the format
+ * {weight}-{module-name} to allow easy sorting by module weight later.
+ */
+function _domain_bootstrap_modules_set($modules = NULL){
+  $key = 'domain_bootstrap_modules';
+
+  if (!is_array($modules)) {
+    $modules = array();
+  }
+
+  $serialized_value = serialize($modules);
+  db_query("UPDATE {variable} SET value = '%s' WHERE name = '%s'", $serialized_value, $key);
+  if (!db_affected_rows()) {
+    @db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $key, $serialized_value);
+  }
+
+  $conf[$key] = $modules;
+}
+
+/**
+ * Removes all disabled or not installed modules from the
+ * 'domain_bootstrap_modules' variable.
+ */
+function domain_bootstrap_modules_cleanup() {
+  $modules = _domain_bootstrap_modules_get();
+  foreach($modules as $k => $name) {
+    $status = db_result(db_query("SELECT status FROM {system} WHERE name = '%s'", $name));
+    if (!$status) {
+      unset($modules[$k]);
+    }
+  }
+  _domain_bootstrap_modules_set($modules);
+}
+
+/**
+ * Tries to call specified hook on all domain_bootstrap modules.
+ *
+ * The hook function names are of the following format:
+ * {$module}_domain_bootstrap_{$hook}
+ * where {$module} is the name of the module implementing the hook and {$hook}
+ * is the identifier for the concrete domain bootstrap hook.
+ *
+ * This function is basically a copy of module_invoke_all() adjusted to our
+ * needs.
+ *
+ * @param $hook
+ * The name of the bootstrap hook to invoke.
+ *
+ * @link http://api.drupal.org/api/function/module_invoke_all/6
+ */
+function _domain_bootstrap_invoke_all() {
+  $args = func_get_args();
+  $hook = $args[0];
+  unset($args[0]);
+  $return = array();
+  foreach (domain_bootstrap_modules() as $module) {
+    $function = $module . '_domain_bootstrap_' . $hook;
+    if (function_exists($function)) {
+      $result = call_user_func_array($function, $args);
+      if (isset($result) && is_array($result)) {
+        $return = array_merge_recursive($return, $result);
+      } else if (isset($result)) {
+        $return[] = $result;
+      }
+    }
+  }
+
+  return $return;
+}
+
+/**
+ * Tries to match the current (host) domainname to a domain in the {domain}
+ * table and returns a respective domain_id.
+ *
+ * @param $_domainname
+ * The domainname to match against. Optional.
+ *
+ * @return
+ * An array containing a domain_id matching the current domainname.
+ */
+function domain_resolve_host($_domainname = "") {
+  if (empty($_domainname)) {
+    $_domainname = domain_current_domainname();
+  }
+
+  return _domain_lookup_simple($_domainname);
+}
+
+/**
+ * Determines current fully qualified domainname.
+ *
+ * @return
+ * The current (host) domainname as a String.
+ */
+function domain_current_domainname() {
+  // We lower case this, since EXAMPLE.com == example.com.
+  return strtolower(rtrim($_SERVER['HTTP_HOST']));
+}
+
+/**
+ * Determines a domain_id matching given $_domainname.
+ *
+ * This function runs a lookup against the {domain} table matching the
+ * subdomain column against the given parameter $_domainname. If a match is
+ * found the function returns an array containing the subdomain (= $_domainname)
+ * and the matching domain_id from the {domain} table.
+ *
+ * If no match is found domain_id is set to 0 for the default domain.
+ *
+ * During the process hook_domain_bootstrap_lookup() is invoked to allow other
+ * modules to modify that result.
+ *
+ * @param $domainname
+ * The string representation of a {domain} entry.
+ *
+ * @param $reset
+ * Set TRUE to ignore cached versions and look the name up again. Optional.
+ *
+ * @return
+ * An array containing a domain_id from {domain} matching the given domainname
+ */
+function _domain_lookup_simple($_domainname, $reset = false) {
+  static $cache = array();
+
+  if (empty($_domainname)) return 0;
+
+  if ($reset || !isset($cache[$_domainname])) {
+    // Lookup the given domainname against our allowed hosts record.
+    $domain = db_fetch_array(db_query_range("SELECT domain_id FROM {domain} WHERE subdomain = '%s' ", $_domainname, 0, 1));
+
+    if (!is_array($domain)) {
+      $domain = array();
+    }
+
+    $domain['subdomain'] = $_domainname;
+    // invoke hook_domain_bootstrap_lookup()
+    $domain_new = _domain_bootstrap_invoke_all('lookup', $domain);
+    if (is_array($domain_new)) {
+      $domain = array_merge($domain, $domain_new);
+    }
+    // no match => use default (0)
+    if (!isset($domain['domain_id'])) {
+      $domain['domain_id'] = 0;
+    }
+
+    $cache[$_domainname] = $domain;
+  }
+  return $cache[$_domainname];
+}
+
+/**
+ * Hook domain_bootstrap_lookup allows to modify the domain record used on the
+ * current page on bootstrap level, that is before it is used anywhere else.
+ *
+ * This for example allows to change the domain_id matched to the current
+ * domainname before related information is retrieved during domain_init().
+ *
+ * Note: Because this function is usually called VERY early many drupal
+ * functions or modules won't be loaded yet.
+ *
+ * In order for this hook to work your module needs to be registered in
+ * domain/settings.inc.
+ *
+ * @param $domain
+ * An array containing current domain (host) name (used during bootstrap) and
+ * the results of lookup against {domain} table.
+ * @return
+ * An array containing at least a valid domain_id.
+ */
+function hook_domain_bootstrap_lookup($domain) {
+  // match en.example.org to default domain (id:0)
+  if ($domain['subdomain'] == 'en.example.org') {
+    $domain['domain_id'] = 0;
+  }
+
+  return $domain;
+}
+
+/**
+ * Hook hook_domain_bootstrap_full allows to execute code after the domain
+ * bootstrap phases which (usually) is even before drupal's hook_boot().
+ *
+ * This can be used to modify drupal's variables system or prefix database#
+ * tables, as used in modules domain_conf and domain_prefix.
+ *
+ * Note: Because this function is usually called VERY early many drupal
+ * functions or modules won't be loaded yet.
+ *
+ * In order for this hook to work your module needs to be registered in
+ * domain/settings.inc.
+ *
+ * @param $domain
+ * An array containing current subdomain and domain_id and any other values
+ * added during domain bootstrap phase 2 (DOMAIN_BOOTSTRAP_DOMAINNAME_RESOLVE).
+ */
+function hook_domain_bootstrap_full($domain) {
+}
diff -urpN domain-HEAD\domain_conf\domain_conf.install domain\domain_conf\domain_conf.install
--- domain-HEAD\domain_conf\domain_conf.install	Wed Mar 26 04:47:31 2008
+++ domain\domain_conf\domain_conf.install	Tue Jul 29 17:23:02 2008
@@ -32,3 +32,21 @@ function domain_conf_schema() {
 function domain_conf_uninstall() {
   drupal_uninstall_schema('domain_conf');
 }
+
+/**
+ * Implementation of hook_enable().
+ *
+ * Register the domain_conf with the domain module so it's loaded during domain
+ * bootstrap and can implement domain_bootstrap hooks.
+ */
+function domain_conf_enable() {
+  domain_bootstrap_register('domain_conf');
+}
+
+/**
+ * Implementation of hook_disable().
+ */
+function domain_conf_disable() {
+  domain_bootstrap_unregister('domain_conf');
+}
+
diff -urpN domain-HEAD\domain_conf\domain_conf.install.bak domain\domain_conf\domain_conf.install.bak
--- domain-HEAD\domain_conf\domain_conf.install.bak	Thu Jan 01 01:00:00 1970
+++ domain\domain_conf\domain_conf.install.bak	Wed Mar 26 04:47:31 2008
@@ -0,0 +1,34 @@
+<?php
+// $Id: domain_conf.install,v 1.4 2008/03/26 02:47:31 agentken Exp $
+
+/**
+ * @file
+ * Install file.
+ */
+
+/**
+ * Implements hook_install()
+ */
+function domain_conf_install() {
+  drupal_install_schema('domain_conf');
+}
+
+/**
+ * Implements hook_schema()
+ */
+function domain_conf_schema() {
+  $schema['domain_conf'] = array(
+    'fields' => array(
+      'domain_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'settings' => array('type' => 'blob', 'not null' => FALSE)),
+    'primary key' => array('domain_id'),
+  );
+  return $schema;
+}
+
+/**
+ * Implements hook_uninstall()
+ */
+function domain_conf_uninstall() {
+  drupal_uninstall_schema('domain_conf');
+}
diff -urpN domain-HEAD\domain_conf\domain_conf.module domain\domain_conf\domain_conf.module
--- domain-HEAD\domain_conf\domain_conf.module	Sun Jul 06 23:16:39 2008
+++ domain\domain_conf\domain_conf.module	Tue Jul 29 17:23:21 2008
@@ -17,6 +17,51 @@
  */
 
 /**
+ * Implementation of hook_domain_bootstrap_full().
+ *
+ * Dynamic domain settings loading: Loads the settings for the current domain.
+ *
+ * This routine was in hook_init(), but there are cases where
+ * the $conf array needs to be loaded in early phases of bootstrap.
+ * In particular, these variables need to be available during variable_init().
+ *
+ * Hook hook_domain_bootstrap_full allows to execute code at domain bootstrap
+ * time which is before drupal's hook_boot() and before variable_init().
+ *
+ * In order for this to work correctly the settings.inc needs to be included
+ * in settings.php (see readme)
+ *
+ * @param $domain
+ * Array containing domain_id for current hostname
+ *
+ * @return void
+ */
+function domain_conf_domain_bootstrap_full($domain) {
+  // To work properly this function needs to be loaded before variable_init(),
+  // therefore we check that domain bootstrap was setup correctly.
+  if (!domain_settings_setup_ok()) {
+    drupal_set_message(t('The Domain module is not installed correctly. Please edit your settings.php file as described in <a href="!url">INSTALL.txt</a>', array('!url' => base_path() . drupal_get_path('module', 'domain') .'/INSTALL.txt')), 'error', FALSE);
+    return;
+  }
+  if (!is_numeric($domain['domain_id'])) {
+    drupal_set_message('Domain Configuration: domain_conf_domain_bootstrap_full, no valid id given. ', 'error');
+    return;
+  }
+  else {
+    $data = array();
+    $data = db_fetch_array(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']));
+    if (!empty($data)) {
+      global $conf;
+      $settings = unserialize($data['settings']);
+      // Overwrite the $conf variables.
+      foreach ($settings as $key => $value) {
+        $conf[$key] = $value;
+      }
+    }
+  }
+}
+
+/**
  * Implements hook_init()
  */
 function domain_conf_init() {
@@ -105,16 +150,6 @@ function domain_conf_domainwarnings() {
     'system_site_information_settings',
     'system_site_maintenance_settings'
   );
-}
-
-/**
- * Implements hook_domaininstall()
- */
-function domain_conf_domaininstall() {
-  // If Domain Conf is being used, check to see that it is installed correctly.
-  if (module_exists('domain_conf') && !function_exists('_domain_conf_load')) {
-    drupal_set_message(t('The Domain Configuration module is not installed correctly.  Please edit your settings.php file as described in <a href="!url">INSTALL.txt</a>', array('!url' => base_path() . drupal_get_path('module', 'domain_conf') .'/INSTALL.txt')));
-  }
 }
 
 /**
diff -urpN domain-HEAD\domain_conf\domain_conf.module.bak domain\domain_conf\domain_conf.module.bak
--- domain-HEAD\domain_conf\domain_conf.module.bak	Thu Jan 01 01:00:00 1970
+++ domain\domain_conf\domain_conf.module.bak	Sun Jul 06 23:16:39 2008
@@ -0,0 +1,334 @@
+<?php
+// $Id: domain_conf.module,v 1.25 2008/07/06 21:16:39 agentken Exp $
+
+/**
+ * @defgroup domain_conf Domain Conf: configuration extension
+ * Functions for the Domain Conf module.
+ */
+
+/**
+ * @file
+ * Domain manager configuration options.
+ *
+ * For this module to work correctly, you will need to follow the INSTALL.txt
+ * instructions for editing your settings.php file.
+ *
+ * @ingroup domain_conf
+ */
+
+/**
+ * Implements hook_init()
+ */
+function domain_conf_init() {
+  // Allow sites to add implementations of hook_domainconf() without hacking.
+  // See http://drupal.org/node/236877.
+  if (arg(0) == 'admin') {
+    $extra = drupal_get_path('module', 'domain_conf') .'/domain_conf.inc';
+    if (file_exists($extra)) {
+      include_once($extra);
+    }
+  }
+}
+
+/**
+ * Implements hook_menu()
+ */
+function domain_conf_menu() {
+  $items = array();
+  $items['admin/build/domain/conf/%domain'] = array(
+    'title' => 'Domain site settings',
+    'type' => MENU_CALLBACK,
+    'access arguments' => array('administer domains'),
+    'page callback' => 'domain_conf_page',
+    'page arguments' => array(4),
+    'file' => 'domain_conf.admin.inc',
+  );
+  $items['admin/build/domain/conf-reset/%domain'] = array(
+    'title' => 'Domain site settings',
+    'type' => MENU_CALLBACK,
+    'access arguments' => array('administer domains'),
+    'page callback' => 'domain_conf_reset',
+    'page arguments' => array(4),
+    'file' => 'domain_conf.admin.inc',
+  );
+  return $items;
+}
+
+/**
+ * Implements hook_theme()
+ */
+function domain_conf_theme() {
+  $themes = array(
+    'domain_conf_reset' => array(
+      'arguments' => array('domain' => array()),
+    ),
+  );
+  return $themes;
+}
+
+/**
+ * Implements hook_domainlinks()
+ */
+function domain_conf_domainlinks($domain) {
+  $links[] = array(
+    'title' => t('settings'),
+    'path' => 'admin/build/domain/conf/'. $domain['domain_id']
+  );
+  return $links;
+}
+
+/**
+ * Implements hook_form_alter()
+ *
+ * Since this function is only loaded at the path admin/build/domain/conf, we
+ * don't have to worry about hook_form_alter() being called when not wanted.
+ */
+function domain_conf_form_alter(&$form, &$form_state, $form_id) {
+  // TODO: Replace with hook_domainbatch()?
+  // Check to be certain that we are on the right form page.
+  $module = arg(2);
+  $action = arg(3);
+  // If we are making the form, load our alterations.
+  if ($form_id == 'system_site_information_settings' && $module == 'domain' && $action == 'conf') {
+    domain_conf_system($form, $form_state, $form_id);
+  }
+}
+
+/**
+ * Implements hook_domainwarnings()
+ */
+function domain_conf_domainwarnings() {
+  // These are the forms for variables set by Domain Conf.
+  return array(
+    'system_admin_theme_settings',
+    'system_date_time_settings',
+    'system_site_information_settings',
+    'system_site_maintenance_settings'
+  );
+}
+
+/**
+ * Implements hook_domaininstall()
+ */
+function domain_conf_domaininstall() {
+  // If Domain Conf is being used, check to see that it is installed correctly.
+  if (module_exists('domain_conf') && !function_exists('_domain_conf_load')) {
+    drupal_set_message(t('The Domain Configuration module is not installed correctly.  Please edit your settings.php file as described in <a href="!url">INSTALL.txt</a>', array('!url' => base_path() . drupal_get_path('module', 'domain_conf') .'/INSTALL.txt')));
+  }
+}
+
+/**
+ * Implements hook_domainbatch()
+ */
+function domain_conf_domainbatch() {
+  $batch = array();
+  // Allows the deletion of all Domain Configuration rows.
+  $batch['domain_conf'] = array(
+    '#form' => array(
+      '#title' => t('Reset configurations'),
+      '#type' => 'checkbox',
+      '#options' => array(0 => 1, 1 => t('Reset')),
+      '#description' => t('Delete custom settings for this domain.'),
+    ),
+    '#domain_action' => 'domain_delete',
+    '#system_default' => 0,
+    '#variable' => 'domain_conf',
+    '#meta_description' => t('Delete custom settings for domains as supplied by Domain Configuration.'),
+    '#table' => 'domain_conf',
+    '#weight' => -2,
+  );
+  // Change the email address.
+  $batch['site_mail'] = array(
+    '#form' => array(
+      '#title' => t('Email address'),
+      '#type' => 'textfield',
+      '#size' => 40,
+      '#maxlength' => 255,
+      '#description' => t('Set the email address for this domain.'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('site_mail', ''),
+    '#variable' => 'site_mail',
+    '#meta_description' => t('Set the email address for all domains.'),
+    '#data_type' => 'string',
+    '#weight' => -8,
+  );
+  // Change the site slogan.
+  $batch['site_slogan'] = array(
+    '#form' => array(
+      '#title' => t('Site slogan'),
+      '#type' => 'textfield',
+      '#size' => 60,
+      '#maxlength' => 255,
+      '#description' => t('The slogan of this domain. Some themes display a slogan when available.'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('site_slogan', ''),
+    '#variable' => 'site_slogan',
+    '#meta_description' => t('Set the site slogan for all domains.'),
+    '#data_type' => 'string',
+    '#weight' => -8,
+  );
+  // Change the site slogan.
+  $batch['site_mission'] = array(
+    '#form' => array(
+      '#title' => t('Site mission'),
+      '#type' => 'textarea',
+      '#cols' => 30,
+      '#rows' => 5,
+      '#description' => t('The mission statement or focus for this domain.'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('site_mission', ''),
+    '#variable' => 'site_mission',
+    '#meta_description' => t('Set the site mission for all domains.'),
+    '#data_type' => 'string',
+    '#weight' => -8,
+  );
+  // Change the site footer.
+  $batch['site_footer'] = array(
+    '#form' => array(
+      '#title' => t('Site footer'),
+      '#type' => 'textarea',
+      '#cols' => 30,
+      '#rows' => 5,
+      '#description' => t('This text will be displayed at the bottom of each page for this domain.'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('site_footer', ''),
+    '#variable' => 'site_footer',
+    '#meta_description' => t('Set the site footer for all domains.'),
+    '#data_type' => 'string',
+    '#weight' => -8,
+  );
+  // Change the site frontpage.
+  $batch['site_frontpage'] = array(
+    '#form' => array(
+      '#title' => t('Site frontpage'),
+      '#type' => 'textfield',
+      '#size' => 30,
+      '#maxlength' => 255,
+      '#description' => t('The home page displays content from this relative URL. If unsure, specify "node".'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('site_frontpage', 'node'),
+    '#variable' => 'site_frontpage',
+    '#meta_description' => t('Set the site frontpage for all domains.'),
+    '#data_type' => 'string',
+    '#weight' => -8,
+  );
+  // Change the anonymous user name.
+  $batch['anonymous'] = array(
+    '#form' => array(
+      '#title' => t('Anonymous user'),
+      '#type' => 'textfield',
+      '#size' => 30,
+      '#maxlength' => 255,
+      '#description' => t('The name used to indicate anonymous users for this domain.'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('anonymous', 'Anonymous'),
+    '#variable' => 'anonymous',
+    '#meta_description' => t('Set the anonymous user label for all domains.'),
+    '#data_type' => 'string',
+    '#weight' => -8,
+  );
+  // Change the administrative theme.
+  $themes = list_themes();
+  ksort($themes);
+  $options[] = t('Use domain default theme');
+  foreach ($themes as $key => $value) {
+    $options[$key] = $key;
+  }
+  $batch['admin_theme'] = array(
+    '#form' => array(
+      '#title' => t('Administrative theme'),
+      '#type' => 'select',
+      '#options' => $options,
+      '#description' => t('Select the administrative theme for this domain.'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('admin_theme', 0),
+    '#variable' => 'admin_theme',
+    '#meta_description' => t('Set the administrative theme for all domains.'),
+    '#data_type' => 'string',
+    '#weight' => -8,
+  );
+  // Change the timezone.
+  $zones = _system_zonelist();
+  $batch['date_default_timezone'] = array(
+    '#form' => array(
+      '#title' => t('Timezone default'),
+      '#type' => 'select',
+      '#options' => $zones,
+      '#description' => t('Select the default site time zone.'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('date_default_timezone', 0),
+    '#variable' => 'date_default_timezone',
+    '#meta_description' => t('Set the default timezone for all domains.'),
+    '#data_type' => 'string',
+    '#weight' => -8,
+  );
+  // Toggle the site offline status.
+  $batch['site_offline'] = array(
+    '#form' => array(
+      '#title' => t('Site status'),
+      '#type' => 'radios',
+      '#options' => array(t('Online'), t('Off-line')),
+      '#description' => t('Toggle online/offline status.'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('site_offline', 0),
+    '#variable' => 'site_offline',
+    '#meta_description' => t('Set the online / offline status for all domains.'),
+    '#data_type' => 'integer',
+    '#weight' => -8,
+  );
+  // Change the site offline message.
+  $batch['site_offline_message'] = array(
+    '#form' => array(
+      '#title' => t('Site offline message'),
+      '#type' => 'textarea',
+      '#cols' => 30,
+      '#rows' => 5,
+      '#description' => t('Message to show visitors when this domain is in off-line mode.'),
+    ),
+    '#domain_action' => 'domain_conf',
+    '#system_default' => variable_get('site_offline_message', ''),
+    '#variable' => 'site_offline_message',
+    '#meta_description' => t('Set the site offline message for all domains.'),
+    '#data_type' => 'string',
+    '#weight' => -8,
+  );
+  return $batch;
+}
+
+/**
+ * Retrieves elements from hook_domainconf() and formats them
+ * as needed.
+ *
+ * @param $all
+ * Should the function return all hook implementations or just those marked
+ * with the domain_settings flag.  Defaults to FALSE.  Used to determine if
+ * we are loading configuration options specific to the Domain Access module.
+ *
+ * @return
+ * An array of form elements according to the FormsAPI or an empty array.
+ */
+function domain_conf_api($all = FALSE) {
+  global $_domain;
+  $options = array();
+  $extra = module_invoke_all('domainconf', $_domain);
+  if (!empty($extra)) {
+    foreach ($extra as $key => $value) {
+      if ($value['#domain_setting'] == TRUE || $all == TRUE) {
+        // Discard the #domain_setting flag; it is not needed.
+        unset($value['#domain_setting']);
+        // Set the $options array.
+        $options[$key] = $value;
+      }
+    }
+  }
+  return $options;
+}
diff -urpN domain-HEAD\domain_conf\settings_domain_conf.inc domain\domain_conf\settings_domain_conf.inc
--- domain-HEAD\domain_conf\settings_domain_conf.inc	Fri Jul 04 21:48:48 2008
+++ domain\domain_conf\settings_domain_conf.inc	Thu Jan 01 01:00:00 1970
@@ -1,54 +0,0 @@
-<?php
-// $Id: settings_domain_conf.inc,v 1.9 2008/07/04 19:48:48 agentken Exp $
-
-/**
- * @file
- * Dynamic domain settings loading.
- *
- * Loads the settings for the current domain.
- *
- * This routine was in hook_init(), but there are cases where
- * the $conf array needs to be loaded in early phases of bootstrap.
- * In particular, these variables need to be available during variable_init().
- *
- * In order for this to work, we must leap ahead in the boostrap process.
- * This step ensures that the database functions are active.
- * Then we run our function, overriding the default $conf variables, as
- * indicated in settings.php
- *
- * @ingroup domain_conf
- */
-
-_drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
-_domain_conf_load();
-
-/**
- * Load the variables for this subdomain
- *
- * @ingroup conf
- */
-function _domain_conf_load($domain = NULL) {
-  $check = db_result(db_query("SELECT status FROM {system} WHERE name = 'domain_conf'"));
-  if ($check > 0) {
-    if (is_null($domain)) {
-      // We lower case this, since EXAMPLE.com == example.com.
-      $_subdomain = strtolower(rtrim($_SERVER['HTTP_HOST']));
-      // Lookup the active domain against our allowed hosts record.
-      $domain = db_fetch_array(db_query("SELECT domain_id FROM {domain} WHERE subdomain = '%s'", $_subdomain));
-    }
-    // If nothing was found, use the default domain.
-    if (!isset($domain['domain_id'])) {
-      $domain['domain_id'] = 0;
-    }
-    $data = array();
-    $data = db_fetch_array(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']));
-    if (!empty($data)) {
-      global $conf;
-      $settings = unserialize($data['settings']);
-      // Overwrite the $conf variables.
-      foreach ($settings as $key => $value) {
-        $conf[$key] = $value;
-      }
-    }
-  }
-}
diff -urpN domain-HEAD\domain_prefix\domain_prefix.install domain\domain_prefix\domain_prefix.install
--- domain-HEAD\domain_prefix\domain_prefix.install	Sun Mar 30 19:51:46 2008
+++ domain\domain_prefix\domain_prefix.install	Tue Jul 29 17:23:55 2008
@@ -60,3 +60,21 @@ function domain_prefix_uninstall() {
  *
  * Developer note: the next update will be update 2.
  */
+
+/**
+ * Implementation of hook_enable().
+ *
+ * Register the domain_prefix with the domain module so it's loaded during domain
+ * bootstrap and can implement domain_bootstrap hooks.
+ */
+function domain_prefix_enable() {
+  domain_bootstrap_register('domain_prefix');
+}
+
+/**
+ * Implementation of hook_disable().
+ */
+function domain_prefix_disable() {
+  domain_bootstrap_unregister('domain_prefix');
+}
+
diff -urpN domain-HEAD\domain_prefix\domain_prefix.install.bak domain\domain_prefix\domain_prefix.install.bak
--- domain-HEAD\domain_prefix\domain_prefix.install.bak	Thu Jan 01 01:00:00 1970
+++ domain\domain_prefix\domain_prefix.install.bak	Sun Mar 30 19:51:46 2008
@@ -0,0 +1,62 @@
+<?php
+// $Id: domain_prefix.install,v 1.6 2008/03/30 17:51:46 agentken Exp $
+
+/**
+ * @file
+ * Install file for the Domain Prefix module
+ */
+
+/**
+ * Implements hook_install()
+ *
+ * @ingroup drupal
+ */
+function domain_prefix_install() {
+  drupal_install_schema('domain_prefix');
+}
+
+/**
+ * Implements hook_schema()
+ */
+function domain_prefix_schema() {
+  $schema['domain_prefix'] = array(
+    'fields' => array(
+      'domain_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'status' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0),
+      'tablename' => array('type' => 'varchar', 'length' => '80', 'not null' => TRUE, 'default' => ''),
+      'module' => array('type' => 'varchar', 'length' => '80', 'not null' => TRUE, 'default' => ''),
+      'source' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)),
+    'indexes' => array(
+      'domain_id' => array('domain_id')),
+  );
+  return $schema;
+}
+
+/**
+ * Implements hook_uninstall()
+ */
+function domain_prefix_uninstall() {
+  // We must drop all the created tables.
+  $result = db_query("SELECT domain_id, tablename FROM {domain_prefix} WHERE status > 1");
+  while ($table = db_fetch_array($result)) {
+    $name = db_escape_table('domain_'. $table['domain_id'] .'_'. $table['tablename']);
+    db_query("DROP TABLE {%s}", $name);
+  }
+  // Now drop the storage table.
+  drupal_uninstall_schema('domain_prefix');
+  variable_del('domain_prefix');
+  variable_del('domain_prefix_options');
+}
+
+
+/**
+ * Update note.
+ *
+ * Since versions prior to 5.x.1.0 are not supported, and ther are no schema changes from
+ * 5.x.1 to 6.x.1, no update functions have been provided for Drupal 6.
+ *
+ * To upgrade from a release candidate, first upgrade the module to 5.x.1.0.  Then upgrade
+ * to Drupal 6.
+ *
+ * Developer note: the next update will be update 2.
+ */
diff -urpN domain-HEAD\domain_prefix\domain_prefix.module domain\domain_prefix\domain_prefix.module
--- domain-HEAD\domain_prefix\domain_prefix.module	Fri Jul 25 15:53:52 2008
+++ domain\domain_prefix\domain_prefix.module	Tue Jul 29 17:24:24 2008
@@ -26,6 +26,60 @@ define('DOMAIN_PREFIX_DROP', 8);
 define('DOMAIN_PREFIX_UPDATE', 16);
 
 /**
+ * Implementation of hook_domain_bootstrap_full().
+ *
+ * Dynamic domain settings loading: Loads the settings for the current domain.
+ *
+ * This routine was in hook_init(), but there are cases where
+ * the $conf array needs to be loaded in early phases of bootstrap.
+ * In particular, these variables need to be available during variable_init().
+ *
+ * Hook hook_domain_bootstrap_full allows to execute code at domain bootstrap
+ * time which is before drupal's hook_boot() and before variable_init().
+ *
+ * In order for this to work correctly settings.inc needs to be included
+ * in settings.php.
+ *
+ * @param $domain
+ * Array containing domain_id for current hostname
+ *
+ * @return void
+ */
+function domain_prefix_domain_bootstrap_full($domain) {
+  // To work properly this function needs to be loaded before variable_init(),
+  // therefore we check that domain bootstrap was setup correctly.
+  if (!domain_settings_setup_ok()) {
+    drupal_set_message(t('The Domain module is not installed correctly. Please edit your settings.php file as described in <a href="!url">INSTALL.txt</a>', array('!url' => base_path() . drupal_get_path('module', 'domain') .'/INSTALL.txt')), 'error', FALSE);
+    return;
+  }
+  else if (!is_numeric($domain['domain_id'])) {
+    drupal_set_message('Domain Prefix: domain_prefix_domain_bootstrap_full, no valid id given. ', 'error');
+    return;
+  }
+  else {
+    $tables = array();
+    $prefix = 'domain_'. $domain['domain_id'] .'_';
+    $result = db_query("SELECT tablename FROM {domain_prefix} WHERE domain_id = %d AND status > %d", $domain['domain_id'], 1);
+    while ($data = db_fetch_array($result)) {
+      $tables[] = $data['tablename'];
+    }
+    if (!empty($tables)) {
+      global $db_prefix;
+      $new_prefix = array();
+      // There might be global prefixing; if so, prepend the global.
+      if (is_string($db_prefix)) {
+        $new_prefix['default'] = $db_prefix;
+        $prefix = $db_prefix . $prefix;
+      }
+      foreach ($tables as $table) {
+        $new_prefix[$table] = $prefix;
+      }
+      $db_prefix = $new_prefix;
+    }
+  }
+}
+
+/**
  * Implements hook_menu()
  */
 function domain_prefix_menu() {
@@ -73,16 +127,6 @@ function domain_prefix_theme() {
     ),
   );
   return $themes;
-}
-
-/**
- * Implements hook_domaininstall()
- */
-function domain_prefix_domaininstall() {
-  // If Domain Prefix is being used, check to see that it is installed correctly.
-  if (module_exists('domain_prefix') && !function_exists('_domain_prefix_load')) {
-    drupal_set_message(t('The Domain Prefix module is not installed correctly.  Please edit your settings.php file as described in <a href="!url">INSTALL.txt</a>', array('!url' => base_path() . drupal_get_path('module', 'domain_prefix') .'/INSTALL.txt')));
-  }
 }
 
 /**
diff -urpN domain-HEAD\domain_prefix\domain_prefix.module.bak domain\domain_prefix\domain_prefix.module.bak
--- domain-HEAD\domain_prefix\domain_prefix.module.bak	Thu Jan 01 01:00:00 1970
+++ domain\domain_prefix\domain_prefix.module.bak	Fri Jul 25 15:53:52 2008
@@ -0,0 +1,126 @@
+<?php
+// $Id: domain_prefix.module,v 1.19 2008/07/25 13:53:52 agentken Exp $
+
+/**
+ * @defgroup domain_prefix Domain Prefix: dynamic table prefixing
+ *
+ * Allows for the dynamic table prefixing of selected database tables.
+ */
+
+/**
+ * @file
+ * Interface for selective table prefixing for use with Domain Access.
+ * For this module to work correctly, you will need to follow the INSTALL.txt
+ * instructions for editing your settings.php file.
+ *
+ * @ingroup domain_prefix
+ */
+
+/**
+ * Constant definitions for the various actions.
+ */
+define('DOMAIN_PREFIX_IGNORE', 1);
+define('DOMAIN_PREFIX_CREATE', 2);
+define('DOMAIN_PREFIX_COPY', 4);
+define('DOMAIN_PREFIX_DROP', 8);
+define('DOMAIN_PREFIX_UPDATE', 16);
+
+/**
+ * Implements hook_menu()
+ */
+function domain_prefix_menu() {
+  $items = array();
+  $items['admin/build/domain/prefix'] = array(
+    'title' => 'Table prefixing',
+    'type' => MENU_LOCAL_TASK,
+    'access arguments' => array('administer table prefixing'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_prefix_configure_form'),
+    'file' => 'domain_prefix.admin.inc',
+  );
+  $items['admin/build/domain/prefix/%domain'] = array(
+    'title' => 'Domain prefix settings',
+    'access arguments' => array('administer table prefixing'),
+    'type' => MENU_CALLBACK,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('domain_prefix_form', 4),
+    'file' => 'domain_prefix.admin.inc',
+  );
+  $items['domain_prefix_update'] = array(
+    'title' => 'Domain prefix update',
+    'access arguments' => array('administer table prefixing'),
+    'type' => MENU_CALLBACK,
+    'page callback' => 'domain_prefix_update',
+    'file' => 'domain_prefix.admin.inc',
+  );
+  return $items;
+}
+
+/**
+ * Implements hook_perm
+ */
+function domain_prefix_perm() {
+  return array('administer table prefixing');
+}
+
+/**
+ * Implements hook_theme()
+ */
+function domain_prefix_theme() {
+  $themes = array(
+    'domain_prefix_configure_form' => array(
+      'arguments' => array('form' => array()),
+    ),
+  );
+  return $themes;
+}
+
+/**
+ * Implements hook_domaininstall()
+ */
+function domain_prefix_domaininstall() {
+  // If Domain Prefix is being used, check to see that it is installed correctly.
+  if (module_exists('domain_prefix') && !function_exists('_domain_prefix_load')) {
+    drupal_set_message(t('The Domain Prefix module is not installed correctly.  Please edit your settings.php file as described in <a href="!url">INSTALL.txt</a>', array('!url' => base_path() . drupal_get_path('module', 'domain_prefix') .'/INSTALL.txt')));
+  }
+}
+
+/**
+ * Implements hook_domainlinks()
+ *
+ * @param $domain
+ *  The currently active $domain array, provided by domain_lookup().
+ */
+function domain_prefix_domainlinks($domain) {
+  if (user_access('administer table prefixing')) {
+    $links[] = array(
+      'title' => t('tables'),
+      'path' => 'admin/build/domain/prefix/'. $domain['domain_id']
+    );
+    return $links;
+  }
+}
+
+/**
+ * Implements hook_domainupdate().
+ */
+function domain_prefix_domainupdate($op, $domain, $form_state = array()) {
+  // Include the extra functions.
+  include_once(drupal_get_path('module', 'domain_prefix') .'/domain_prefix.admin.inc');
+  switch ($op) {
+    case 'create':
+      $rule = variable_get('domain_prefix_options', 1);
+      if ($rule) {
+        // Get the current settings.
+        $settings = variable_get('domain_prefix', NULL);
+        if (!empty($settings)) {
+          $settings['domain_id'] = $domain['domain_id'];
+          drupal_execute('domain_prefix_form', $settings, $domain['domain_id'], $form_state);
+        }
+      }
+      break;
+    case 'delete':
+      domain_prefix_drop_records($domain['domain_id']);
+      break;
+  }
+}
diff -urpN domain-HEAD\domain_prefix\settings_domain_prefix.inc domain\domain_prefix\settings_domain_prefix.inc
--- domain-HEAD\domain_prefix\settings_domain_prefix.inc	Fri Jul 04 21:48:48 2008
+++ domain\domain_prefix\settings_domain_prefix.inc	Thu Jan 01 01:00:00 1970
@@ -1,52 +0,0 @@
-<?php
-// $Id: settings_domain_prefix.inc,v 1.10 2008/07/04 19:48:48 agentken Exp $
-
-/**
- * @file
- * Dynamic domain table prefix loading.
- *
- * Loads the table prefixes for the current domain.
- *
- * @ingroup domain_prefix
- */
-
-_drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
-_domain_prefix_load();
-
-/**
- * Load the prefixes for this subdomain
- *
- * @ingroup prefix
- */
-function _domain_prefix_load($domain = NULL) {
-  $check = db_result(db_query("SELECT status FROM {system} WHERE name = '%s'", 'domain_prefix'));
-  if ($check > 0) {
-    if (is_null($domain)) {
-      // We lower case this, since EXAMPLE.com == example.com.
-      $_subdomain = strtolower(rtrim($_SERVER['HTTP_HOST']));
-      // Lookup the active domain against our allowed hosts record.
-      $domain = db_fetch_array(db_query("SELECT domain_id FROM {domain} WHERE subdomain = '%s'", $_subdomain));
-    }
-    if (isset($domain['domain_id'])) {
-      $tables = array();
-      $prefix = 'domain_'. $domain['domain_id'] .'_';
-      $result = db_query("SELECT tablename FROM {domain_prefix} WHERE domain_id = %d AND status > %d", $domain['domain_id'], 1);
-      while ($data = db_fetch_array($result)) {
-        $tables[] = $data['tablename'];
-      }
-      if (!empty($tables)) {
-        global $db_prefix;
-        $new_prefix = array();
-        // There might be global prefixing; if so, prepend the global.
-        if (is_string($db_prefix)) {
-          $new_prefix['default'] = $db_prefix;
-          $prefix = $db_prefix . $prefix;
-        }
-        foreach ($tables as $table) {
-          $new_prefix[$table] = $prefix;
-        }
-        $db_prefix = $new_prefix;
-      }
-    }
-  }
-}
diff -urpN domain-HEAD\settings.inc domain\settings.inc
--- domain-HEAD\settings.inc	Thu Jan 01 01:00:00 1970
+++ domain\settings.inc	Thu Jul 17 16:41:54 2008
@@ -0,0 +1,45 @@
+<?php
+// $Id$
+/**
+ *
+ * @file
+ * settings.inc
+ *
+ * This file should be included at the bottom of your settings.php file:
+ * <?php
+ * require_once '/sites/all/modules/domain/settings.inc';
+ * ?>
+ * If you have installed the domain module into a different folder than
+ * /sites/all/modules/domain please adjust the path approriately.
+ *
+ * @ingroup domain
+ */
+
+/**
+ * Include bootstrap file, setup setup checker function and start bootstrap phases.
+ */
+require_once 'domain_bootstrap.inc';
+domain_settings_setup_ok();
+domain_bootstrap();
+
+/**
+ * Small helper function to determine whether this file was included correctly in
+ * the user's settings.php
+ *
+ * If it was included at the right time than cache.inc shouldn't be included
+ * yet and the function 'cache_get' not be defined.
+ *
+ * When the function is called first (from within this file) the state is saved
+ * in a static variable, every later call will return that boolean value.
+ *
+ * @return
+ * TRUE if settings.inc was included correctly in settings.php, else FALSE
+ */
+function domain_settings_setup_ok() {
+  static $state = NULL;
+  if ($state === NULL) {
+    $state = !function_exists('cache_get');
+  }
+  return $state;
+}
+
