You are here

function domain_lookup_simple in Domain Access 6.2

Same name and namespace in other branches
  1. 7.3 domain.module \domain_lookup_simple()
  2. 7.2 domain.module \domain_lookup_simple()

Determines a domain_id matching given $_name.

This function runs a lookup against the {domain} table matching the subdomain column against the given parameter $_name. If a match is found the function returns an array containing the domain requested 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.

Parameters

$name: The string representation of a {domain} entry.

$reset: Set TRUE to ignore cached versions and look the name up again. Optional.

Return value

An array containing a domain_id from {domain} matching the given domainname

1 call to domain_lookup_simple()
domain_resolve_host in ./domain.module
Tries to match the current (host) domain name to a domain in the {domain} table and returns a respective domain_id.

File

./domain.module, line 2398
Core module functions for the Domain Access suite.

Code

function domain_lookup_simple($name, $reset = FALSE) {
  static $cache = array();
  if (empty($name)) {
    return array();
  }
  if ($reset || !isset($cache[$name])) {

    // Lookup the given domain name against our allowed hosts record.
    $domain = db_fetch_array(db_query("SELECT domain_id, subdomain, sitename FROM {domain} WHERE subdomain = '%s'", $name));
    if (!is_array($domain)) {
      $domain = array();
    }

    // If no match => use default (0)
    if (!isset($domain['domain_id'])) {
      $domain['domain_id'] = 0;
    }
    $domain['subdomain'] = $name;

    // Invoke hook_domain_bootstrap_lookup()
    $domain_new = _domain_bootstrap_invoke_all('lookup', $domain);
    if (is_array($domain_new)) {
      if (isset($domain_new['domain_id']) && is_array($domain_new['domain_id'])) {
        foreach ($domain_new as $key => $value) {
          if (is_array($value)) {
            $domain_new[$key] = $value[0];
          }
        }
        $modules = array();
        foreach (_domain_bootstrap_modules() as $module) {
          if (function_exists($module . '_domain_bootstrap_lookup')) {
            $modules[] = $module;
          }
        }
        $lookup = domain_lookup($domain_new['domain_id']);
        $domain_new['error'] = t('domain lookup. More than one registered domain was returned. Defaulting to %domain. The likely cause is a conflict between %modules', array(
          '%domain' => $lookup['sitename'],
          '%modules' => implode(', ', $modules),
        ));
      }
      $domain = array_merge($domain, $domain_new);
    }
    $cache[$name] = $domain;
  }
  return $cache[$name];
}