You are here

function domain_lookup_simple in Domain Access 7.3

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

Determines the domain matching the given hostname.

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 domain name

1 call to domain_lookup_simple()
domain_resolve_host in ./domain.module
Resolve an HTTP_HOST to a registered domain.

File

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

Code

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

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

    // If no match => use default domain.
    if (!isset($domain['domain_id'])) {
      $domain['domain_id'] = domain_default_id();
    }
    $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];
}