--- og_user_roles.module.5.x-3.1.orig	2008-05-11 11:41:52.000000000 -0700
+++ og_user_roles.module	2008-05-13 14:23:50.000000000 -0700
@@ -1,5 +1,5 @@
 <?php
-// $Id: og_user_roles.module,v 1.1.2.14 2008/05/11 04:27:55 somebodysysop Exp $
+// $Id: og_user_roles.module,v 1.1.2.3 2007/07/08 19:50:44 somebodysysop Exp $
 
 /**
  * @file
@@ -380,8 +380,7 @@ function og_user_roles_multinode($theme 
     $form[$realm]['realm'] = array('#type' => 'textfield', '#size' => 25, '#disabled' => TRUE, '#value' => check_plain($realm), '#default_value' => $realm); 
     $form[$realm]['group'] = array('#type' => 'textfield', '#size' => 5, '#default_value' => (isset($existing[$realm]->groupname) ? $existing[$realm]->groupname : '') ); 
     $form[$realm]['logic'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->logic) ? $existing[$realm]->logic : 'AND'), '#options' => array('AND' => 'AND', 'OR' => 'OR') ); 
-//    $form[$realm]['weight'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->weight) ? $existing[$realm]->weight : 'A'), '#options' => array('A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E', 'F' => 'F', 'G' => 'G') ); 
-    $form[$realm]['weight'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->weight) ? $existing[$realm]->weight : '0'), '#options' => array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6') ); 
+    $form[$realm]['weight'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->weight) ? $existing[$realm]->weight : '0'), '#options' => array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9') ); 
     $form[$realm]['check'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->checkstatus) ? $existing[$realm]->checkstatus : '0'), '#options' => array('0' => '0', '1' => '1') ); 
   }
 
@@ -992,6 +991,33 @@ function og_user_roles_init() {
 	 */
     $exempted = array('ad','minutes');
 
+    $orig_query = $_SERVER['QUERY_STRING'];
+	// Get rid of Create Content 'node/add?gids[]'
+      $pattern = '/q\=.*node\/add\&gids\[\]\=(\d+)/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of Create Content 'node/ognodeadd&gids[]'
+      $pattern = '/q\=.*node\/ognodeadd\&gids\[\]\=(\d+)/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of Create Content 'node/ognodeadd&type='
+      $pattern = '/q\=.*node\/ognodeadd\&type\=(\w+)/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of 'node/add followed by &'
+      $pattern = '/q\=.*node\/add\/[^\&]+\&/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of 'node/add followed which ends the line'
+      $pattern = '/q\=.*node\/add\/[^\&]+$/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of 'gids[]='
+      $pattern = '/.*gids\[\]\=(\d+)[\&]?/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of 'node/ognodeadd'
+      $pattern = '/q\=.*node\/ognodeadd/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+	// Get rid of '&' if it starts a line
+      $pattern = '/^\&/i';
+      $orig_query = preg_replace($pattern, "", $orig_query);
+    drupal_set_message($orig_query);
+
     // If this is a group node/add, re-direct to ognodeadd
     if (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids']) && (!in_array(arg(2), $exempted)) ) {
       
@@ -1029,6 +1055,7 @@ function og_user_roles_init() {
         $path .= '/book/parent/'. arg(4);
       }
 
+      if ($orig_query) $query = $query . '&' . $orig_query;
       drupal_goto($path, $query);
     }
 
@@ -1043,6 +1070,7 @@ function og_user_roles_init() {
       if (!empty($gid) && $gid != 0) { 
         $path = 'node/ognodeadd';
         $query = 'type='. $type .'&gids[]='. $gid .'&tid='. $tid;
+        if ($orig_query) $query = $query . '&' . $orig_query;
         drupal_goto($path, $query);
       }
     }
@@ -1087,6 +1115,7 @@ function og_user_roles_init() {
           $path .= '/book/parent/'. arg(4);
         }
 
+        if ($orig_query) $query = $query . '&' . $orig_query;
         drupal_goto($path, $query);
       }
     }
@@ -1271,6 +1300,7 @@ function og_user_roles_init() {
       if (module_exists('book') && $type == 'book' && arg(3) == 'parent' && is_numeric(arg(4))) {
         $path .= '/book/parent/'. arg(4);
       }
+       if ($orig_query) $query = $query . '&' . $orig_query;
        drupal_goto($path, $query);
     }
   }
@@ -2733,6 +2763,7 @@ function og_user_roles_form_alter($form_
       '#description' => t('If you received a group registration code, enter it here.'),
     );
   }
+  $roles = array();
   // If this is a group node edit (use og_last to determine if this is a group node) and
   // the user has the 'configure member roles' permission, and we allow group admins
   // to set default group roles, then print the 'basicgrouprole' form on the
@@ -2813,6 +2844,27 @@ function og_user_roles_form_alter($form_
           $form['#validate'] += array('og_user_roles_logo_form_validate' => array($form_id, &$form));          
           $form['#submit'] += array('og_user_roles_logo_form_submit' => array($form_id, &$form));          
 
+        // Add the code to display 'Create content' link and/or remove 'create_' links.
+
+          $form['og_user_roles_links_gid'] = array(
+            '#type' => 'fieldset',
+            '#title' => t('Control group menu content links.'),
+            '#collapsible' => TRUE,
+            );
+          $form['og_user_roles_links_gid']['og_user_roles_links_content_' . $gid] = array(
+            '#type' => 'checkbox',
+            '#title' => t('Display the <strong>Create content</strong> link?'),
+            '#default_value' => variable_get('og_user_roles_links_content_' . $gid, 0),
+            '#description' => t('Do you wish to display the OGR <strong>Create content</strong> link on this group\'s menu?'),
+            );
+          $form['og_user_roles_links_gid']['og_user_roles_links_remove_' . $gid] = array(
+            '#type' => 'checkbox',
+            '#title' => t('Remove the default <strong>Create</strong> links?'),
+            '#default_value' => variable_get('og_user_roles_links_remove_' . $gid, 0),
+            '#description' => t('Do you wish to remove the default OG <strong>Create</strong> content links on this group\'s menu?'),
+            );
+          $form['#submit'] += array('og_user_roles_links_form_submit' => array($form_id, &$form));          
+
         // Add the code to disallow public posts to the
         // group edit form.
 
@@ -2863,19 +2915,22 @@ function og_user_roles_form_alter($form_
               <p><strong>Code1,Code2,Code3<br /></strong></p>
               <p>Each registration code separated by a comma. No spaces.'),
             );
-          $form['og_user_roles_regcode_gid']['og_user_roles_assign_regcoderole_' . $gid] = array(
-            '#type' => 'checkbox',
-            '#title' => t('Set default basic group (group limited) role for users who join this group using this registration code?'),
-            '#default_value' => variable_get('og_user_roles_assign_regcoderole_' . $gid, 0),
-            '#description' => t('Do you wish to automatically assign a specific "registration code group role" to new subscribers to this group <b>who use this registration code to subscribe</b> to this group? The role is limited to this group. This role assignment can be be removed by the groups\' admin(s)'),
-            );
-          $form['og_user_roles_regcode_gid']['og_user_roles_regcoderole_value_' . $gid] = array(
-            '#type' => 'select',
-            '#title' => t('Role to assign'),
-            '#options' => $roles,
-            '#default_value' => variable_get('og_user_roles_regcoderole_value_' . $gid, 0),
-            '#description' => t('Select the role you wish to use as the "registration code group role" for every new subscriber who subscribes to this group using one of the registration codes above.'),
-            );      
+      	  // They only see this if they can configure user roles
+          if (user_access('configure member roles')) {
+            $form['og_user_roles_regcode_gid']['og_user_roles_assign_regcoderole_' . $gid] = array(
+              '#type' => 'checkbox',
+              '#title' => t('Set default basic group (group limited) role for users who join this group using this registration code?'),
+              '#default_value' => variable_get('og_user_roles_assign_regcoderole_' . $gid, 0),
+              '#description' => t('Do you wish to automatically assign a specific "registration code group role" to new subscribers to this group <b>who use this registration code to subscribe</b> to this group? The role is limited to this group. This role assignment can be be removed by the groups\' admin(s)'),
+              );
+            $form['og_user_roles_regcode_gid']['og_user_roles_regcoderole_value_' . $gid] = array(
+              '#type' => 'select',
+              '#title' => t('Role to assign'),
+              '#options' => $roles,
+              '#default_value' => variable_get('og_user_roles_regcoderole_value_' . $gid, 0),
+              '#description' => t('Select the role you wish to use as the "registration code group role" for every new subscriber who subscribes to this group using one of the registration codes above.'),
+              );      
+          }
           $form['#validate'] += array('og_user_roles_regcode_form_validate' => array($form_id, &$form));          
           $form['#submit'] += array('og_user_roles_regcode_form_submit' => array($form_id, &$form));          
         }
@@ -2920,6 +2975,11 @@ function og_user_roles_logo_form_validat
 	}
   }
 }
+function og_user_roles_links_form_submit($form_id, $form_values) {
+  $gid = arg(1);
+  variable_set('og_user_roles_links_content_' . $gid, $form_values['og_user_roles_links_content_' . $gid]);
+  variable_set('og_user_roles_links_remove_' . $gid, $form_values['og_user_roles_links_remove_' . $gid]);
+}
 function og_user_roles_nopublic_form_submit($form_id, $form_values) {
   $gid = arg(1);
   variable_set('og_user_roles_assign_nopublic_' . $gid, $form_values['og_user_roles_assign_nopublic_' . $gid]);
@@ -3044,10 +3104,29 @@ function og_user_roles_theme() {
  * $group is an object containing the group node
  */
 function og_user_roles_og_create_links($group) {
-  $links[] = l(t('Create content'), "node/add", array('title' => t('Add new content in this group.')), "gids[]=$group->nid");
-  return $links;
+  if (variable_get('og_user_roles_links_content_' . $group->nid, 0) == 1) {
+    $links[] = l(t('Create content'), "node/add", array('title' => t('Add new content in this group.')), "gids[]=$group->nid");
+    return $links;
+  }
+}
+
+/**
+ * hook_og_link_alter
+ *
+ * Modification as per: http://drupal.org/node/2517905
+ * Optionally remove create_ links.
+ */
+function og_user_roles_og_link_alter(&$links, $group_node) {
+  if (variable_get('og_user_roles_links_remove_' . $group_node->nid, 0) == 1) {
+    foreach($links as $key => $value) {
+      if(substr($key,0,7) == 'create_') {
+        unset($links["$key"]);
+      }
+    }
+  }
 }
 
+
 /**
  * hook_block
  *
