_domain_prefix_load

Definition

_domain_prefix_load($domain = NULL)
domain_prefix/settings_domain_prefix.inc, line 20

Description

Load the prefixes for this subdomain

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;
      }
    }
  }
}