From 12ea49759dcc63bef60050622cb329e1b8f958fe Mon Sep 17 00:00:00 2001
From: Daniel Wroblewski
Date: Mon, 7 Mar 2011 13:30:35 +0100
Subject: [PATCH] Added options for inverting default behaviour to disallowing access to nodes based on current country

---
 geoip_country.module |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/geoip_country.module b/geoip_country.module
index 6645110..317df44 100644
--- a/geoip_country.module
+++ b/geoip_country.module
@@ -43,9 +43,11 @@ function geoip_country_form_alter(&$form, $form_state, $form_id) {
         '#collapsed' => FALSE,
         '#collapsible' => TRUE,
       );
+
+      $desc_part = variable_get('geoip_country_blacklist', 0) == 0 ? ' be only accessible ' : ' not be accessible ';
       $form['geoip_country']['countries'] = array(
         '#title' => t('Countries'),
-        '#description' => t('If you select one or more countries, the node will be only accessible from the selected countries. Leaving blank will allow node access from everywhere.'),
+        '#description' => t('If you select one or more countries, the node will ' . $desc_part . ' from the selected countries. Leaving blank will allow node access from everywhere.'),
         '#type' => 'select',
         '#size' => 5,
         '#multiple' => TRUE,
@@ -97,6 +99,16 @@ function geoip_country_options_form() {
   $form = array();
   $options = array();
 
+  $form['geoip_country_blacklist'] = array(
+     '#title' => t('Blacklist behaviour'),
+     '#type' => 'radios',
+     '#default_value' => variable_get('geoip_country_blacklist', 0),
+     '#options' => array(
+       t('Disabled'),
+       t('Enabled'),
+     ),
+     '#description' => t('If blacklist is enabled access to nodes is allowed from all countries except for those selected.')
+   );
 
   $form['geoip_country_content_types'] = array(
     '#title' => t('Select content types need GeoIP control'),
@@ -147,7 +159,7 @@ function geoip_country_node_access_records($node) {
     $grants[] = array(
       'realm' => 'access_'. $code,
       'gid' => 1,
-      'grant_view' => TRUE,
+      'grant_view' => variable_get('geoip_country_blacklist', 0) == 0 ? TRUE : FALSE,
       'grant_update' => FALSE,
       'grant_delete' => FALSE,
       'priority' => 0,
-- 
1.7.3.1

