Index: og_block_visibility.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og_block_visibility/og_block_visibility.module,v retrieving revision 1.13.2.2 diff -u -r1.13.2.2 og_block_visibility.module --- og_block_visibility.module 22 Jan 2009 14:15:23 -0000 1.13.2.2 +++ og_block_visibility.module 5 Nov 2010 14:05:21 -0000 @@ -54,7 +54,12 @@ return $form; } - $form['#submit'][] = 'og_block_visibility_submit'; + $form['group_vis_settings']['og_block_vis_'.$module.'_' . $delta . '_onlymember'] = array( + '#type' => 'checkbox', + '#title' => t('Show this block only to group members.'), + '#description' => t('Show this block only within the elected groups and only if the user is a member of the group.'), + '#default_value' => variable_get('og_block_vis_'.$module.'_' . $delta . '_onlymember', 0), + ); $form['group_vis_settings']['group_visibility'] = array( '#type' => 'checkbox', @@ -68,7 +73,7 @@ if ($count > 10) { $form['group_vis_settings']['groups'] = array( '#type' => 'select', - '#title' => t('Groups:'), + '#title' => t('Groups'), '#default_value' => $groups, '#options' => $options, '#multiple' => TRUE, @@ -79,12 +84,13 @@ else { $form['group_vis_settings']['groups'] = array( '#type' => 'checkboxes', - '#title' => t('Groups:'), + '#title' => t('Groups'), '#default_value' => $groups, '#options' => $options, ); } + $form['#submit'][] = 'og_block_visibility_submit'; return $form; } @@ -117,11 +123,16 @@ if (!empty($groups)) { og_block_visibility_reset_visibility($module, $delta); } - } - - // Was group visibility enabled? - // Check for is_array because $form['groups'] might be a message stating that no groups exist. - if ($form_values['group_visibility'] == 1 && is_array($form_values['groups'])) { + + variable_set('og_block_vis_'.$module.'_' . $delta . '_onlymember', $form_values['og_block_vis_'.$module.'_' . $delta . '_onlymember']); + // Add anyway the PHP code if we're dealing with only-member check! + if ($form_values['og_block_vis_'.$module.'_' . $delta . '_onlymember'] == 1) { + og_block_visibility_set_visibility($module, $delta, array()); + } + } + elseif ($form_values['group_visibility'] == 1 && is_array($form_values['groups'])) { + // Was group visibility enabled? + // Check for is_array because $form['groups'] might be a message stating that no groups exist. // Remove all unchecked elements foreach ($form_values['groups'] as $nid => $checked) { @@ -137,8 +148,7 @@ // Block visibility has changed; set block visibility og_block_visibility_set_visibility($module, $delta, $form_values['groups']); } - } - + } } /** @@ -207,18 +217,28 @@ function og_block_visibility_check($module, $delta) { // Are we in a group? if ($group = og_get_group_context()) { + global $user; + // Check if only-members can see this block + if ( variable_get('og_block_vis_'.$module.'_' . $delta . '_onlymember', 0) == 1) { + if (in_array($group->nid, array_keys($user->og_groups))) { + return TRUE; + } + else { + return FALSE; + } + } + // Does the current group have this block assigned to it? $groups = og_block_visibility_get_assignments($module, $delta); if (in_array($group->nid, $groups)) { - // Is the block public? - if ($group->og_selective <= OG_MODERATED) { - return TRUE; - } - // Is current user a member of this group? - global $user; + // Is current user a member of this group? if (in_array($group->nid, array_keys($user->og_groups))) { return TRUE; } + // Is the group public? + if ($group->og_private == 0) { + return TRUE; + } } } }