Index: og_forum.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_forum/Attic/og_forum.module,v
retrieving revision 1.11.2.11.2.18.2.17.2.19
diff -u -r1.11.2.11.2.18.2.17.2.19 og_forum.module
--- og_forum.module	3 Jun 2010 16:07:51 -0000	1.11.2.11.2.18.2.17.2.19
+++ og_forum.module	9 Nov 2010 13:06:41 -0000
@@ -421,40 +421,50 @@
   global $user;
 
   if ($primary_field == 'tid') { 
-	if (arg(0) == 'forum') { 
+    if (arg(0) == 'forum') {
       if (user_access('administer forums') || (!module_exists('og_access') || variable_get('forum_all_public', 0))) {  
-	    return;
-      // On forum* paths, filter terms by og_forum_is_public() and the user's
-      // group memberships via {og_term} relationships.
+        return array();
       } else {
-        $return['join'] = "LEFT JOIN {og_term} ogt ON ogt.tid = t.tid";
-        // Either the forum is unconfigured or public.
-        $return['where'] = "ogt.public IS NULL OR ogt.public > " . PRIVATE_BY_GROUP_OWNER;
-        // ...or the user is member of the group associated with the forum.
-        if (!empty($user->og_groups)) {
-          $return['where'] .= " OR ogt.nid IN (" . implode(',', array_keys($user->og_groups)) . ")";
-        }
-        return $return;
+        // Rewrite the forum access
+        return og_forum_get_sql();
       }
     }
-    if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'forum') {
-	  if (isset($_GET['gids']) && is_array($_GET['gids']) && isset($_GET['gids'][0]) && is_numeric($_GET['gids'][0])) {
-	    if (in_array($_GET['gids'][0], array_keys($user->og_groups))) {
-	      return;
+    elseif (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'forum') {
+	    if (isset($_GET['gids']) && is_array($_GET['gids']) && isset($_GET['gids'][0]) && is_numeric($_GET['gids'][0])) {
+        // if a &gids is present in the URL
+	      if (in_array($_GET['gids'][0], array_keys($user->og_groups))) {
+	        return array();
+	      }
 	    }
-	  }
-      $return['join'] = "LEFT JOIN {og_term} ogt ON t.tid = ogt.tid";
-      $return['where'] = "ogt.nid IS NULL";
-      if ($og_forum_container = variable_get('forum_default_container', FALSE)) {
-        $return['where'] .= " AND t.tid != $og_forum_container";
-      }
-      $return['distinct'] = TRUE;
-      return $return;
+      // Rewrite the forum access
+      return og_forum_get_sql();
     }
   }
 }
 
 /**
+ * Filter terms by: og_forum_is_public(), user's group subscription and group forum term {og_term}
+ */
+function og_forum_get_sql() {
+  global $user;
+  $return = array();
+  $return['distinct'] = TRUE;
+  $return['join'] = "LEFT JOIN {og_term} ogt ON ogt.tid = t.tid";
+  // Either the forum is unconfigured or public or public
+  $return['where'] = "ogt.public > " . PRIVATE_BY_GROUP_OWNER;
+  
+  if (!empty($user->og_groups)) {
+    // Add own user groups into accessible forums/TIDs
+    $return['where'] .= " OR ogt.nid IN (" . implode(',', array_keys($user->og_groups)) . ")";
+  }
+  
+  if ($og_forum_container = variable_get('forum_default_container', FALSE)) {
+    $return['where'] .= " AND t.tid != $og_forum_container";
+  }  
+  return $return;
+}
+
+/**
  * Implementation of hook_nodeapi().
  *
  * Automatically creates a forum container and forum each time an organic group is added.

