You are here

function _domain_prefix_load in Domain Access 5

Load the prefixes for this subdomain

2 calls to _domain_prefix_load()
domain_cron in ./domain.module
Implement hook_cron()
settings_domain_prefix.inc in domain_prefix/settings_domain_prefix.inc
2 string references to '_domain_prefix_load'
domain_cron in ./domain.module
Implement hook_cron()
domain_prefix_domaininstall in domain_prefix/domain_prefix.module
Implement hook_domaininstall()

File

domain_prefix/settings_domain_prefix.inc, line 20

Code

function _domain_prefix_load($domain = NULL) {
  $check = db_result(db_query("SELECT status FROM {system} WHERE name = '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 > 1", $domain['domain_id']);
      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;
      }
    }
  }
}