%d", $domain['domain_id'], 1); while ($data = db_fetch_array($result)) { $tables[] = $data['tablename']; } if (!empty($tables)) { $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; } // Keep existing $db_prefix values as they were defined in settings.php, // in case they're not overwritten in $new_prefix. // See http://drupal.org/node/632950 for background. if (is_array($db_prefix)) { $db_prefix = array_merge($db_prefix, $new_prefix); } else { $db_prefix = $new_prefix; } } else { $db_prefix = $original_prefix; } // This function may already be loaded, see http://drupal.org/node/929540. if (function_exists('domain_prefix_domainpath')) { return; } // Check for prefixes of the url_alias table, and if present add hook_domainprefix(). $count = db_result(db_query("SELECT COUNT(*) FROM {domain_prefix} WHERE status > 1 AND tablename = 'url_alias'")); if (!empty($count)) { include 'domain_prefix.path.inc'; } } /** * Implement hook_menu() */ function domain_prefix_menu() { $items = array(); $items['admin/build/domain/prefix'] = array( 'title' => 'Table prefixing', 'type' => MENU_LOCAL_TASK, 'access arguments' => array('administer table prefixing'), 'page callback' => 'drupal_get_form', 'page arguments' => array('domain_prefix_configure_form'), 'file' => 'domain_prefix.admin.inc', ); $items['admin/build/domain/prefix/%domain'] = array( 'title' => 'Domain prefix settings', 'access arguments' => array('administer table prefixing'), 'type' => MENU_CALLBACK, 'page callback' => 'drupal_get_form', 'page arguments' => array('domain_prefix_form', 4), 'file' => 'domain_prefix.admin.inc', ); $items['domain_prefix_update'] = array( 'title' => 'Domain prefix update', 'access arguments' => array('administer table prefixing'), 'type' => MENU_CALLBACK, 'page callback' => 'domain_prefix_update', 'file' => 'domain_prefix.admin.inc', ); return $items; } /** * Implement hook_perm */ function domain_prefix_perm() { return array('administer table prefixing'); } /** * Implement hook_theme() */ function domain_prefix_theme() { $themes = array( 'domain_prefix_configure_form' => array( 'arguments' => array('form' => array()), ), ); return $themes; } /** * Implement hook_enable(). * * Register the domain_prefix with the domain module so it's loaded during domain * bootstrap and can implement domain_bootstrap hooks. */ function domain_prefix_enable() { domain_bootstrap_register(); } /** * Implement hook_disable(). */ function domain_prefix_disable() { domain_bootstrap_unregister('domain_prefix'); } /** * Uniform prefix string * * @param $domain_id * The domain_id taken from {domain}. */ function domain_prefix_string($domain_id) { return 'domain_'. $domain_id .'_'; } /** * Check for existing table prefixing. */ function domain_prefix_get_prefix() { global $db_prefix; // Check for existing table prefixing. $prefix = NULL; if (!empty($db_prefix)) { if (is_array($db_prefix)) { $prefix = $db_prefix['default']; } else { $prefix = $db_prefix; } } return $prefix; } /** * Does a table exist -- we use this to bypass Drupal's default table prefixing check. * * @param $prefix * The table prefix used with this domain. Optional. * @param $table * The name of the table being acted upon. */ function domain_prefix_table_exists($prefix, $table) { return db_table_exists(db_escape_table($prefix . $table)); } /** * Implement hook_domainlinks() * * @param $domain * The currently active $domain array, provided by domain_lookup(). */ function domain_prefix_domainlinks($domain) { if (user_access('administer table prefixing') && $domain['domain_id'] > 0) { $links[] = array( 'title' => t('tables'), 'path' => 'admin/build/domain/prefix/'. $domain['domain_id'] ); return $links; } return FALSE; } /** * Implement hook_domainupdate(). */ function domain_prefix_domainupdate($op, $domain, $form_state = array()) { // Include the extra functions. include drupal_get_path('module', 'domain_prefix') .'/domain_prefix.admin.inc'; switch ($op) { case 'create': $rule = variable_get('domain_prefix_options', 1); if ($rule) { // Get the current settings. $settings = variable_get('domain_prefix', NULL); if (!empty($settings)) { $settings['domain_id'] = $domain['domain_id']; drupal_execute('domain_prefix_form', $form_state, $domain, $settings); } } break; case 'delete': domain_prefix_drop_records($domain['domain_id']); break; } }