Index: og_promote.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_promote/Attic/og_promote.module,v
retrieving revision 1.5.2.1
diff -u -r1.5.2.1 og_promote.module
--- og_promote.module	30 Mar 2007 16:59:54 -0000	1.5.2.1
+++ og_promote.module	21 Feb 2008 21:27:07 -0000
@@ -36,7 +36,8 @@
  * Implementation of hook_og().
  */
 function og_promote_og($op, $nid, $uid, $args = array()) {
-  if (($role_id = variable_get('og_promote_role', 0)) != 0 && in_array($nid, variable_get('og_promote_groups', NULL))) {
+  $type = _og_promote_get_node_type($nid);
+  if (($role_id = variable_get('og_promote_role', 0)) && (in_array($nid, variable_get('og_promote_groups', array()), true) || in_array($type, variable_get('og_promote_group_types', array()), true))) {
     switch ($op) {
       case 'user insert':
       case 'user update':
@@ -54,9 +55,15 @@
         break;
       case 'user delete':
         $groups = variable_get('og_promote_groups', array());
+        $group_types = variable_get('og_promote_group_types', array());
         $user_groups = array_keys(og_get_subscriptions($uid));
-        // check that the user isn't in any of the other groups.
-        if (in_array($nid, $groups) && !count(array_intersect(array_diff($groups, array(0)), array_diff($user_groups, array($nid))))) {
+        $user_groups_new = array_diff($user_groups, array($nid));
+        $user_group_types_new = array();
+        foreach ($user_groups_new as $gid) {
+          $user_group_types_new[] = _og_promote_get_node_type($gid);
+        }
+        // check that the user isn't in any of the other groups given explicitely or any of the other groups given by content type.
+        if ((in_array($nid, $groups) || in_array($type, $group_types)) && !(count(array_intersect($groups, $user_groups_new)) + count(array_intersect($group_types, $user_group_types_new)))) {
           $user = user_load(array('uid' => $uid));
           $edit = array();
           $edit['roles'] = array();
@@ -86,7 +93,7 @@
     }
   }
   if (count($role_names)) {
-    $form['og_promote_role'] = array('#type' => 'radios', '#title' => t('Roles'), '#options' => $role_names, '#default_value' => variable_get('og_promote_role', 0), '#description' => t('Choose a role that users which become members of the groups below should be promoted to. If the member gets unsubscribed, it will be removed from the role.'));
+    $form['og_promote_role'] = array('#type' => 'radios', '#title' => t('Roles'), '#options' => $role_names, '#default_value' => variable_get('og_promote_role', 0), '#description' => t('Choose a role that users will promoted to if they become member of any of the groups specified below. If the member gets unsubscribed, it will be removed from the role.'));
   }
   else {
     $form['og_promote_role'] = array('#type' => 'item', '#title' => t('No roles'), '#description' => t('You need to define some additional roles to use this module.'));
@@ -94,6 +101,18 @@
   $options = array();
   $values = array();
   $types = variable_get('og_node_types', array('og'));
+  
+  foreach ($types as $type) {
+    $options[$type] = node_get_types('name', array('type' => $type));
+  }
+  if (count($options)) {
+    $form['og_promote_group_types'] = array('#type' => 'checkboxes', '#title' => t('Group content types'), '#options' => $options, '#default_value' => variable_get('og_promote_group_types', array()), '#description' => t('The group content types that are defined for this site.'));
+  }
+  else {
+    $form['og_promote_group_types'] = array('#type' => 'item', '#title' => t('No group content types'), '#options' => $options, '#default_value' => variable_get('og_promote_group_types', array()), '#description' => t('You need to create some group content types.'));
+  }
+  
+  $options = array();
   foreach ($types as $type) {
     $result = db_query("SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type = '%s' ORDER BY n.title", $type);
     while ($group = db_fetch_object($result)) {
@@ -122,3 +141,10 @@
   }
   return system_settings_form($form);
 }
+
+/**
+ * Helper function, returns node type of given node id.
+ */
+function _og_promote_get_node_type($nid) {
+  return db_result(db_query('SELECT type FROM {node} WHERE nid = %d', $nid)); 
+}
\ No newline at end of file
