View source
<?php
define('DOMAIN_PREFIX_IGNORE', 1);
define('DOMAIN_PREFIX_CREATE', 2);
define('DOMAIN_PREFIX_COPY', 4);
define('DOMAIN_PREFIX_DROP', 8);
define('DOMAIN_PREFIX_UPDATE', 16);
function domain_prefix_domain_bootstrap_full($domain) {
static $original_prefix;
global $db_prefix;
if (!isset($original_prefix)) {
$original_prefix = $db_prefix;
}
$tables = array();
$prefix = 'domain_' . $domain['domain_id'] . '_';
$result = db_query("SELECT tablename FROM {domain_prefix} WHERE domain_id = %d AND status > %d", $domain['domain_id'], 1);
while ($data = db_fetch_array($result)) {
$tables[] = $data['tablename'];
}
if (!empty($tables)) {
$new_prefix = array();
if (is_string($db_prefix)) {
$new_prefix['default'] = $db_prefix;
$prefix = $db_prefix . $prefix;
}
foreach ($tables as $table) {
$new_prefix[$table] = $prefix;
}
if (is_array($db_prefix)) {
$db_prefix = array_merge($db_prefix, $new_prefix);
}
else {
$db_prefix = $new_prefix;
}
}
else {
$db_prefix = $original_prefix;
}
if (function_exists('domain_prefix_domainpath')) {
return;
}
$count = db_result(db_query("SELECT 1 FROM {domain_prefix} WHERE status > 1 AND tablename = 'url_alias'"));
if ($count > 0) {
include 'domain_prefix.path.inc';
}
}
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;
}
function domain_prefix_perm() {
return array(
'administer table prefixing',
);
}
function domain_prefix_theme() {
$themes = array(
'domain_prefix_configure_form' => array(
'arguments' => array(
'form' => array(),
),
),
);
return $themes;
}
function domain_prefix_enable() {
domain_bootstrap_register();
}
function domain_prefix_disable() {
domain_bootstrap_unregister('domain_prefix');
}
function domain_prefix_string($domain_id) {
return 'domain_' . $domain_id . '_';
}
function domain_prefix_get_prefix() {
global $db_prefix;
$prefix = NULL;
if (!empty($db_prefix)) {
if (is_array($db_prefix)) {
$prefix = $db_prefix['default'];
}
else {
$prefix = $db_prefix;
}
}
return $prefix;
}
function domain_prefix_table_exists($prefix, $table) {
return db_table_exists(db_escape_table($prefix . $table));
}
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;
}
function domain_prefix_domainupdate($op, $domain, $form_state = array()) {
module_load_include('inc', 'domain_prefix', 'domain_prefix.admin');
switch ($op) {
case 'create':
$rule = variable_get('domain_prefix_options', 1);
if ($rule) {
$settings = variable_get('domain_prefix', NULL);
if (!empty($settings)) {
$settings['domain_id'] = $domain['domain_id'];
$form_state['values']['op'] = t('Generate domain tables');
$form_state['values']['execute'] = TRUE;
drupal_execute('domain_prefix_form', $form_state, $domain, $settings);
}
}
break;
case 'delete':
domain_prefix_drop_records($domain['domain_id']);
break;
}
}