t('Domain site settings'), 'path' => 'admin/build/domain/conf', 'access' => user_access('administer domains') && user_access('administer site congifuration'), 'type' => MENU_CALLBACK, 'callback' => 'domain_conf_page', 'callback arguments' => array(arg(4)) ); $items[] = array( 'title' => t('Domain site settings'), 'path' => 'admin/build/domain/conf-reset', 'access' => user_access('administer domains') && user_access('administer site congifuration'), 'type' => MENU_CALLBACK, 'callback' => 'domain_conf_reset', 'callback arguments' => array(arg(4)) ); // Allow sites to add implementations of hook_domainconf() without hacking. // See http://drupal.org/node/236877. if (arg(0) == 'admin') { $extra = drupal_get_path('module', 'domain_conf') .'/domain_conf.inc'; if (file_exists($extra)) { include_once($extra); } } } return $items; } /** * The domain conf page callback router. * * @param $domain_id * The unique identifier for this domain, taken from {domain}. */ function domain_conf_page($domain_id) { global $_domain; $domain = domain_lookup($domain_id); $output = theme_domain_conf_reset($domain); if ($domain['domain_id'] > 0) { // Ensure we are on the proper domain. domain_goto($domain); drupal_set_title(t('@site : Domain site settings', array('@site' => $domain['sitename']))); return $output . drupal_get_form('system_site_information_settings'); } else if ($domain['domain_id'] == 0) { return $output . drupal_get_form('domain_conf_default', $domain); } else { return t('Invalid domain request.'); } } /** * Special configuration options for the main domain. * * @param $domain * The $domain object for the default domain. * @return * A $form array according to the FormsAPI, if unique configuration is possible. */ function domain_conf_default($domain) { drupal_set_title(t('@site : Domain site settings', array('@site' => $domain['sitename']))); $form = array(); // Grab any extra elements defined by other modules. $extra = domain_conf_api(); if (!empty($extra)) { // Convert the $extra array to the $form array. $form = $extra; $form['domain_conf_message'] = array( '#type' => 'markup', '#value' => t('
The following custom settings may be applied to the main domain. These options are specific to the Domain module and do not have standard configuration pages.
'), '#weight' => -100, ); // Domain information, for saving. $form['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']); // Submit functions $form['#submit']['domain_conf_form_submit'] = array(); $form['#validate']['domain_conf_form_validate'] = array(); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save domain settings'), '#weight' => 10 ); } else { $form['domain_conf_message'] = array('#type' => 'markup', '#value' => t('There are no custom domain settings to configure.')); } return $form; } /** * Implement hook_domainlinks() */ function domain_conf_domainlinks($domain) { $links[] = array( 'title' => t('settings'), 'path' => 'admin/build/domain/conf/'. $domain['domain_id'] ); return $links; } /** * Implement hook_form_alter() * * Since this function is only loaded at the path admin/build/domain/conf, we * don't have to worry about hook_form_alter() being called when not wanted. */ function domain_conf_form_alter($form_id, &$form) { // We use the system_site_information_settings form as a base, and add the elements we need // from other forms. The default values are altered based on stored settings. if ($form_id == 'system_site_information_settings') { // Check to be certain that we are on the right form page. $module = arg(2); $action = arg(3); if ($module == 'domain' && $action == 'conf') { $domain_id = arg(4); $domain = domain_lookup($domain_id); $data = db_result(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id'])); if (!empty($data)) { $settings = unserialize($data); } else { $settings = array(); } $unset = array('buttons', '#submit'); foreach ($unset as $key) { unset($form[$key]); } $form['main'] = array( '#type' => 'fieldset', '#title' => t('Domain information'), '#collapsible' => TRUE, '#weight' => -10 ); // Put the defaults in the fieldset $fields = array('site_name', 'site_mail', 'site_slogan', 'site_mission', 'site_footer', 'site_frontpage', 'anonymous'); foreach ($fields as $field) { $form['main'][$field] = $form[$field]; unset($form[$field]); } // Change the path for the frontpage. $prefix = $form['main']['site_frontpage']['#field_prefix']; $_path = parse_url($prefix); $str = $_path['host']; $fix = preg_replace("/$str/", $domain['subdomain'], $prefix, 1); $form['main']['site_frontpage']['#field_prefix'] = $fix; // Admin theme settings $themes = list_themes(); ksort($themes); $options[] = t('Use domain default theme'); foreach ($themes as $key => $value) { $options[$key] = $key; } $form['main']['admin_theme'] = array( '#type' => 'select', '#title' => t('Administrative theme'), '#options' => $options, '#default_value' => variable_get('admin_theme', '0'), ); // Date settings: set the default timezone $form['date'] = array( '#type' => 'fieldset', '#title' => t('Timezone settings'), '#collapsible' => TRUE, '#weight' => -5 ); $zones = _system_zonelist(); $form['date']['date_default_timezone'] = array( '#type' => 'select', '#title' => t('Default time zone'), '#default_value' => isset($settings['date_default_timezone']) ? $settings['date_default_timezone'] : variable_get('date_default_timezone', 0), '#options' => $zones, '#description' => t('Select the default site time zone.') ); // Offline notices. $form['offline'] = array( '#type' => 'fieldset', '#title' => t('Maintenance settings'), '#collapsible' => TRUE, '#weight' => 5 ); $form['offline']['site_offline'] = array( '#type' => 'radios', '#title' => t('Site status'), '#default_value' => isset($settings['site_offline']) ? $settings['site_offline'] : variable_get('site_offline', 0), '#options' => array(t('Online'), t('Off-line')), '#description' => t('When set to "Online", all visitors will be able to browse your site normally. When set to "Off-line", only users with the "administer site configuration" permission will be able to access your site to perform maintenance; all other visitors will see the site off-line message configured below. Authorized users can log in during "Off-line" mode directly via the user login page.', array('@user-login' => url('user'))), ); $form['offline']['site_offline_message'] = array( '#type' => 'textarea', '#title' => t('Site off-line message'), '#default_value' => isset($settings['site_offline_message']) ? $settings['site_offline_message'] : variable_get('site_offline_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => $domain['sitename']))), '#description' => t('Message to show visitors when the site is in off-line mode.') ); // Site name must be edited at the domain creation screen. $form['main']['site_name']['#disabled'] = TRUE; $form['main']['site_name']['#description'] = t('The name of this web site, as entered in the domain-specific settings.', array('!url' => url('admin/build/domain/edit/'. $domain['domain_id']))); // Reset the provided form defaults, if needed $form['main']['site_name']['#default_value'] = $domain['sitename']; $form['main']['site_mail']['#default_value'] = isset($settings['site_mail']) ? $settings['site_mail'] : variable_get('site_mail', ini_get('sendmail_from')); $form['main']['site_slogan']['#default_value'] = isset($settings['site_slogan']) ? $settings['site_slogan'] : variable_get('site_slogan', ''); $form['main']['site_mission']['#default_value'] = isset($settings['site_mission']) ? $settings['site_mission'] : variable_get('site_mission', ''); $form['main']['site_footer']['#default_value'] = isset($settings['site_footer']) ? $settings['site_footer'] : variable_get('site_footer', ''); $form['main']['site_frontpage']['#default_value'] = isset($settings['site_frontpage']) ? $settings['site_frontpage'] : variable_get('site_frontpage', 'node'); $form['main']['anonymous']['#default_value'] = isset($settings['anonymous']) ? $settings['anonymous'] : variable_get('anonymous', t('Guest')); // Domain information, for saving. $form['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']); // Grab any extra elements defined by other modules. $extra = domain_conf_api(TRUE); // Merge the $extra and $form arrays. $form = array_merge($form, $extra); // Submit functions $form['#submit']['domain_conf_form_submit'] = array(); $form['#validate']['domain_conf_form_validate'] = array(); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save domain settings'), '#weight' => 10 ); } } } /** * FormsAPI */ function domain_conf_form_submit($form_id, $form_values) { // Throw away what we don't need. $settings = $form_values; $unset = array('form_token', 'form_id', 'op', 'submit'); foreach ($unset as $key) { unset($settings[$key]); } // INSERT or UPDATE? $check = db_fetch_array(db_query("SELECT domain_id FROM {domain_conf} WHERE domain_id = %d", $form_values['domain_id'])); if (isset($check['domain_id'])) { $sql = "UPDATE {domain_conf} SET settings = %b WHERE domain_id = %d"; db_query($sql, serialize($settings), $form_values['domain_id']); } else { $sql = "INSERT INTO {domain_conf} VALUES (%d, %b)"; db_query($sql, $form_values['domain_id'], serialize($settings)); } // Clear the cache. cache_clear_all(); drupal_set_message(t('Domain options saved successfully.')); } /** * Implement hook_domainwarnings() */ function domain_conf_domainwarnings() { // These are the forms for variables set by Domain Conf. return array( 'system_admin_theme_settings', 'system_date_time_settings', 'system_site_information_settings', 'system_site_maintenance_settings' ); } /** * Implement hook_domaininstall() */ function domain_conf_domaininstall() { // If Domain Conf is being used, check to see that it is installed correctly. if (module_exists('domain_conf') && !function_exists('_domain_conf_load')) { drupal_set_message(t('The Domain Configuration module is not installed correctly. Please edit your settings.php file as described in INSTALL.txt', array('!url' => base_path() . drupal_get_path('module', 'domain_conf') .'/INSTALL.txt'))); } } /** * Resets configuration settings by removing the domain row from {domain_conf}. * * @param $domain_id * The domain_id of the requested domain. * @return * A confirmation form. */ function domain_conf_reset($domain_id) { $domain = domain_lookup($domain_id); if ($domain == -1) { return t('An invalid request has been made.'); } return drupal_get_form('domain_conf_reset_form', $domain); } /** * FormsAPI for resetting a domain configuration. * * @param $domain * The $domain object for the selected domain. * @return * Themed HTML form. */ function domain_conf_reset_form($domain) { $extra['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']); $extra['#redirect'] = 'admin/build/domain/conf/'. $domain['domain_id']; $form = confirm_form($extra, t('Are you sure you wish to reset the settings for %name?', array('%name' => $domain['sitename'])), 'admin/build/domain/conf/'. $domain_id, t('Submitting this form will restore default settings for this domain.')); return $form; } /** * FormsAPI for domain_conf_reset_form. */ function domain_conf_reset_form_submit($form_id, $form_values) { db_query("DELETE FROM {domain_conf} WHERE domain_id = %d", $form_values['domain_id']); drupal_set_message(t('Domain configuration settings have been reset.')); } /** * Theme a message at the top of domain configuration pages. * * @param $domain * The $domain object for the selected domain. * @return * Themed HTML messages. */ function theme_domain_conf_reset($domain) { $output = ''; $output .= ''. t('These settings will replace or supplement your default site settings when %name is the active domain.', array('%name' => $domain['sitename'])) .'
'; $data = db_fetch_array(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id'])); if (!empty($data)) { $output .= ''. t('You may erase these settings to restore the default behavior.', array('!url' => url('admin/build/domain/conf-reset/'. $domain['domain_id']))) .'
'; } return $output; } /** * Implement hook_domainbatch() */ function domain_conf_domainbatch() { $batch = array(); // Allows the deletion of all Domain Configuration rows. $batch['domain_conf'] = array( '#form' => array( '#title' => t('Reset configurations'), '#type' => 'checkbox', '#options' => array(t('Reset')), '#description' => t('Delete custom settings for this domain.'), ), '#domain_action' => 'domain_delete', '#system_default' => 0, '#variable' => 'domain_conf', '#meta_description' => t('Delete custom settings for domains as supplied by Domain Configuration.'), '#table' => 'domain_conf', '#weight' => -2, ); // Change the email address. $batch['site_mail'] = array( '#form' => array( '#title' => t('Email address'), '#type' => 'textfield', '#size' => 40, '#maxlength' => 255, '#description' => t('Set the email address for this domain.'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('site_mail', ''), '#variable' => 'site_mail', '#meta_description' => t('Set the email address for all domains.'), '#data_type' => 'string', '#weight' => -8, ); // Change the site slogan. $batch['site_slogan'] = array( '#form' => array( '#title' => t('Site slogan'), '#type' => 'textfield', '#size' => 60, '#maxlength' => 255, '#description' => t('The slogan of this domain. Some themes display a slogan when available.'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('site_slogan', ''), '#variable' => 'site_slogan', '#meta_description' => t('Set the site slogan for all domains.'), '#data_type' => 'string', '#weight' => -8, ); // Change the site slogan. $batch['site_mission'] = array( '#form' => array( '#title' => t('Site mission'), '#type' => 'textarea', '#cols' => 30, '#rows' => 5, '#description' => t('The mission statement or focus for this domain.'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('site_mission', ''), '#variable' => 'site_mission', '#meta_description' => t('Set the site mission for all domains.'), '#data_type' => 'string', '#weight' => -8, ); // Change the site footer. $batch['site_footer'] = array( '#form' => array( '#title' => t('Site footer'), '#type' => 'textarea', '#cols' => 30, '#rows' => 5, '#description' => t('This text will be displayed at the bottom of each page for this domain.'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('site_footer', ''), '#variable' => 'site_footer', '#meta_description' => t('Set the site footer for all domains.'), '#data_type' => 'string', '#weight' => -8, ); // Change the site frontpage. $batch['site_frontpage'] = array( '#form' => array( '#title' => t('Site frontpage'), '#type' => 'textfield', '#size' => 30, '#maxlength' => 255, '#description' => t('The home page displays content from this relative URL. If unsure, specify "node".'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('site_frontpage', 'node'), '#variable' => 'site_frontpage', '#meta_description' => t('Set the site frontpage for all domains.'), '#data_type' => 'string', '#weight' => -8, ); // Change the anonymous user name. $batch['anonymous'] = array( '#form' => array( '#title' => t('Anonymous user'), '#type' => 'textfield', '#size' => 30, '#maxlength' => 255, '#description' => t('The name used to indicate anonymous users for this domain.'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('anonymous', 'Anonymous'), '#variable' => 'anonymous', '#meta_description' => t('Set the anonymous user label for all domains.'), '#data_type' => 'string', '#weight' => -8, ); // Change the administrative theme. $themes = list_themes(); ksort($themes); $options[] = t('Use domain default theme'); foreach ($themes as $key => $value) { $options[$key] = $key; } $batch['admin_theme'] = array( '#form' => array( '#title' => t('Administrative theme'), '#type' => 'select', '#options' => $options, '#description' => t('Select the administrative theme for this domain.'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('admin_theme', 0), '#variable' => 'admin_theme', '#meta_description' => t('Set the administrative theme for all domains.'), '#data_type' => 'string', '#weight' => -8, ); // Change the timezone. $zones = _system_zonelist(); $batch['date_default_timezone'] = array( '#form' => array( '#title' => t('Timezone default'), '#type' => 'select', '#options' => $zones, '#description' => t('Select the default site time zone.'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('date_default_timezone', 0), '#variable' => 'date_default_timezone', '#meta_description' => t('Set the default timezone for all domains.'), '#data_type' => 'string', '#weight' => -8, ); // Toggle the site offline status. $batch['site_offline'] = array( '#form' => array( '#title' => t('Site status'), '#type' => 'radios', '#options' => array(t('Online'), t('Off-line')), '#description' => t('Toggle online/offline status.'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('site_offline', 0), '#variable' => 'site_offline', '#meta_description' => t('Set the online / offline status for all domains.'), '#data_type' => 'integer', '#weight' => -8, ); // Change the site offline message. $batch['site_offline_message'] = array( '#form' => array( '#title' => t('Site offline message'), '#type' => 'textarea', '#cols' => 30, '#rows' => 5, '#description' => t('Message to show visitors when this domain is in off-line mode.'), ), '#domain_action' => 'domain_conf', '#system_default' => variable_get('site_offline_message', ''), '#variable' => 'site_offline_message', '#meta_description' => t('Set the site offline message for all domains.'), '#data_type' => 'string', '#weight' => -8, ); foreach ($batch as $item => $values) { $batch[$item]['#permission'] = 'administer site configuration'; } return $batch; } /** * Retrieves elements from hook_domainconf() and formats them * as needed. * * @param $all * Should the function return all hook implementations or just those marked * with the domain_settings flag. Defaults to FALSE. Used to determine if * we are loading configuration options specific to the Domain Access module. * * @return * An array of form elements according to the FormsAPI or an empty array. */ function domain_conf_api($all = FALSE) { $options = array(); $extra = module_invoke_all('domainconf'); if (!empty($extra)) { foreach ($extra as $key => $value) { if ($value['#domain_setting'] == TRUE || $all == TRUE) { // Discard the #domain_setting flag; it is not needed. unset($value['#domain_setting']); // Set the $options array. $options[$key] = $value; } } } return $options; } /** * Implement hook_domainupdate(). */ function domain_conf_domainupdate($op, $domain, $edit = array()) { if ($op == 'delete') { db_query("DELETE FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']); cache_clear_all('variables', 'cache'); } }