fetchField(); if (empty($check)) { return NULL; } // Load bootstrap modules registered by Domain Access. _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_NAME_RESOLVE: // Get the domain_id of the request. $_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: // Make sure the load process worked correctly before invoking the hook. if (!domain_settings_setup_ok()) { return FALSE; } // Grant access to all affiliates. See http://drupal.org/node/770650 $_domain['site_grant'] = DOMAIN_SITE_GRANT; _domain_bootstrap_invoke_all('full', $_domain); break; } return TRUE; } /** * Returns a list of modules which are loaded during domain_bootstrap phases. * * 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 ($reset || is_null($modules)) { $modules = _domain_bootstrap_modules_get(); if (!is_array($modules)) { $modules = array(); } if (!in_array('domain', $modules)) { $modules['-99'] = '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. */ function _domain_bootstrap_modules_get() { global $conf; $key = 'domain_bootstrap_modules'; $table = domain_get_primary_table('variable'); $result = db_query("SELECT value FROM $table WHERE name = :name", array(':name' => $key))->fetchField(); if (!empty($result)) { $conf[$key] = unserialize($result); } else { $conf[$key] = array('domain'); } return $conf[$key]; } /** * 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. * * @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); } elseif (isset($result)) { $return[] = $result; } } } return $return; } /** * Escape the names of the default tables for variable lookups. * * There are a few cases where we must directly query data from the * primary site's database. Due to table prefixing and Domain Prefix, we * must ensure that we are querying the correct table. * * When using this function, you should insert the $table result directly * into your query string, or use token replacement '%s' syntax. Do not * enclose the table name in brackets {}, as that defeats the purpose of * this function. * * @see _domain_conf_load_primary() * * @param $table * The name of the base table to lookup. * @return * A query-safe table name pointing to the primary domain. */ function domain_get_primary_table($table) { global $db_prefix; if (is_string($db_prefix)) { $table = $db_prefix . $table; } elseif (is_array($db_prefix)) { $table = $db_prefix['default'] . $table; } return db_escape_table($table); }