The following domains have been created for your site. The currently active domain is shown in boldface. You may click on a domain to change the currently active domain. Your default domain has an ID of zero (0).
'); $header = array( array('data' => t('Id'), 'field' => 'd.domain_id'), array('data' => t('Domain'), 'field' => 'd.subdomain'), array('data' => t('Site name'), 'field' => 'd.sitename'), array('data' => t('Status'), 'field' => 'd.valid'), array('data' => t('Scheme'), 'field' => 'd.scheme'), ); // Get header elements from other modules $extra = module_invoke_all('domainview', 'header'); $header = array_merge($header, $extra); $header[] = array('data' => t('Actions')); // Cannot use domain_domains() here because we need to sort the output. $domains = array(); $actions = array(); // Get any select sql from other modules. $select = module_invoke_all('domainview', 'select'); $select_sql = ''; if (!empty($select)) { $select_sql = ', '. implode(', ', $select); $select_sql = rtrim($select_sql, ','); } // Get any tablesort sql from other modules. $join = module_invoke_all('domainview', 'join'); $join_sql = ''; if (!empty($join)) { $join_sql = ' '. implode(' ', $join); } $sql = 'SELECT d.*'. $select_sql .' FROM {domain} d'. $join_sql . tablesort_sql($header); $result = pager_query($sql, variable_get('domain_list_size', DOMAIN_LIST_SIZE)); while ($data = db_fetch_array($result)) { $domains[] = $data; } foreach ($domains as $domain) { // Let submodules overwrite the defaults, if they wish. $domain = domain_api($domain); $link = l($domain['subdomain'], domain_get_uri($domain), array('absolute' => TRUE)); if ($domain['domain_id'] > 0) { $actions = array(); $actions[] = l(t('edit'), 'admin/build/domain/edit/'. $domain['domain_id']); $actions[] = l(t('delete'), 'admin/build/domain/delete/'. $domain['domain_id']); } // Add advanced settings from other modules. $items = array(); $items = module_invoke_all('domainlinks', $domain); if (!empty($items)) { foreach ($items as $item) { if (!empty($item)) { $actions[] = l($item['title'], $item['path']); } } } // Set the valid flag. ($domain['valid'] == 1) ? $valid = t('Active') : $valid = t('Inactive'); $row = array($domain['domain_id'], ($domain['domain_id'] == $_domain['domain_id']) ? ''. $link .'' : $link, filter_xss_admin($domain['sitename']), $valid, $domain['scheme']); // Let other modules add data. foreach (module_implements('domainview') as $module) { $row[] = module_invoke($module, 'domainview', 'data', $domain); } // Add the actions. $row[] = theme('item_list', $actions); $rows[] = $row; } if (!empty($rows)) { $output .= theme_table($header, $rows, array('id' => 'domain-list')); $output .= theme('pager', NULL, variable_get('domain_list_size', DOMAIN_LIST_SIZE), 0); return $output; } else { return t('No domains have been configured.'); } } /** * Module settings and behaviors. */ function domain_configure() { if (empty($_POST)) { // Is the module installed correctly? module_invoke_all('domaininstall'); } // Return the configuration form. return drupal_get_form('domain_configure_form'); } /** * FormsAPI for configuring the domain module. */ function domain_configure_form($form_state, $user_submitted = FALSE) { $root = variable_get('domain_root', ''); if (empty($root)) { domain_set_primary_domain(); } $form = array(); $form['domain'] = array( '#type' => 'fieldset', '#title' => t('Default domain settings'), '#collapsible' => TRUE ); $sitename = variable_get('site_name', 'Drupal'); $form['domain']['domain_root'] = array( '#type' => 'textfield', '#title' => t('Primary domain name'), '#size' => 40, '#maxlength' => 80, '#required' => TRUE, '#default_value' => variable_get('domain_root', ''), '#description' => t('The primary domain for your site. Typically example.com or www.example.com. Do not use http or slashes.Check the content types that should be published to all affiliates when new content is created.
')); foreach ($node_types as $key => $value) { $form['domain_node']['domain_node_'. $key] = array( '#type' => 'checkbox', '#title' => check_plain($value), '#default_value' => variable_get('domain_node_'. $key, $default), ); } // Some editors will not have full node editing permissions. This allows us // to give selected permissions for nodes within the editor's domain. $form['domain_form'] = array( '#type' => 'fieldset', '#title' => t('Domain node editing'), '#collapsible' => TRUE ); $form['domain_form']['intro'] = array('#value' => t('When editors view domain-access restricted nodes, which form elements should be exposed?
')); $options = array( 'log' => t('Log messages'), 'options' => t('Publishing options'), 'comment_settings' => t('Comment settings'), 'path' => t('Path aliasing'), 'attachments' => t('File attachments') ); ksort($options); $form['domain_form']['domain_form_elements'] = array( '#type' => 'checkboxes', '#default_value' => variable_get('domain_form_elements', array('options', 'delete', 'comment_settings', 'path')), '#options' => $options, '#description' => t('Some elements may not be editable for all users due to permission restrictions.'), ); return system_settings_form($form); } /** * Checks to see if the webserver returns a valid response * for a request to a domain. * * @param $domain * An array containing the record from the {domain} table */ function domain_check_response($domain) { $url = domain_get_path($domain) . drupal_get_path('module', 'domain') .'/tests/200.png'; $response = drupal_http_request($url); if ($response->code != 200) { drupal_set_message(t('%server is not responding and may not be configured correctly at the server level. Server code !code was returned.', array('%server' => $url, '!code' => $response->code)), 'warning'); } } /** * Allows for the batch update of certain elements. * * @param $action * The name of the action to perform; corresponds to the keys of the $batch array * returned by hook_domainbatch(). * @return * The appropriate form, or a list of actions, or an error. */ function domain_batch($action = NULL) { // We must have the module configured correctly. $domains = domain_domains(); if (empty($domains)) { return t('There are no domains configured for this site.'); } $batch = module_invoke_all('domainbatch'); // We must have some actions, otherwise, no point. if (empty($batch)) { return t('There are no batch actions configured.'); } // If we are on the main page, just list the actions. if (empty($action)) { return domain_batch_list($batch); } // If #variable is not set, eliminate the root domain. if (empty($batch[$action]['#variable'])) { unset($domains[0]); } // If we are doing a delete action, only valid domains can be acted upon. $allowed = array(); if (!empty($batch[$action]['#table'])) { $data = db_query("SELECT domain_id FROM {%s}", $batch[$action]['#table']); while ($test = db_result($data)) { $allowed[] = $domains[$test]; } if (empty($allowed)) { return t('There are no valid domains on which to perform this action. The likely reason is that no records exist in the specified table.'); } } else { $allowed = $domains; } // If we passed all the checks, generate the form. return drupal_get_form('domain_batch_form', $action, $batch[$action], $allowed); } /** * Lists available batch updates for the domain module. * * @param $batch * An array of batch actions, as defined by hook_domainbatch(). * @return * A themed table of links and descriptions for batch actions. */ function domain_batch_list($batch) { $header = array(t('Action'), t('Description')); $rows = array(); foreach ($batch as $key => $value) { if (!isset($value['#module'])) { $value['#module'] = t('Other'); } } uasort($batch, 'domain_batch_sort'); $group = ''; foreach ($batch as $key => $value) { $permission = isset($value['#permission']) ? $value['#permission'] : 'administer domains'; if (!user_access($permission)) { continue; } if ($group != $value['#module']) { $rows[] = array(array('data' => ''. t('%module options', array('%module' => $value['#module'])) .'', 'colspan' => 2)); $group = $value['#module']; } $rows[] = array(l($value['#form']['#title'], 'admin/build/domain/batch/'. $key), $value['#meta_description']); } $output = ''. t('Batch updates allow you to edit values for multiple domains at one time. These functions are helpful when moving your sites from staging to production, or any time you need to make mass changes quickly. The following batch update actions may be performed.') .'
'; $output .= ''. t('Note that you will only be shown domains on which each action may be performed. If the module is not yet configured, some actions may be empty.') .'
'; return $output . theme('table', $header, $rows); } /** * Sorting function for domain batch options. */ function domain_batch_sort($a, $b) { if ($a['#module'] != $b['#module']) { return strcmp($a['#module'], $b['#module']); } if ($a['#weight'] == $b['#weight']) { return strcmp($a['#form']['#title'], $b['#form']['#title']); } else { return ($a['#weight'] < $b['#weight']) ? -1 : 1; } } /** * Generate the form data for a batch update. * * @param $form_state * The current form state, passed by FormsAPI. * @param $action * The name of the action to perform; corresponds to the keys of the $batch array * returned by hook_domainbatch(). * @param $batch * The batch data for this $action, as defined by hook_domainbatch(). * @param $domains * The current settings for each domain. * @return * A themed table of links and descriptions for batch actions. */ function domain_batch_form($form_state, $action, $batch, $domains) { $default = array(); drupal_set_title($batch['#form']['#title']); $form = array(); $form['message'] = array( '#type' => 'markup', '#value' => theme('domain_batch_title', $batch) ); // For some values, allow every record to be updated. if (!empty($batch['#update_all'])) { $form['domain_batch_all'] = array( '#type' => 'fieldset', '#title' => t('Update value for all domains'), '#weight' => -10, '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('By entering a value below and checking the Apply to all domains option, you can set the desired value for all domains.'), ); $form['domain_batch_all']['batch_all_setting'] = $batch['#form']; $form['domain_batch_all']['batch_all_setting']['#default_value'] = $batch['#system_default']; $form['domain_batch_all']['batch_override'] = array( '#type' => 'checkbox', '#title' => t('Apply to all domains'), ); $form['domain_batch_all']['submit'] = array('#type' => 'submit', '#value' => t('Update all domain settings')); } $form['domain_batch'] = array( '#tree' => TRUE, '#title' => $batch['#form']['#title'], '#description' => $batch['#meta_description'] ); if ($batch['#domain_action'] == 'domain_conf' && $batch['#form']['#type'] == 'select') { $batch['#form']['#options'] = array('domain-conf-ignore' => t('Use primary domain settings')) + $batch['#form']['#options']; } foreach ($domains as $domain) { // Set the current value according to the stored values. if (isset($domain[$action])) { $default[$domain['domain_id']] = $domain[$action]; } if ($batch['#domain_action'] == 'domain_conf') { // Set the default value to the main settings. // In rare cases, variable_get() returns unusable data, so we override it. if (empty($batch['#override_default'])) { $default[$domain['domain_id']] = variable_get($action, $batch['#system_default']); } else { $default[$domain['domain_id']] = $batch['#system_default']; } // Check for domain-specific settings. $result = db_result(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id'])); $settings = domain_unserialize($result); if (isset($settings[$action])) { $default[$domain['domain_id']] = $settings[$action]; } } else if ($batch['#domain_action'] == 'custom' && isset($batch['#lookup'])) { $default[$domain['domain_id']] = $batch['#system_default']; $func = $batch['#lookup']; $setting = $func($domain); if ($setting != -1) { $default[$domain['domain_id']] = $setting; } } // Take the settings from the $batch array. $form['domain_batch'][$domain['domain_id']] = $batch['#form']; // Add the domain-specific elements. $form['domain_batch'][$domain['domain_id']]['#sitename'] = check_plain($domain['sitename']); if (isset($default[$domain['domain_id']])) { $form['domain_batch'][$domain['domain_id']]['#default_value'] = $default[$domain['domain_id']]; } } $api_keys = array('variable', 'table', 'data_type'); // These are optional elements, only passed if present. foreach ($api_keys as $key) { if (isset($batch['#'. $key])) { $form[$key] = array('#type' => 'value', '#value' => $batch['#'. $key]); } } // Custom submit and validate handlers. foreach (array('submit', 'validate') as $key) { if (isset($batch['#'. $key])) { $form[$key .'_handler'] = array('#type' => 'value', '#value' => $batch['#'. $key]); } } $form['handler'] = array('#type' => 'value', '#value' => $batch['#domain_action']); $form['batch_item'] = array('#type' => 'value', '#value' => $action); $form['submit'] = array('#type' => 'submit', '#value' => t('Update domain settings')); return $form; } /** * FormsAPI */ function theme_domain_admin_users_form($form) { // Overview table: $header = array( theme('table_select_header_cell'), array('data' => t('Username'), 'field' => 'u.name'), array('data' => t('Status'), 'field' => 'u.status'), t('Roles'), t('Domains'), array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'), array('data' => t('Last access'), 'field' => 'u.access'), t('Operations') ); $output = drupal_render($form['options']); $output .= drupal_render($form['domain']); if (isset($form['name']) && is_array($form['name'])) { foreach (element_children($form['name']) as $key) { $rows[] = array( drupal_render($form['accounts'][$key]), drupal_render($form['name'][$key]), drupal_render($form['status'][$key]), drupal_render($form['roles'][$key]), drupal_render($form['user_domains'][$key]), drupal_render($form['member_for'][$key]), drupal_render($form['last_access'][$key]), drupal_render($form['operations'][$key]), ); } } else { $rows[] = array(array('data' => t('No users available.'), 'colspan' => '7')); } $output .= theme('table', $header, $rows); if ($form['pager']['#value']) { $output .= drupal_render($form['pager']); } $output .= drupal_render($form); return $output;} /** * FormsAPI */ function theme_domain_batch_form($form) { $output = ''; $output = drupal_render($form['message']); if (isset($form['domain_batch_all'])) { $output .= drupal_render($form['domain_batch_all']); } $header = array(t('Id'), t('Domain'), t('Setting')); $rows = array(); foreach (element_children($form['domain_batch']) as $key) { $temp = $form['domain_batch'][$key]['#title']; unset($form['domain_batch'][$key]['#title']); $row = array($key, $form['domain_batch'][$key]['#sitename'], drupal_render($form['domain_batch'][$key])); $rows[] = $row; $form['domain_batch'][$key]['#title'] = $temp; } $output .= drupal_render($form['domain_batch']); $output .= theme('table', $header, $rows); $output .= drupal_render($form); return $output; } /** * Theme function for displaying batch editing. * * @param $batch * the batch function to be performed. */ function theme_domain_batch_title($batch) { $output = ''; $output = ''. $batch['#meta_description'] .'
'; if (!empty($batch['#required'])) { $output .= ''. t('All values are required.') .'
'; } return $output; } /** * FormsAPI for validating batch form actions. */ function domain_batch_form_validate($form, &$form_state) { // Define the validation function and call it. if (isset($form_state['values']['validate_handler']) && function_exists($form_state['values']['validate_handler'])) { $form_state['values']['validate_handler']($form_state['values']); } } /** * FormsAPI for saving batch form actions. */ function domain_batch_form_submit($form, &$form_state) { if (!empty($form_state['values']['batch_override'])) { foreach ($form_state['values']['domain_batch'] AS $domain_id => $value) { $options_all[$domain_id] = $form_state['values']['batch_all_setting']; } $form_state['values']['domain_batch'] = $options_all; } $item = $form_state['values']['batch_item']; switch ($form_state['values']['handler']) { case 'domain': foreach ($form_state['values']['domain_batch'] as $key => $value) { // Note that $type in the query below is a sanitzed value passed from domain_batch_data_type(). db_query("UPDATE {domain} SET %s = ". domain_batch_data_type($form_state['values']['data_type']) ." WHERE domain_id = %d", $item, $value, $key); // Update the variable for the root domain if (!empty($form_state['values']['variable']) && $key == 0) { variable_set($form_state['values']['variable'], $value); } } break; case 'domain_conf': foreach ($form_state['values']['domain_batch'] as $key => $value) { $settings = array(); if ($key > 0 || empty($form_state['values']['variable'])) { $data = db_fetch_array(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $key)); if (isset($data['settings'])) { $settings = domain_unserialize($data['settings']); $settings[$item] = $value; db_query("UPDATE {domain_conf} SET settings = %b WHERE domain_id = %d", serialize($settings), $key); } else { $settings[$item] = $value; db_query("INSERT INTO {domain_conf} (domain_id, settings) VALUES (%d, %b)", $key, serialize($settings)); } } else if (!empty($form_state['values']['variable'])) { variable_set($form_state['values']['variable'], $value); } } break; case 'domain_delete': $table = $form_state['values']['table']; foreach ($form_state['values']['domain_batch'] as $key => $value) { if ($value == 1) { if (is_array($table)) { foreach ($table as $current) { db_query("DELETE FROM {%s} WHERE domain_id = %d", $current, $key); } } else { db_query("DELETE FROM {%s} WHERE domain_id = %d", $table, $key); } } } break; case 'custom': if (isset($form_state['values']['submit_handler']) && function_exists($form_state['values']['submit_handler'])) { $func = $form_state['values']['submit_handler']; $func($form_state['values']); } break; } drupal_set_message(t('Settings have been updated successfully.'), 'status', FALSE); } /** * Converts a data type indicator into a sql-safe string. * * @param $type * The data type defined in hook_domainbatch(). * @return * A sql-safe string ('%s', %d, %f, %b) for use with db_query(). */ function domain_batch_data_type($type) { $return = "'%s'"; switch ($type) { case 'string': break; case 'integer': $return = "%d"; break; case 'float': $return = "%f"; break; case 'binary': $return = "%b"; break; } return $return; } /** * FormsAPI to set default domain membership for each role. * * These settigns are added to the $user object. * * @see domain_get_user_domains() */ function domain_roles_form($form_state) { $form = array(); $form['domain_add_roles'] = array( '#type' => 'radios', '#options' => array( 0 => t('Add default roles dynamically'), 1 => t('Add default roles to the user account'), ), '#title' => t('Role settings behavior'), '#description' => t('Adding role settings to the user account will permanently save them for each user on account updates. Otherwise, role-based settings can be added or removed at will.'), '#default_value' => variable_get('domain_add_roles', 0), ); $roles = user_roles(); $defaults = variable_get('domain_roles', array()); $roles[0] = t('new user'); ksort($roles); $form['domain_roles'] = array( '#tree' => TRUE, '#value' => ''. t('You may set optional default domains for each site user role. These settings will be added to each user when determining the permissions the user has to view and edit content on your site. These settings are expressly needed if you allow anonymous users to post content on your site.') .'
', ); $domains = array(); foreach (domain_domains() as $key => $value) { if ($key > 0) { $domains[$key] = $value['sitename']; } else { $domains[-1] = $value['sitename']; } } foreach ($roles as $rid => $role) { $form['domain_roles'][$rid]['#tree'] = TRUE; foreach ($domains as $domain_id => $domain) { $form['domain_roles'][$rid][$domain_id] = array( '#title' => filter_xss_admin($domain), '#type' => 'checkbox', '#default_value' => (isset($defaults[$rid][$domain_id])) ? $defaults[$rid][$domain_id] : 0, ); } } $form = system_settings_form($form); // System settings form adds a theme we cannot use. unset($form['#theme']); return $form; } /** * FormsAPI */ function theme_domain_roles_form($form) { $output = ''; $header = array(t('Domains')); $rows = array(); $roles = user_roles(); $roles[0] = t('new user'); ksort($roles); $domains = domain_domains(); foreach ($roles as $rid => $role) { $header[] = $role; } foreach ($domains as $domain_id => $domain) { $row = array(); if ($domain_id == 0) { $domain_id = -1; } $row[] = filter_xss_admin($domain['sitename']); foreach ($roles as $rid => $role) { $form['domain_roles'][$rid][$domain_id]['#title'] = ''; $row[] = drupal_render($form['domain_roles'][$rid][$domain_id]); } $rows[] = $row; } $output .= drupal_render($form['domain_add_roles']); $output .= theme('table', $header, $rows); $output .= drupal_render($form); return $output; }