My company would like to control whether the popup shows based on a country context, and due to our URL structure, a set of include/exclude paths will not work for us.

I would like to request adding a hook that permits users to define a callback function for determining country context, along with a means of selecting which function they prefer to use. On the admin page, this would be a select list or set of radio buttons, followed by a textbox that allows the user to enter a list of enabled countries/languages.

I will write the hook myself, and would like to request adding it as a feature for the module. That way, we do not need to maintain a "hacked" version of the module, and I figure the feature will be helpful for other developers trying to do the same.

Edited to add: We have tried using the Smart IP module, but as a rule, we want to minimize the use of external services, as we have a high-volume site.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

laboratory.mike’s picture

Issue summary: View changes
svenryen’s picture

So essentially you're looking for a way to choose which method/external module to when determining country context, plus a textarea to enter the countries.

I don't think this will go into the feature roadmap immediately.

How about if you provide a patch with the functionality that you're looking for, and then I'll have a look at it.

laboratory.mike’s picture

Absolutely; I'm working on it at the moment and plan to have the patch ready soon.

By the way, While looking at the country list, I noticed that the country array contains a NULL entry, along with the country code strings. But, in the code for checking a geoip match, there is a check for a null country code:

if (isset($popup_settings['eu_only']) && $popup_settings['eu_only']) {
    //use the geoip function if exists
    $country_code = function_exists('geoip_country_code_by_name') ? geoip_country_code_by_name(ip_address()) : '';
    if(module_exists('geoip')) {
      $country_code = geoip_country_code();
    } elseif(module_exists('smart_ip')) {
       $smart_ip_session = smart_ip_session_get('smart_ip');
       $country_code = isset($smart_ip_session['location']['country_code']) ? $smart_ip_session['location']['country_code'] : NULL;
    }
    $geoip_match = false;
    if (in_array($country_code, array(NULL, 'BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'GB', 'IE', 'EL', 'ES', 'FR', 'HR', 'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT', 'NL', 'NO', 'AT', 'PL', 'PT', 'RO', 'SI', 'SK', 'FI', 'SE', 'UK'))) {
      $geoip_match = true;
    }
    /** This is the second NULL check **/
    if ($country_code == '')
    {
      $geoip_match = true;
    }
  } else {
    $geoip_match = true;
  }

Since the patch I'm working on will allow users to potentially delete the NULL value from the country list, I think the best solution would be to not include NULL in the country list array, add it in an array_push just before checking the list, or just using the extra check that you have already placed in the code. IIRC, using == instead of === , which is what the module is doing now, is sufficient to catch a null value.

laboratory.mike’s picture

OK, here's the patch. One thing to note is the new hook, hook_cookie_compliance_country_info() . I'm using this to allow other modules to provide a callback function for providing a two-letter country code to be evaluated by the geoip check. I went ahead and created three default cases for the hook: Smart IP, GeoIP, and if neither module is enabled, a fallback that always returns a match. I believe this matches the default behavior. If you wouldlike documentation for the hook, I would be glad to provide it.

To check it out, Check the " Limit the popup display to a defined list of countries " checkbox, and a radio list will appear, displaying the options for callbacks. The "always true" fallback only shows if nothing else is available.

laboratory.mike’s picture

Status: Active » Needs review
laboratory.mike’s picture

New patch; adding some helper text re: installing Smart IP/GeoIP, and the default country list.

laboratory.mike’s picture

Sorry! One more: I found that there is some new code about cookie lifetimes, and my module didn't have that. I'm updating my module to include the missing code, so that the patch is created correctly.

svenryen’s picture

Thanks for the patch. I added it to the module. I need to code some update handler that will ensure those who had the feature enabled before still see it working after the upgrade.

laboratory.mike’s picture

Thanks, let me know if there is anything else I can do. I will be working on #2451131: Add option to add classes to popup/buttons in the meantime.

svenryen’s picture

Hi again, Mike! I'm afraid I have to take your patch out again. When I went to look at my test site, it became apparent that the file you're including on line 10 is not included in your patch. As a result, there are PHP warnings thrown (Warning: include_once(eu_cookie_compliance.country_list.inc): failed to open stream: No such file or directory in include_once() (line 10 of /Webserver/eu_cookie/drupal-7.32/sites/all/modules/eu-cookie-compliance/eu_cookie_compliance.module).)

Would you be able to resolve this and provide a patch that can be applied without any issues?

Thanks, appreciate your work.

laboratory.mike’s picture

Status: Needs review » Needs work

Sure thing. We're a little snowed under with work over at the office, but I'll aim to get this out before the week's end.

svenryen’s picture

Hi Mike! Just wondering if you have an update on the patch?

laboratory.mike’s picture

Here's the new patch, along with the country list include file. I'm not sure why, but when I create a patch, it isn't included. Maybe because it's a new/untracked file.

laboratory.mike’s picture

As always, right after checking it I manage to find one more typo. I didn't have a space in the str_replace statement (cleaning up stray spaces).

laboratory.mike’s picture

Status: Needs work » Needs review
svenryen’s picture

Assigned: laboratory.mike » svenryen

Hi Mike! Thanks for the updated patch. Sorry that progress has stalled. I'll be taking a look at it soon.

  • svenryen committed 4725cd3 on 7.x-1.x
    Revert "Issue #2445289 by laboratory.mike: Adding country context for...
  • svenryen committed 9084272 on 7.x-1.x authored by laboratory.mike
    Issue #2445289 by laboratory.mike: Adding country context for this...
svenryen’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

Hi @laboratory.mike, I tried applying your patch, but unfortunately it failed.

Would you be able to create a new patch?
Also, when you make a patch, please put your new settings in the "Advanced" section and make sure you patch 1.x, not 2.x.

svenryen’s picture

Status: Needs review » Needs work
svenryen’s picture

Assigned: svenryen » Unassigned
svenryen’s picture

Hi @laboratory.mike ! I'm pleased to share with you that as of 23 July, the -dev version of the module now offers
variable_get('eu_cookie_compliance_eu_countries', $eu_countries_default);

You can simply initialize your own array in settings.php with a list of countries that will see the banner.

You're still welcome to contribute a patch, and I'll add this functionality to the UI. As of now, your patch discards the 'eu_only' setting without migrating the user and that has to be resolved. Either you need to rework your logic so that you still use 'eu_only', or you need to provide an update hook where you migrate this setting to your new variables (paying attention to the locale realms that have now been introduced).

svenryen’s picture

Status: Needs work » Fixed
svenryen’s picture

Status: Fixed » Closed (fixed)
laboratory.mike’s picture

Just wanted to jump in and say its fine to close this - this ticket was prompted by work with a company I am no longer working for, and my development priorities have changed with my new job.

peezy’s picture

Thanks for your work on this module and this issue.

'in_eu' kept returning TRUE (even for random strings) using the geoip module, until I tweaked the eu_cookie_compliance_user_in_eu() function a bit.

laboratory.mike’s picture

Yes, those look like reasonable tweaks.