diff --git b/docroot/sites/all/modules/contrib/geoip/INSTALL.txt a/docroot/sites/all/modules/contrib/geoip/INSTALL.txt
index d7636f5..b656ea0 100644
--- b/docroot/sites/all/modules/contrib/geoip/INSTALL.txt
+++ a/docroot/sites/all/modules/contrib/geoip/INSTALL.txt
@@ -16,13 +16,13 @@ Before using this module, you will need to:
3. Create a 'sites/all/libraries/geoip' directory.
-4. Move the uncompressed database to the 'sites/all/libraries/geoip' directory.
+4. Move the uncompressed database to the 'sites/all/libraries/geoip' directory.
5. Profit!
Updates
--------------------
-Both of the Lite databases are updated monthly. The module will prompt
+Both of the Lite databases are updated monthly. The module will prompt
administrators to update if the timestamp on the data file is older than one
month. Simply replace the database file(s) with the latest one from the MaxMind
site.
diff --git b/docroot/sites/all/modules/contrib/geoip/geoip.admin.inc a/docroot/sites/all/modules/contrib/geoip/geoip.admin.inc
index cf7c9c6..15f46e7 100644
--- b/docroot/sites/all/modules/contrib/geoip/geoip.admin.inc
+++ a/docroot/sites/all/modules/contrib/geoip/geoip.admin.inc
@@ -1,5 +1,4 @@
country or city databases from MaxMind.com.', array('@country-url' => 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz', '@city-url' => 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz', '@home-url' => 'http://www.maxmind.com/app/ip-location')), 'warning');
+ drupal_set_message(t(
+ 'The GeoIP database file is more than a month old. Download the latest country or city databases from MaxMind.com.',
+ array(
+ '@country-url' => 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz',
+ '@city-url' => 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz', '@home-url' => 'http://www.maxmind.com/app/ip-location',
+ )),
+ 'warning');
}
}
diff --git b/docroot/sites/all/modules/contrib/geoip/geoip.info a/docroot/sites/all/modules/contrib/geoip/geoip.info
index de21039..a4a666f 100644
--- b/docroot/sites/all/modules/contrib/geoip/geoip.info
+++ a/docroot/sites/all/modules/contrib/geoip/geoip.info
@@ -1,14 +1,11 @@
name = GeoIP
-description = API for using the MaxMind GeoLite Country database
+description = API for using the MaxMind GeoLite Country / City database
core = 7.x
-files[] = geoip.admin.inc
-files[] = geoip.install
-files[] = geoip.values.inc
+
+configure = admin/config/regional/geoip
+
files[] = lib/geoip.inc
files[] = lib/geoipcity.inc
-files[] = lib/geoipregionvars.php
-files[] = geoip.tokens.inc
-files[] = geoip.rules.inc
; Information added by drupal.org packaging script on 2013-09-30
version = "7.x-1.x-dev"
diff --git b/docroot/sites/all/modules/contrib/geoip/geoip.install a/docroot/sites/all/modules/contrib/geoip/geoip.install
index eaf9d04..993e57e 100644
--- b/docroot/sites/all/modules/contrib/geoip/geoip.install
+++ a/docroot/sites/all/modules/contrib/geoip/geoip.install
@@ -1,20 +1,48 @@
$t('GeoIP Database'),
+ );
+
+ // Ensure the module file is load.
+ module_load_include('module', 'geoip');
+ $file = geoip_data_file();
+
+ if (!$file || !file_exists($file)) {
+ $requirements['geoip_database']['value'] = l($t('Missing'), 'admin/config/regional/geoip');
+ $requirements['geoip_database']['description'] = $t('The GeoIP database file is missing or not configured. Download the latest file at MaxMind.com.', array('@url' => 'http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz'));
+ $requirements['geoip_database']['severity'] = ($phase == 'runtime') ? REQUIREMENT_WARNING : REQUIREMENT_ERROR;
+ }
+ else {
+ $mtime = filemtime($file);
+ if ($mtime < strtotime('1 months ago')) {
+ $requirements['geoip_database']['value'] = $t('Out of date');
+ $requirements['geoip_database']['description'] = $t('The GeoIP database file is more than a month old. Download the latest file at MaxMind.com.', array('@url' => 'http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz'));
+ $requirements['geoip_database']['severity'] = REQUIREMENT_WARNING;
+ }
+ else {
+ $requirements['geoip_database']['value'] = $t('Installed');
+ }
}
- return t('Default path of the geoip_data_file updated.');
+
+ return $requirements;
}
diff --git b/docroot/sites/all/modules/contrib/geoip/geoip.js a/docroot/sites/all/modules/contrib/geoip/geoip.js
new file mode 100644
index 0000000..97b02d3
--- /dev/null
+++ a/docroot/sites/all/modules/contrib/geoip/geoip.js
@@ -0,0 +1,88 @@
+(function ($) {
+ Drupal.geoip = {
+ /**
+ * Make a country lookup request.
+ *
+ * @param callback
+ * Callback function which will be called when the request completes.
+ * @param param
+ * Optional, value that will be passed to the callback after the data.
+ */
+ lookupCountry: function (callback, param) {
+ // Save a request if we've got the country stored in a cookie.
+ cookie = Drupal.geoip.readCookie('geoip_country');
+ if (cookie) {
+ callback(cookie, param);
+ return;
+ }
+
+ // If there's a debug IP address in URL, pass that back to the server.
+ var url = Drupal.settings.basePath + 'geoip/json/country',
+ debug = /geoip_debug=(?:[0-9]+).(?:[0-9]+).(?:[0-9]+).(?:[0-9]+)/.exec(window.location.search);
+ if (debug !== null) {
+ url += '?'+ debug[0];
+ }
+
+ $.ajax({
+ url: url,
+ dataType: 'json',
+ success: function (country) {
+ var expires = null;
+ if (Drupal.settings.geoip.lifetime) {
+ expires = new Date();
+ expires.setDate(expires.getDate() + Drupal.settings.geoip.lifetime);
+ }
+ // Don't bother caching empty strings since they indicate a problem
+ // with the look up.
+ if (country) {
+ Drupal.geoip.createCookie('geoip_country', country, expires);
+ }
+ callback(country, param);
+ }
+ });
+ },
+
+ /**
+ * Creates a cookie.
+ *
+ * @param name
+ * Name of the cookie.
+ * @param value
+ * String value to store.
+ * @param expires
+ * Optional Date object specifying when the cookie should expire.
+ */
+ createCookie: function (name, value, expires) {
+ var cookie = name + "=" + value + "; path=" + Drupal.settings.basePath;
+ if (expires && expires instanceof Date) {
+ cookie += "; expires=" + expires.toGMTString();
+ }
+ document.cookie = cookie;
+ },
+
+ /**
+ * Reads a cookie.
+ *
+ * @param name
+ * Name of the cookie.
+ *
+ * @return
+ * The value of the cookie, or null if none was found.
+ */
+ readCookie: function (name) {
+ var nameEQ = name + '=',
+ ca = document.cookie.split(';'),
+ i, c;
+ for (i = 0; i < ca.length; i++) {
+ c = ca[i];
+ while (c.charAt(0) === ' ') {
+ c = c.substring(1,c.length);
+ }
+ if (c.indexOf(nameEQ) === 0) {
+ return c.substring(nameEQ.length, c.length);
+ }
+ }
+ return null;
+ }
+ };
+}(jQuery));
diff --git b/docroot/sites/all/modules/contrib/geoip/geoip.module a/docroot/sites/all/modules/contrib/geoip/geoip.module
index 8fba32a..6ec2538 100644
--- b/docroot/sites/all/modules/contrib/geoip/geoip.module
+++ a/docroot/sites/all/modules/contrib/geoip/geoip.module
@@ -1,17 +1,27 @@
'GeoIP',
'description' => 'Configure the path to the GeoIP database.',
'page callback' => 'drupal_get_form',
@@ -19,52 +29,49 @@ function geoip_menu() {
'access arguments' => array('administer site configuration'),
'file' => 'geoip.admin.inc',
);
-
+ $items['geoip/json/country'] = array(
+ 'page callback' => 'geoip_json_country',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
return $items;
}
/**
- * Implements hook_requirements().
- *
- * @param string $phase
- * @return array
+ * Helper function to add the GeoIP JavaScript.
*/
-function geoip_requirements($phase) {
- $requirements = array();
- // Ensure translations don't break at install time
- $t = get_t();
-
- // Test for a valid GeoIP database
- $requirements['geoip_database'] = array(
- 'title' => $t('GeoIP Database'),
- );
-
- $file = geoip_data_file();
-
- if (!$file || !file_exists($file)) {
- $requirements['geoip_database']['value'] = l(t('Missing'), 'admin/settings/geoip');
- $requirements['geoip_database']['description'] = $t('The GeoIP database file is missing or not configured. Download the latest file at MaxMind.com.', array('@url' => 'http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz'));
- $requirements['geoip_database']['severity'] = ($phase == 'runtime') ? REQUIREMENT_WARNING : REQUIREMENT_ERROR;
+function geoip_add_js() {
+ static $geoip_json_included;
+
+ if (!$geoip_json_included) {
+ $geoip_json_included = TRUE;
+
+ // Lifetime of country cookie in days.
+ $settings = array(
+ 'lifetime' => 1,
+ );
+ drupal_add_js(array('geoip' => $settings), 'setting');
+ drupal_add_js(drupal_get_path('module', 'geoip') . '/geoip.js');
}
- else {
- $mtime = filemtime($file);
- if ($mtime < strtotime('1 months ago')) {
- $requirements['geoip_database']['value'] = $t('Out of date');
- $requirements['geoip_database']['description'] = $t('The GeoIP database file is more than a month old. Download the latest file at MaxMind.com.', array('@url' => 'http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz'));
- $requirements['geoip_database']['severity'] = REQUIREMENT_WARNING;
- }
- else {
- $requirements['geoip_database']['value'] = $t('Installed');
- }
- }
-
- return $requirements;
}
/**
- * Helper function to get the current ip address
+ * Callback handler that returns JSON data of the country.
+ */
+function geoip_json_country() {
+ // Cast it to a string so that NULLs (which are the result of some lookup
+ // failures, like being on a private IP address) will become empty strings.
+ // A NULL would result in an empty JSON response, {}, which would prevent the
+ // AJAX success callback from firing.
+ drupal_json((string) geoip_country_code());
+ exit();
+}
+
+/**
+ * Helper function to get the current ip address.
*
* @return string
+ * The ip address of the user.
*/
function geoip_ip_address() {
if (variable_get('geoip_debug', FALSE) && !empty($_GET['geoip_debug'])) {
@@ -86,11 +93,11 @@ function geoip_instance() {
return FALSE;
}
- // geoip.inc is common to both database types
+ // The file geoip.inc is common to both database types.
_geoip_load_lib();
$instance = geoip_open($data_file, GEOIP_STANDARD);
- // conditionally load the geoipcity include file
+ // Conditionally load the geoipcity include file.
if ($instance->databaseType == GEOIP_CITY_EDITION_REV1) {
_geoip_load_lib('geoipcity.inc');
}
@@ -99,15 +106,17 @@ function geoip_instance() {
}
/**
- * Get the file path of the geoip module. This is a wrapper around
- * drupal_get_path() that falls back to simply using the directory of the
- * module file if too early in the bootstrap.
+ * Get the file path of the geoip module.
+ *
+ * This is a wrapper around drupal_get_path() that falls back to simply using
+ * the directory of the module file if too early in the bootstrap.
*
* @return string
+ * The path to the geoip module.
*/
function geoip_get_path() {
if (function_exists('drupal_get_path')) {
- // Let drupal set the path
+ // Let drupal set the path.
$path = drupal_get_path('module', 'geoip');
}
else {
@@ -122,6 +131,7 @@ function geoip_get_path() {
* Return the path of the GeoIP.dat data file.
*
* @return string
+ * The MaxMind data file.
*/
function geoip_data_file() {
return variable_get('geoip_data_file', 'sites/all/libraries/geoip/GeoIP.dat');
@@ -130,7 +140,7 @@ function geoip_data_file() {
/**
* Include the external geoip libraries.
*
- * @param $file
+ * @param string $file
* The file to be included. Must reside in the lib sub-directory.
*/
function _geoip_load_lib($file = 'geoip.inc') {
@@ -151,12 +161,13 @@ function _geoip_load_lib($file = 'geoip.inc') {
*/
/**
- * API function to return the country code for a given IP. Defaults to using the
- * current user's IP if not specified. This function works with both the country
- * and city level databases.
+ * API function to return the country code for a given IP.
+ *
+ * Defaults to using the current user's IP if not specified. This function works
+ * with both the country and city level databases.
*
* @return string
- * Country Code
+ * Country Code
*/
function geoip_country_code($ip = NULL) {
$ip = $ip ? $ip : geoip_ip_address();
@@ -178,9 +189,16 @@ function geoip_country_code($ip = NULL) {
}
/**
- * API function to return the city data for a given IP. Defaults to using the
- * current user's IP if not specified. This function only works with the city
- * level database and will return false in all other cases.
+ * API function to return the city data for a given IP.
+ *
+ * Defaults to using the current user's IP if not specified. This function only
+ * works with the city level database and will return FALSE in all other cases.
+ *
+ * @param string $ip
+ * Optional, string specifying an IP address.
+ *
+ * @return string|FALSE
+ * City name or FALSE on errors.
*/
function geoip_city($ip = NULL) {
$ip = $ip ? $ip : geoip_ip_address();
@@ -208,19 +226,26 @@ function geoip_city($ip = NULL) {
}
/**
- * API function to retrieve the region name, given a country code and region
- * code. This function relies on the geoipregionvars.php file, which is just a
+ * API function to retrieve the region name.
+ *
+ * This function relies on the geoipregionvars.php file, which is just a
* huge array.
*
+ * @param string $country_code
+ * The country code of the country to lookup in.
+ * @param string $region_code
+ * The region code to look for.
+ *
* @return string
+ * The region name.
*/
function geoip_region_name($country_code, $region_code) {
- static $GEOIP_REGION_NAME;
- if (!isset($GEOIP_REGION_NAME)) {
+ static $geoip_region_name;
+ if (!isset($geoip_region_name)) {
include drupal_get_path('module', 'geoip') . '/lib/geoipregionvars.php';
}
- return $GEOIP_REGION_NAME[$country_code][$region_code];
+ return $geoip_region_name[$country_code][$region_code];
}
/**
@@ -229,7 +254,8 @@ function geoip_region_name($country_code, $region_code) {
* Returns codes as specified by http://www.maxmind.com/app/iso3166
*
* @return array
- * Associative array with the country code as key, and the country name as value.
+ * Associative array with the country code as key, and the country name as
+ * value.
*/
function geoip_country_values() {
static $countries = NULL;
@@ -241,5 +267,30 @@ function geoip_country_values() {
}
/**
+ * Implements hook_entity_property_info_alter().
+ */
+function geoip_entity_property_info_alter(&$info) {
+ // Add the current user's currency to the site information.
+ $info['site']['properties']['geoip_country_code'] = array(
+ 'label' => t("User's country code"),
+ 'description' => t('Country code detected by ip.'),
+ 'getter callback' => 'geoip_get_properties',
+ 'type' => 'text',
+ );
+}
+
+/**
+ * Entity metadata callback: returns the current user's currency.
+ *
+ * @see commerce_multicurrency_entity_property_info_alter()
+ */
+function geoip_get_properties($data, array $options, $name) {
+ switch ($name) {
+ case 'geoip_country_code':
+ return geoip_country_code();
+ }
+}
+
+/**
* @} End of "defgroup geoip".
*/
diff --git b/docroot/sites/all/modules/contrib/geoip/geoip.rules.inc a/docroot/sites/all/modules/contrib/geoip/geoip.rules.inc
new file mode 100644
index 0000000..5a4f9a6
--- /dev/null
+++ a/docroot/sites/all/modules/contrib/geoip/geoip.rules.inc
@@ -0,0 +1,44 @@
+ array(
+ 'label' => t('Check for user country detected by ip'),
+ 'base' => 'geoip_rules_condition_country_compare',
+ 'parameter' => array(
+ 'Countries' => array(
+ 'label' => t('Country'),
+ 'type' => 'list
This page provides an overview of your site's IP detection and language negotiation settings. You may configure which language is chosen when each country is detected from the user's IP, using the form below. All detectable languages are listed in the Detected country drop-down list, and all installed languages are listed in t the Language drop-down list. If a country is detected but doesn't have an entry in this list, the default language will be used.
"); return $help; } } /** - * Implements hook_init(). - */ -function geoip_language_init() { - $drush = (function_exists('drush_verify_cli') && drush_verify_cli()); - global $base_path; - // Abort the redirect if bootstrap happened outside of index.php or if the - // requested path is inside the files directory - $count = drupal_multilingual(); - $files_dir = variable_get('file_public_path', conf_path() . '/files'); - if ($drush - || !$count - || ($_SERVER['SCRIPT_NAME'] != $base_path . 'index.php') - || (strpos($_GET['q'], $files_dir) === 0) - || (strpos($_GET['q'], 'batch') === 0) - || (strpos($_GET['q'], 'devel/') === 0) - || ($_SERVER['REQUEST_METHOD'] == 'POST')) { - return; - } - global $language; - $args = explode('/', request_uri()); - if (!in_array($language->prefix, $args)) { - //global $base_path; - - // no language prefix, then redirect. - $prefix = $language->prefix; - header('Location: ' . $base_path . $prefix . '/' . drupal_get_path_alias($_GET['q'], $language->language)); - exit(); - } -} - -/** * Implements hook_menu(). - * - * @return array */ function geoip_language_menu() { $items = array(); - $items['admin/config/regional/language/geoip'] = array( - 'title' => 'GeoIP', + $items['admin/config/regional/language/configure/geoip'] = array( 'type' => MENU_LOCAL_TASK, - 'weight' => 5, + 'title' => 'Geoip Language configuration', 'page callback' => 'geoip_language_settings_overview', - 'access arguments' => array('administer languages'), + 'access arguments' => array('configure geoip'), 'file' => 'geoip_language.admin.inc', ); - $items['admin/config/regional/language/geoip/delete/%'] = array( + $items['admin/config/regional/language/configure/geoip/delete'] = array( 'title' => 'Delete GeoIP mapping', 'page callback' => 'drupal_get_form', - 'page arguments' => array('geoip_admin_delete_mapping', 6), - 'access arguments' => array('administer languages'), + 'page arguments' => array('geoip_admin_delete_mapping'), + 'access arguments' => array('configure geoip'), 'type' => MENU_CALLBACK, 'file' => 'geoip_language.admin.inc', ); @@ -85,138 +50,71 @@ function geoip_language_menu() { } /** + * Implements hook_permission(). + */ +function geoip_language_permission() { + return array( + 'configure geoip' => array( + 'title' => t('Administer geoip'), + ), + ); +} + +/** * Implements hook_language_negotiation_info(). */ function geoip_language_language_negotiation_info() { return array( - 'geoip_language' => array( + GEOIP_LANGUAGE_NEGOTIATION_PATH => array( 'callbacks' => array( - 'language' => 'geoip_language_negotiation', - 'switcher' => 'geoip_language_language_switcher', - 'url_rewrite' => 'geoip_language_language_rewrite', + 'language' => 'geoip_language_language_provider_callback', ), 'file' => drupal_get_path('module', 'geoip_language') . '/geoip_language.module', - 'weight' => -5, - 'name' => t('Geoip'), - 'description' => t('Path prefix with geoip detection fallback'), - 'config' => 'admin/config/regional/language/geoip', + 'weight' => -4, + 'name' => t('Geoip Language'), + 'config' => 'admin/config/regional/language/configure/geoip', + 'description' => t('Uses Geoip to determine the users language.'), 'cache' => 0, ), ); } /** - * Determine the appropriate language based on path prefix, with fallbacks for - * user preferred language and GeoIP mapped language. - */ -function geoip_language_negotiation($languages) { - // Mostly copied from language_initialize(). Do a basic path prefix lookup to - // determine the language. - list($language, $_GET['q']) = language_url_split_prefix(isset($_GET['q']) ? $_GET['q'] : NULL, $languages); - if ($language !== FALSE) { - $language_url = $language->language; - include_once DRUPAL_ROOT . '/includes/path.inc'; - drupal_path_initialize(); - if (isset($_SESSION) && count($_SESSION)) { - $_SESSION['geoip_language'] = $language->language; - } - return $language_url; - } - - // Begin fallbacks. At this point, we know that there is not a valid path - // prefix, so we must first determine a language, and then do a redirect to - // the current path, in that language - global $user; - // First check to see if a language was previously determined. - if (isset($_SESSION['geoip_language']) && isset($languages[$_SESSION['geoip_language']])) { - $language = $languages[$_SESSION['geoip_language']]; - $language_url = $language->language; - } - // Fallback for user-preferred language. - elseif ($user->uid && isset($languages[$user->language])) { - $language = $languages[$user->language]; - $language_url = $language->language; - } - // If all else fails, do a GeoIP lookup and redirect. - else { - $language = geoip_language_detect_language(); - $language_url = $language->language; - } - - // Set the global language object. - $GLOBALS['language'] = $language; - if (isset($_SESSION) && count($_SESSION)) { - $_SESSION['geoip_language'] = $language->language; - } - - include_once DRUPAL_ROOT . '/includes/path.inc'; - drupal_path_initialize(); - - return $language_url; -} - -/** - * Return the cookie language switcher block. + * Determine the site language. */ -function geoip_language_language_switcher($type, $path) { - $languages = language_list('enabled'); - $links = array(); - - foreach ($languages[1] as $language) { - $links[$language->language] = array( - 'href' => $path, - 'title' => $language->native, - 'language' => $language, - 'attributes' => array('class' => array('language-link')), - ); - } - - return $links; +function geoip_language_language_provider_callback() { + // At this point in the bootstrap we don't have access to many functions, so + // this: module_load_include('module', 'geoip', 'geoip') + // won't work because drupal_get_path has not been loaded. + require_once dirname(__FILE__) . '/../geoip.module'; + + // Get the language. + return geoip_language_language_map(geoip_country_code(geoip_ip_address())); } /** - * Rewrite URLs for the geoip language provider. + * Resolve the country to a BCP47 language code. */ -function geoip_language_language_rewrite(&$path, &$options) { - if (!isset($languages)) { - $languages = language_list('enabled'); - $languages = array_flip(array_keys($languages[1])); - } +function geoip_language_language_map($country) { + $mapping = geoip_language_mappings(); - // Language can be passed as an option, or we go for current URL language. - if (!isset($options['language'])) { - global $language; - $options['language'] = $language; - } - // We allow only enabled languages here. - elseif (!isset($languages[$options['language']->language])) { - unset($options['language']); - return; + // Pick the language. + $language = NULL; + if (isset($mapping[$country])) { + $language = $mapping[$country]; } - if (isset($options['language'])) { - switch (variable_get('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX)) { - case LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX: - if (!empty($options['language']->prefix)) { - $options['prefix'] = $options['language']->prefix . '/'; - } - break; - } - } + return $language; } /** * API function to create a new mapping. - * - * @return array */ function geoip_language_mapping_create($country, $language) { $data = array( - 'country' => $country, - 'language' => $language, + $country => $language, ); - drupal_write_record('geoip_language', $data); - geoip_language_mappings(TRUE); + variable_set('geoip_language_map', array_merge(variable_get('geoip_language_map', array()), $data)); $countries = geoip_country_values(); watchdog('geoip_language', 'GeoIP mapping created for %country', array('%country' => $countries[$country])); @@ -226,15 +124,11 @@ function geoip_language_mapping_create($country, $language) { /** * API function to delete a mapping. - * - * @return boolean */ function geoip_language_mapping_delete($country) { - $deleted = db_delete('geoip_language') - ->condition('country', $country) - ->execute(); - //db_query("DELETE FROM {geoip_language} WHERE country = :country", array(':country' => $country[0])); - geoip_language_mappings(TRUE); + $data = variable_get('geoip_language_map', array()); + unset($data[$country]); + variable_set('geoip_language_map', $data); $countries = geoip_country_values(); watchdog('geoip_language', 'GeoIP mapping deleted for %country', array('%country' => $countries[$country])); @@ -242,97 +136,7 @@ function geoip_language_mapping_delete($country) { /** * API function to return the country-language mapping. - * - * TODO: Serializing to a text file is insane. This should go into the cache - * table instead. - * - * @return array - * Associative array key=countrycode, value= Language as ISO 639-1 Code */ function geoip_language_mappings($reset = FALSE) { - static $mapping = NULL; - - if ($reset || !isset($mapping)) { - $file = variable_get('file_directory_path', conf_path() .'/files') .'/geoip_language.txt'; - if (file_exists($file)) { - $data = unserialize(file_get_contents($file)); - if (isset($data['geoip'])) { - foreach ($data['geoip'] as $value) { - $mapping[$value->country] = $value->language; - } - } - } - // Build the mapping array and cache it to the filesystem. - if ($reset || !$mapping) { - $mapping = array(); - $data = array( - 'geoip' => array(), - 'default' => language_default('prefix'), - ); - - $query = db_select('geoip_language', 'g'); - $query->join('languages', 'l', 'g.language = l.language'); - $result = $query - ->fields('g', array('country', 'language')) - ->fields('l', array('prefix')) - ->orderBy('country', 'ASC') - ->execute(); - - while ($row = $result->fetchObject()) { - $mapping[$row->country] = $row->language; - $data['geoip'][$row->country] = $row; - } - - // Add default - $file = file_save_data(serialize($data), 'public://geoip_language.txt', FILE_EXISTS_REPLACE); - } - } - - return $mapping; -} - -/** - * Return the language object mapped to the current GeoIP detected country. - * - * @return string - * Language as ISO 639-1 Code - * @link http://de.wikipedia.org/wiki/ISO_639#ISO_639-1 @endlink - */ -function geoip_language_detect_language($reset = FALSE) { - drupal_load('module', 'geoip'); - static $geoip_language = NULL; - - if ($reset || !isset($geoip_language)) { - // Get a list of enabled languages. - $languages = language_list('enabled'); - $languages = $languages[1]; - // Get a list of country->language mappings. - $mappings = geoip_language_mappings(); - // GeoIP detect the current country. - $country_code = geoip_country_code(); - - // Make sure country_code, the mapping for that country_code, and the enabled - // language for that mapping, all exist. - if ($country_code && isset($mappings[$country_code]) && $languages[$mappings[$country_code]]) { - $geoip_language = $languages[$mappings[$country_code]]; - } - else { - $geoip_language = language_default(); - } - } - - return $geoip_language; -} - -/** - * Implements hook_flush_caches(). - * - * @return array - * Return an empty array - we do the flush ourselfes - */ -function geoip_language_flush_caches() { - // Reload the geoip cache file. - geoip_language_mappings(TRUE); - - return array(); + return variable_get('geoip_language_map', array()); } diff --git b/docroot/sites/all/modules/contrib/geoip/geoip_language/geoip_language.test a/docroot/sites/all/modules/contrib/geoip/geoip_language/geoip_language.test index 66321b3..1e983df 100644 --- b/docroot/sites/all/modules/contrib/geoip/geoip_language/geoip_language.test +++ a/docroot/sites/all/modules/contrib/geoip/geoip_language/geoip_language.test @@ -5,11 +5,11 @@ * Test suite for geoip_language.module */ -class geoipLanguageTestCase extends DrupalWebTestCase { +class GeoipLanguageTestCase extends DrupalWebTestCase { /** - * Implements getInfo(). + * Implementation of getInfo(). */ - function getInfo() { + public static function getInfo() { return array( 'name' => t('GeoIP Language'), 'description' => t('Test suite for the geoip_language module.'), @@ -18,17 +18,22 @@ class geoipLanguageTestCase extends DrupalWebTestCase { } /** - * Implements setUp(). + * Implementation of setUp(). */ - function setUp() { + public function setUp() { parent::setUp('locale', 'geoip', 'geoip_language'); - $this->admin_user = $this->drupalCreateUser(array('administer languages', 'administer site configuration', 'access administration pages')); + $this->admin_user = $this->drupalCreateUser(array( + 'administer languages', + 'administer site configuration', + 'access administration pages', + 'configure geoip', + )); $this->visitor = $this->drupalCreateUser(array('access content')); $this->drupalLogin($this->admin_user); // Make sure default language has a prefix. - $this->drupalPost('admin/settings/language/edit/en', array('prefix' => 'global'), t('Save language')); + $this->drupalPost('admin/config/regional/language/edit/en', array('prefix' => 'global'), t('Save language')); // Add and map french/france $this->addLanguage('fr'); geoip_language_mapping_create('FR', 'fr'); @@ -36,7 +41,7 @@ class geoipLanguageTestCase extends DrupalWebTestCase { $this->addLanguage('de'); geoip_language_mapping_create('DE', 'de'); - // reset language in the testing thread so url's get formatted properly. + // Reset language in the testing thread so url's get formatted properly. $GLOBALS['language'] = language_default(); variable_set('geoip_debug', TRUE); @@ -49,17 +54,19 @@ class geoipLanguageTestCase extends DrupalWebTestCase { * @param string $language_code * The language code to enable. */ - function addLanguage($language_code) { + public function addLanguage($language_code) { // Check to make sure that language has not already been installed. - $this->drupalGet('admin/settings/language'); + $this->drupalGet('admin/config/regional/language/'); if (strpos($this->drupalGetContent(), 'enabled[' . $language_code . ']') === FALSE) { // Doesn't have language installed so add it. $edit = array(); $edit['langcode'] = $language_code; - $this->drupalPost('admin/settings/language/add', $edit, t('Add language')); + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); - $languages = language_list('language', TRUE); // Make sure not using cached version. + // Make sure not using cached version. + drupal_static_reset('language_list'); + $languages = language_list(); $this->assertTrue(array_key_exists($language_code, $languages), t('%language language was installed successfully.', array('%language' => $languages[$language_code]->name))); if (array_key_exists($language_code, $languages)) { @@ -74,30 +81,43 @@ class geoipLanguageTestCase extends DrupalWebTestCase { } } - function dsm($object) { - $this->error(''.check_plain(print_r($object,1)).''); + /** + * Debugging helper. + * + * @param mixed $object + * Whatever shall be displayed. + */ + public function dsm($object) { + $this->error('
' . check_plain(print_r($object, 1)) . ''); } - function testMappingCrud() { + /** + * Test if the mapping configuration works properly. + */ + public function testMappingCrud() { $mappings = geoip_language_mappings(TRUE); $this->assertFalse(array_key_exists('US', $mappings), t('No mapping for US')); - $this->drupalPost('admin/settings/language/geoip', array('country' => 'US', 'language' => 'en'), t('Add mapping'), array('language' => $GLOBALS['language'])); + $this->drupalPost('admin/config/regional/language/configure/geoip', array('country' => 'US', 'language' => 'en'), t('Add mapping'), array('language' => $GLOBALS['language'])); $mappings = geoip_language_mappings(TRUE); $this->assertEqual($mappings['US'], 'en', t('Mapping created for US => en')); - $this->drupalPost('admin/settings/language/geoip/delete/US', array(), t('Delete')); + $this->drupalPost('admin/config/regional/language/configure/geoip/delete/US', array(), t('Delete')); $mappings = geoip_language_mappings(TRUE); $this->assertFalse(array_key_exists('US', $mappings), t('US mapping deleted.')); } - function testDefaultLanguageNegotiation() { + /** + * Test if the language negotiation handles ips as expected. + */ + public function testDefaultLanguageNegotiation() { global $base_url, $base_path; - $languages = language_list('language', TRUE); + drupal_static_reset('language_list'); + $languages = language_list(); // US ip address, should map to en language and force a redirect. Not using // url() or any of its derivatives, so as not to taint this url. - $this->drupalGet($base_url . $base_path .'node?geoip_debug=140.211.166.6'); + $this->drupalGet($base_url . $base_path . 'node?geoip_debug=140.211.166.6'); $url = url('node', array('absolute' => TRUE, 'language' => $languages['en'])); $this->assertEqual($this->getUrl(), $url, t('Redirect to default language (%url).', array('%url' => $this->getUrl()))); @@ -108,7 +128,7 @@ class geoipLanguageTestCase extends DrupalWebTestCase { // Now french should be in the session. Browsing directly to a page without // a prefix should redirect me to the french version. - $this->drupalGet($base_url . $base_path .'node'); + $this->drupalGet($base_url . $base_path . 'node'); $url = url('node', array('absolute' => TRUE, 'language' => $languages['fr'])); $this->assertEqual($this->getUrl(), $url, t('Redirect to the language stored in the session (%url).', array('%url' => $this->getUrl()))); @@ -119,13 +139,17 @@ class geoipLanguageTestCase extends DrupalWebTestCase { $this->assertEqual($this->getUrl(), $url, t('No redirect for default language prefix (%url).', array('%url' => $this->getUrl()))); } - function testFrenchLanguageNegotiation() { + /** + * Test if the language negotiation handles ips as expected. + */ + public function testFrenchLanguageNegotiation() { global $base_url, $base_path; - $languages = language_list('language', TRUE); + drupal_static_reset('language_list'); + $languages = language_list(); // FR ip address, should map to fr language and force a redirect. Not using // url() or any of its derivatives, so as not to taint this url. - $this->drupalGet($base_url . $base_path .'node?geoip_debug=81.255.22.101'); + $this->drupalGet($base_url . $base_path . 'node?geoip_debug=81.255.22.101'); $url = url('node', array('absolute' => TRUE, 'language' => $languages['fr'])); $this->assertEqual($this->getUrl(), $url, t('Redirect to french path (%url).', array('%url' => $this->getUrl()))); } diff --git b/docroot/sites/all/modules/contrib/geoip/interdiff.txt a/docroot/sites/all/modules/contrib/geoip/interdiff.txt deleted file mode 100644 index f941bf0..0000000 --- b/docroot/sites/all/modules/contrib/geoip/interdiff.txt +++ /dev/null @@ -1,39 +0,0 @@ -diff --git a/docroot/sites/all/modules/contrib/geoip/geoip.info b/docroot/sites/all/modules/contrib/geoip/geoip.info -index 590ce27..a4a666f 100644 ---- a/docroot/sites/all/modules/contrib/geoip/geoip.info -+++ b/docroot/sites/all/modules/contrib/geoip/geoip.info -@@ -2,7 +2,7 @@ name = GeoIP - description = API for using the MaxMind GeoLite Country / City database - core = 7.x - --configure = admin/config/system/geoip -+configure = admin/config/regional/geoip - - files[] = lib/geoip.inc - files[] = lib/geoipcity.inc -diff --git a/docroot/sites/all/modules/contrib/geoip/geoip.install b/docroot/sites/all/modules/contrib/geoip/geoip.install -index 810129b..993e57e 100644 ---- a/docroot/sites/all/modules/contrib/geoip/geoip.install -+++ b/docroot/sites/all/modules/contrib/geoip/geoip.install -@@ -28,7 +28,7 @@ function geoip_requirements($phase) { - $file = geoip_data_file(); - - if (!$file || !file_exists($file)) { -- $requirements['geoip_database']['value'] = l($t('Missing'), 'admin/config/system/geoip'); -+ $requirements['geoip_database']['value'] = l($t('Missing'), 'admin/config/regional/geoip'); - $requirements['geoip_database']['description'] = $t('The GeoIP database file is missing or not configured. Download the latest file at MaxMind.com.', array('@url' => 'http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz')); - $requirements['geoip_database']['severity'] = ($phase == 'runtime') ? REQUIREMENT_WARNING : REQUIREMENT_ERROR; - } -diff --git a/docroot/sites/all/modules/contrib/geoip/geoip.module b/docroot/sites/all/modules/contrib/geoip/geoip.module -index ad9b6a2..6ec2538 100644 ---- a/docroot/sites/all/modules/contrib/geoip/geoip.module -+++ b/docroot/sites/all/modules/contrib/geoip/geoip.module -@@ -21,7 +21,7 @@ function geoip_init() { - * Menu items. - */ - function geoip_menu() { -- $items['admin/config/system/geoip'] = array( -+ $items['admin/config/regional/geoip'] = array( - 'title' => 'GeoIP', - 'description' => 'Configure the path to the GeoIP database.', - 'page callback' => 'drupal_get_form', diff --git b/docroot/sites/all/modules/contrib/geoip/lib/geoipcity.inc a/docroot/sites/all/modules/contrib/geoip/lib/geoipcity.inc index 08efe52..84ff925 100644 --- b/docroot/sites/all/modules/contrib/geoip/lib/geoipcity.inc +++ a/docroot/sites/all/modules/contrib/geoip/lib/geoipcity.inc @@ -67,9 +67,9 @@ class geoipdnsrecord { function getrecordwithdnsservice($str){ $record = new geoipdnsrecord; - $keyvalue = split(";",$str); + $keyvalue = explode(";",$str); foreach ($keyvalue as $keyvalue2){ - list($key,$value) = split("=",$keyvalue2); + list($key,$value) = explode("=",$keyvalue2); if ($key == "co"){ $record->country_code = $value; } @@ -120,14 +120,14 @@ function _get_record($gi,$ipnum){ if ($seek_country == $gi->databaseSegments) { return NULL; } - + // workaround php's broken substr, strpos, etc handling with // mbstring.func_overload and mbstring.internal_encoding $enc = mb_internal_encoding(); - mb_internal_encoding('ISO-8859-1'); + mb_internal_encoding('ISO-8859-1'); $record_pointer = $seek_country + (2 * $gi->record_length - 1) * $gi->databaseSegments; - + if ($gi->flags & GEOIP_MEMORY_CACHE) { $record_buf = substr($gi->memory_buffer,$record_pointer,FULL_RECORD_LENGTH); } elseif ($gi->flags & GEOIP_SHARED_MEMORY){