Index: multidomain.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multidomain/multidomain.module,v
retrieving revision 1.1.2.9
diff -u -r1.1.2.9 multidomain.module
--- multidomain.module	3 May 2007 15:34:20 -0000	1.1.2.9
+++ multidomain.module	3 May 2007 16:36:51 -0000
@@ -152,6 +152,47 @@
     '#default_value' => $edit['weight'],
   );
 
+  // Add variables that can be set for this domain.
+  $form['variables'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Site configuration options'),
+    '#collapsible' => TRUE,
+    '#tree' => TRUE,
+  );
+
+  $forms = array(
+    // Key is form_id.
+    'system_site_information_settings' => array(
+      // Values are keys of form elements.
+      array('site_name'),
+      array('site_mail'),
+      array('site_slogan'),
+      array('site_mission'),
+      array('site_footer'),
+      array('site_frontpage'),
+    ),
+    'menu_configure' => array(
+      array('settings_links', 'menu_primary_menu'),
+      array('settings_links', 'menu_secondary_menu'),
+    ),
+  );
+
+  $form['variables'] += multidomain_get_form_bits($forms);
+
+  // Add default theme select.
+  $options = array();
+  foreach (list_themes() as $theme) {
+    if ($theme->status) {
+      $options[$theme->name] = $theme->name;
+    }
+  }
+  $form['variables']['theme_default'] = array(
+    '#type' => 'select',
+    '#title' => t('Default theme'),
+    '#options' => $options,
+    '#default_value' => variable_get('theme_default', 'garland'),
+  );
+
   $types = node_get_types();
   $form['page_vis_settings']['types'] = array(
     '#type' => 'checkboxes',
@@ -191,7 +232,7 @@
   $form['init'] = array(
     '#type' => 'textarea',
     '#title' => t('Initialization code'),
-    '#description' => t('Code to run during initialization of pages on this domain. Remember the <em>&lt;?php</em> and <em>?></em> tags. A common task here is overriding variables using the global $conf variable.'),
+    '#description' => t('Code to run during initialization of pages on this domain. Remember the <em>&lt;?php</em> and <em>?></em> tags.'),
     '#default_value' => $edit['init'],
   );
 
@@ -215,6 +256,20 @@
   if ($form_values['domain'] != $form_values['url']) {
     unset($domains[$form_values['url']]);
   }
+  // If the value is the same as the main domain's default, don't save it.
+  // This ensures that later changes to the main domain's settings will
+  // apply also to other domains, unless that other domain has already
+  // had a custom value set.
+    foreach ($form_values['variables'] as $name => $value) {
+    // Determine if there is an existing value.
+    if ($existing_value = db_result(db_query("SELECT value FROM {variable} WHERE name = '%s'", $name))) {
+      // If so, unserialize it and compare it to the value submitted.
+      if ($value == unserialize($existing_value)) {
+        unset($form_values['variables'][$name]);
+      }
+    }
+  }
+
   $domains[$form_values['domain']] = $form_values;
   uasort($domains, '_multidomain_domain_sort');
   variable_set('multidomain_sites', $domains);
@@ -310,15 +365,51 @@
  * Implementation of hook_init().
  */
 function multidomain_init() {
+  global $conf;
+
   $domains = variable_get('multidomain_sites', array());
   $protocol = ( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ;
   if ($domain = $domains[$protocol . $_SERVER['HTTP_HOST']]) {
+    // Set any variables specific to this domain.
+    if(isset($domain['variables']) && is_array($domain['variables'])) {
+      foreach($domain['variables'] as $name => $value) {
+drupal_set_message('setting '. $name);
+        $conf[$name] = $value;
+      }
+    }
     if ($domain['init']) {
       drupal_eval($domain['init']);
     }
   }
 }
 
+/**
+ * Return specified elements from an array of forms.
+ */
+function multidomain_get_form_bits($forms) {
+  $form = array();
+  foreach ($forms as $form_id => $elements) {
+    if (function_exists($form_id)) {
+      $source_form = $form_id();
+      foreach ($elements as $element) {
+        $return = $source_form;
+        foreach ($element as $key) {
+          if (isset($return[$key])) {
+            $return = $return[$key];
+          }
+          else {
+            break;
+          }
+        }
+        if ($return !== $source_form) {
+          $form[$key] = $return;
+        }
+      }
+    }
+  }
+  return $form;
+}
+
 if (!function_exists('custom_url_rewrite')) {
   function custom_url_rewrite($type, $alias, $real_path) {
     static $default = null;
@@ -343,8 +434,15 @@
     }
     $base = $force_default ? $default : NULL;
     foreach ($domains as $domain => $info) {
+      $page_match = FALSE;
+      // If this is a link to the configuration of this domain, match it.
+      // This is needed because we need the variables to be set to this domain's
+      // versions, so that the form elements load with the correct defaults.
+      if ($path == 'admin/settings/multidomain/settings/'. str_replace('://', '_', $domain)) {
+        $page_match = TRUE;
+      }
       // Match path if necessary
-      if ($info['pages']) {
+      if (!$page_match && $info['pages']) {
         if ($info['visibility'] < 2) {
           $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($info['pages'], '/')) .')$/';
           // Compare with the internal and path alias (if any).
@@ -361,11 +459,8 @@
           $page_match = drupal_eval($info['pages']);
         }
       }
-      else {
-        $page_match = FALSE;
-      }
 
-      if (sizeof($info['types'])) {
+      if (!$page_match && sizeof($info['types'])) {
         $parts = explode('/', $real_path);
         if ($parts[0] == 'node' && is_numeric($parts[1])) {
           $node = node_load($parts[1]);
