--- og_user_roles.module.5.x-2.5.orig	2007-10-15 12:24:11.000000000 -0700
+++ og_user_roles.module	2007-11-08 10:40:11.000000000 -0800
@@ -1,5 +1,5 @@
 <?php
-// $Id: og_user_roles.module,v 1.1.2.9 2007/10/11 22:53:24 somebodysysop Exp $
+// $Id: og_user_roles.module,v 1.1.2.3 2007/07/08 19:50:44 somebodysysop Exp $
 
 /**
  * @file
@@ -717,9 +717,12 @@ function views_handler_filter_group() {
   $list = array();
   $list = variable_get('og_node_types', array('og'));
 
-  $group_types = implode(',', $list);
+// Modification as per: http://drupal.org/node/184357
+//  $group_types = implode(',', $list);
+  $group_types = implode("','", $list);
   $vids = array();
-  $result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type IN ('%s') ORDER BY n.title", $group_types);
+//  $result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type IN ('%s') ORDER BY n.title", $group_types);
+  $result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type IN ('".$group_types."') ORDER BY n.title");
   while ($obj = db_fetch_object($result)) {
     $vids[$obj->nid] = $obj->title;
   }
@@ -757,8 +760,19 @@ function og_user_roles_init() {
     if (!function_exists('arg') && $user->uid > 0) {
       drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // added as per this issue: http://drupal.org/node/149469
     }
+    // Modification as per: http://drupal.org/node/183860
+    og_user_roles_theme();
+
+    /** 
+     * Modules exempted from ognodeadd:
+	 * Originally for ad module: http://drupal.org/node/183081
+	 * Added minutes module: http://drupal.org/node/184102
+	 */
+    $exempted = array('ad','minutes');
+
     // If this is a group node/add, re-direct to ognodeadd
-    if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids'])) {
+    if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids']) && (!in_array(arg(2), $exempted)) ) {
+      
       $gids = $_GET['gids'];
       $gid = intval(current($_REQUEST['gids']));
       $type = arg(2);
@@ -814,7 +828,7 @@ function og_user_roles_init() {
     // If this is a non-group node/add, but og_last session cookie is set
     // then re-direct to ognodeadd
 	// But, make sure you don't redirect for omitted nodes.
-    if (arg(0) == 'node' && arg(1) == 'add' && $_SESSION['og_last'] && (!is_null(arg(2))) ) {
+    if (arg(0) == 'node' && arg(1) == 'add' && $_SESSION['og_last'] && (!is_null(arg(2)))  && (!in_array(arg(2), $exempted)) ) {
 
       $gid = $_SESSION['og_last']->nid;
 
@@ -902,7 +916,58 @@ function og_user_roles_init() {
 		}
       }
 	}
+    // Modification for ad module: http://drupal.org/node/183081
+    // Add groupID if we are in group context.
+    if (module_exists('ad')) {
+	  if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'ad' && (arg(3) == 'image' || arg(3) == 'text') && $_SESSION['og_last'] && (!isset($_REQUEST['gids'])) ) {
+//        $gid = $_SESSION['og_last']->nid;
+//        $uri_request_id = request_uri();
+//        $this_url = parse_url($uri_request_id);
+//        $this_path = $this_url[path];
+//        $this_path = ltrim($this_path, "\/");
+//        $path = $this_path;
+
+        $gid = $_SESSION['og_last']->nid;
+        $uri_request_id = request_uri();
+        $this_url = parse_url($uri_request_id);
+        $this_path = $this_url[path];
+        $base_path_len = strlen(base_path());
+        $this_path2 = substr($this_path, $base_path_len);
+        $path = $this_path2;
+
+        $query = 'gids[]='. $gid;
+        // Only add if $gid > 0
+        if ($gid > 0) {
+          drupal_goto($path, $query);
+		}
+      }
+	}
+    // Modification for minutes module: http://drupal.org/node/184102
+    // Add groupID if we are in group context.
+    if (module_exists('minutes')) {
+	  if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'minutes' && is_numeric(arg(3)) && $_SESSION['og_last'] && (!isset($_REQUEST['gids'])) ) {
+//        $gid = $_SESSION['og_last']->nid;
+//        $uri_request_id = request_uri();
+//        $this_url = parse_url($uri_request_id);
+//        $this_path = $this_url[path];
+//        $this_path = ltrim($this_path, "\/");
+//        $path = $this_path;
+
+        $gid = $_SESSION['og_last']->nid;
+        $uri_request_id = request_uri();
+        $this_url = parse_url($uri_request_id);
+        $this_path = $this_url[path];
+        $base_path_len = strlen(base_path());
+        $this_path2 = substr($this_path, $base_path_len);
+        $path = $this_path2;
 
+        $query = 'gids[]='. $gid;
+        // Only add if $gid > 0
+        if ($gid > 0) {
+          drupal_goto($path, $query);
+		}
+      }
+	}
     // Modification user edit
     // If this is going to http://clients.brixrealtyinc.com/user/76
     // But the referrer is http://clients.brixrealtyinc.com/oguseredit/76/edit?gids[]=47
@@ -1521,7 +1586,7 @@ function og_user_roles_all_roles($user) 
     // Modification as per: http://drupal.org/node/155882 - replaced $uri_request_id
     // with arg() values.
     if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids'])) {
-      $location = 10 .'('. arg(0) .'|'. arg(1) .'|'. arg(2) .')';
+      $location = 10;
       $gids = $_GET['gids'];
       $gid = intval(current($_REQUEST['gids']));
     }
@@ -1597,7 +1662,13 @@ function og_user_roles_all_roles($user) 
     $_SESSION['og_last']->nid = $gid;
   }
 
-  $query = 'SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid WHERE ogr.uid = %d AND ogr.gid = %d';
+/*
+ * Modification as per http://drupal.org/node/189227
+ * Makes sure use is "active" (not in moderation) before any of these group roles are added.
+ * Was: $query = 'SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid WHERE ogr.uid = %d AND ogr.gid = %d';
+ */
+
+  $query = 'SELECT r.rid, r.name FROM {role} r INNER JOIN {og_users_roles} ogr ON r.rid = ogr.rid INNER JOIN {og_uid} ogu ON ogu.uid = ogr.uid AND ogu.nid = ogr.gid WHERE ogr.uid = %d AND ogr.gid = %d AND ogu.is_active = 1';
   $results = db_query($query, $uid, $gid);
 
   //
@@ -1867,7 +1938,10 @@ function og_user_roles_ognodeadd() {
     $access = module_invoke($module, 'access', 'create', $type);
 
     if ($access === TRUE) {
-      $output = node_add($type);
+    // Working on this issue: http://drupal.org/node/183096
+      $content_type = node_get_types('type', str_replace('-', '_', $type));
+      $output = '<p>'. filter_xss_admin($content_type->help) .'</p>';
+      $output .= node_add($type);
     }
     else {
       $output = 'Access denied.';
@@ -2556,4 +2630,53 @@ function og_user_roles_role_submit($form
     // Remove from og_users_roles table all rows with this rid:
     db_query('DELETE FROM {og_users_roles} WHERE rid = %d', $form_values['rid']);
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Modification as per http://drupal.org/node/183860
+ * Override theme based on what group is being displayed (if any).
+ * Be smart about selecting the 'active' group for ambigous urls like node/$nid
+ *
+ * @param
+ *   none
+ * @return
+ *   none
+ */
+function og_user_roles_theme() {
+  global $custom_theme;
+  $group_node = NULL; // a node object containing the 'active' group for this request
+
+  $type = $_GET['type'];
+
+  if (arg(0) == 'og' && is_numeric(arg(2))) {
+    $group_node = og_set_theme(arg(2));
+  }
+  elseif (arg(0) == 'node' && is_numeric(arg(1))) {
+    $group_node = og_set_theme(arg(1));
+  }
+  elseif (arg(0) == 'node' && (arg(1) == 'add' || arg(1) == 'ognodeadd') && (arg(2) == 'book' || $type == 'book') && arg(3) == 'parent') {
+    $group_node = og_set_theme(arg(4));
+    $_REQUEST['edit']['og_groups'][] = $group_node->nid; // checks the right box on node form
+  }
+  elseif (arg(0) == 'node' && (arg(1) == 'add' || arg(1) == 'ognodeadd') && isset($_REQUEST['gids'])) {
+    $gid = intval(current($_REQUEST['gids']));
+    $group_node = node_load($gid);
+    $custom_theme = $group_node->og_theme;
+  }
+  elseif (arg(0) == 'forum' && is_numeric(arg(1))) {
+    $tid = intval(arg(1));
+    $gid = og_user_roles_gid_from_tid($tid);
+    $group_node = node_load($gid);
+    $custom_theme = $group_node->og_theme;
+  }
+  elseif (arg(0) == 'og_calendar' && is_numeric(arg(1))) {
+    $gid = intval(arg(1));
+    $group_node = node_load($gid);
+    $custom_theme = $group_node->og_theme;
+  }
+  elseif (arg(0) == 'comment' && is_numeric(arg(2))) {
+    $group_node = og_set_theme(arg(2));
+  }
+
+  og_set_group_context($group_node);
+}
