Index: multidomain.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multidomain/multidomain.module,v
retrieving revision 1.1.2.15
diff -u -r1.1.2.15 multidomain.module
--- multidomain.module	3 Jun 2007 15:36:57 -0000	1.1.2.15
+++ multidomain.module	3 Jun 2007 16:44:51 -0000
@@ -2,6 +2,21 @@
 // $Id: multidomain.module,v 1.1.2.15 2007/06/03 15:36:57 nedjo Exp $
 
 /**
+ * Don't rewrite node SQL to filter by taxonomy.
+ */
+define('MULTIDOMAIN_TAXONOMY_REWRITE_NONE', 0);
+
+/**
+ * Rewrite node SQL to filter by taxonomy for non-default domains.
+ */
+define('MULTIDOMAIN_TAXONOMY_REWRITE_NON_DEFAULT', 1);
+
+/**
+ * Rewrite node SQL to filter by taxonomy for all domains.
+ */
+define('MULTIDOMAIN_TAXONOMY_REWRITE_NON_ALL', 1);
+
+/**
  * Implementation of hook_help().
  */
 function multidomain_help($section) {
@@ -147,12 +162,12 @@
   $vid = variable_get('multidomain_vocabulary', '');
   $vocabulary = taxonomy_get_vocabulary($vid);
 
-  $form['taxonomy']['multidomain_taxonomy_primary'] = array(
+  $form['taxonomy']['multidomain_taxonomy_rewrite_sql'] = array(
     '#type' => 'radios',
-    '#title' => t('Content visibility from primary domain'),
-    '#default_value' => variable_get('multidomain_taxonomy_primary', 1),
-    '#options' => array(t('All content'), t('Only content in this domain\'s category')),
-    '#description' => t('Content may be assigned to a domain by category. Select whether you want to see content from all domains\' categories on the master domain or only content specifically assigned to the master domain.'),
+    '#title' => t('Content filtering by domain'),
+    '#default_value' => variable_get('multidomain_taxonomy_rewrite_sql', MULTIDOMAIN_TAXONOMY_REWRITE_NONE),
+    '#options' => array(MULTIDOMAIN_TAXONOMY_REWRITE_NONE => t('None: all domains see all content'), MULTIDOMAIN_TAXONOMY_REWRITE_NON_DEFAULT => t('All except default: the default domain sees all content while other domains see only their own content'), MULTIDOMAIN_TAXONOMY_REWRITE_ALL => t('All: all domains, including the default, see only their own content')),
+    '#description' => t('Content may be assigned to a domain by category. Select whether you want each domain to see only content assigned to itself.'),
   );
 
   $form['taxonomy']['multidomain_nodes'] = array(
@@ -541,23 +556,40 @@
  */
 function multidomain_db_rewrite_sql($query, $primary_table, $primary_field) {
   static $domains;
+  static $rewrite;
+  static $default;
   $return = array();
   if ($primary_field == 'nid') {
     if ($domains === NULL) {
       $domains = variable_get('multidomain_sites', array());
-      if (variable_get('multidomain_taxonomy_primary', 1)) {
-        $domains[variable_get('singlesignon_master_url', 'http://')] = array(
+      $rewrite = variable_get('multidomain_taxonomy_rewrite_sql', MULTIDOMAIN_TAXONOMY_REWRITE_NONE);
+      $default = variable_get('singlesignon_master_url', 'http://');
+      // The domains array doesn't include the default domain. Add it if needed.
+      if ($rewrite == MULTIDOMAIN_TAXONOMY_REWRITE_ALL) {
+        $domains[$default] = array(
           'tid' => variable_get('multidomain_master_domain_tid', 0),
         );
       }
     }
-    $protocol = ( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ;
-    // Determine if we are on a registered domain.
-    if ($domain = $domains[$protocol . $_SERVER['HTTP_HOST']]) {
-      if (isset($domain['tid'])) {
-        $return['join'] = 'INNER JOIN {term_node} tn ON tn.nid = '. $primary_table .'.nid';
-        $return['where'] = 'tn.tid = '. $domain['tid'];
-      }
+    $current = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'];
+    switch ($rewrite) {
+      // If we are not rewriting, simply return.
+      case MULTIDOMAIN_TAXONOMY_REWRITE_NONE:
+        return $return;
+      // If we are are rewriting all but the default, return if this is the default.
+      case MULTIDOMAIN_TAXONOMY_REWRITE_NON_DEFAULT:
+        if ($current == $default) {
+          return $return;
+        }
+        // Fall through.
+      case MULTIDOMAIN_TAXONOMY_REWRITE_ALL:
+        // Determine if we are on a registered domain.
+        if ($domain = $domains[$current]) {
+          if (isset($domain['tid'])) {
+            $return['join'] = 'INNER JOIN {term_node} tn ON tn.nid = '. $primary_table .'.nid';
+            $return['where'] = 'tn.tid = '. $domain['tid'];
+          }
+        }
     }
   }
   return $return;
