function domain_conf_menu($may_cache) {
$items = array();
if (!$may_cache) {
$items[] = array(
'title' => t('Domain site settings'),
'path' => 'admin/build/domain/conf',
'access' => user_access('administer domains'),
'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'),
'type' => MENU_CALLBACK,
'callback' => 'domain_conf_reset',
'callback arguments' => array(arg(4))
);
if (arg(0) == 'admin') {
$extra = drupal_get_path('module', 'domain_conf') .'/domain_conf.inc';
if (file_exists($extra)) {
include_once($extra);
}
}
}
return $items;
}
function domain_conf_page($domain_id) {
global $_domain;
$domain = domain_lookup($domain_id);
$output = theme_domain_conf_reset($domain);
if ($domain['domain_id'] > 0) {
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.');
}
}
function domain_conf_default($domain) {
drupal_set_title(t('!site : Domain site settings', array('!site' => $domain['sitename'])));
$form = array();
$extra = domain_conf_api();
if (!empty($extra)) {
$form = $extra;
$form['domain_conf_message'] = array(
'#type' => 'markup',
'#value' => t('<p>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.</p>'),
'#weight' => -100,
);
$form['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']);
$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;
}
function domain_conf_domainlinks($domain) {
$links[] = array(
'title' => t('settings'),
'path' => 'admin/build/domain/conf/'. $domain['domain_id']
);
return $links;
}
function domain_conf_form_alter($form_id, &$form) {
if ($form_id == 'system_site_information_settings') {
$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
);
$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]);
}
$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;
$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'),
);
$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.')
);
$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 <a href="@user-login">user login</a> 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.')
);
$form['main']['site_name']['#disabled'] = TRUE;
$form['main']['site_name']['#description'] = t('The name of this web site, as entered in the <a href="!url">domain-specific settings</a>.', array('!url' => url('admin/build/domain/edit/'. $domain['domain_id'])));
$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'));
$form['domain_id'] = array('#type' => 'value', '#value' => $domain['domain_id']);
$extra = domain_conf_api(TRUE);
$form = array_merge($form, $extra);
$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
);
}
}
}
function domain_conf_form_submit($form_id, $form_values) {
$settings = $form_values;
$unset = array('form_token', 'form_id', 'op', 'submit');
foreach ($unset as $key) {
unset($settings[$key]);
}
$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));
}
drupal_set_message(t('Domain options saved successfully.'));
}
function domain_conf_domainwarnings() {
return array(
'system_admin_theme_settings',
'system_date_time_settings',
'system_site_information_settings',
'system_site_maintenance_settings'
);
}
function domain_conf_domaininstall() {
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 <a href="!url">INSTALL.txt</a>', array('!url' => base_path() . drupal_get_path('module', 'domain_conf') .'/INSTALL.txt')));
}
}
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);
}
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;
}
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.'));
}
function theme_domain_conf_reset($domain) {
$output = '';
$output .= '<p>'. t('These settings will replace or supplement your default site settings when %name is the active domain.', array('%name' => $domain['sitename'])) .'</p>';
$data = db_fetch_array(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']));
if (!empty($data)) {
$output .= '<p>'. t('You may <a href="!url">erase these settings</a> to restore the default behavior.', array('!url' => url('admin/build/domain/conf-reset/'. $domain['domain_id']))) .'</p>';
}
return $output;
}
function domain_conf_domainbatch() {
$batch = array();
$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,
);
$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,
);
$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,
);
$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,
);
$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,
);
$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,
);
$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,
);
$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,
);
$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,
);
$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,
);
$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,
);
return $batch;
}
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) {
unset($value['#domain_setting']);
$options[$key] = $value;
}
}
}
return $options;
}