GeoIP Detection - Version 2.5.7

Version Description

  • ADD: Shortcodes can now optionally specifiy the IP: [geoip_detect2 property="country.isoCode" ip="(ipv4 or ipv6)"]
  • ADD: Plugin is now translated into German.
  • FIX: geoip_detect2_get_info_from_current_ip() now also handles the case when REMOTE_ADDR contains multiple IP adresses
Download this release

Release Info

Developer benjamin4
Plugin Icon 128x128 GeoIP Detection
Version 2.5.7
Comparing to
See all releases

Code changes from version 2.5.6 to 2.5.7

api.php CHANGED
@@ -19,8 +19,7 @@ use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
19
  * @since 2.4.0 New parameter $skipCache
20
  * @since 2.5.0 Parameter $skipCache has been renamed to $options with 'skipCache' property
21
  */
22
- function geoip_detect2_get_info_from_ip($ip, $locales = null, $options = array())
23
- {
24
  _geoip_maybe_disable_pagecache();
25
  // 1) Processing the parameters.
26
 
@@ -90,8 +89,7 @@ function geoip_detect2_get_info_from_ip($ip, $locales = null, $options = array()
90
  * @since 2.4.0 New parameter $skipCache
91
  * @since 2.5.0 Parameter $skipCache has been renamed to $options with 'skipCache' property
92
  */
93
- function geoip_detect2_get_info_from_current_ip($locales = null, $options = array())
94
- {
95
  return geoip_detect2_get_info_from_ip(geoip_detect2_get_client_ip(), $locales, $options);
96
  }
97
 
@@ -145,12 +143,14 @@ function geoip_detect2_get_current_source_description($source = null) {
145
  function geoip_detect2_get_client_ip() {
146
  _geoip_maybe_disable_pagecache();
147
 
148
- $ip = '::1';
149
 
150
  if (isset($_SERVER['REMOTE_ADDR']))
151
  $ip = $_SERVER['REMOTE_ADDR'];
152
 
153
- $ip_list = array($ip);
 
 
154
 
155
  if (get_option('geoip-detect-has_reverse_proxy', 0) && isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
156
  {
@@ -163,6 +163,7 @@ function geoip_detect2_get_client_ip() {
163
  $trusted_proxies = explode(',', $trusted_proxies);
164
 
165
  // Always trust localhost
 
166
  $trusted_proxies[] = '::1';
167
  $trusted_proxies[] = '127.0.0.1';
168
 
@@ -170,12 +171,12 @@ function geoip_detect2_get_client_ip() {
170
  $ip_list[] = $ip;
171
 
172
  $ip_list = array_diff($ip_list, $trusted_proxies);
173
- }
174
-
175
- // Each Proxy server append their information at the end, so the last IP is most trustworthy.
176
- $ip = end($ip_list);
177
- }
178
-
179
  if (!$ip)
180
  $ip = '::1'; // By default, use localhost
181
 
@@ -195,8 +196,7 @@ function geoip_detect2_get_client_ip() {
195
  * @since 2.4.3 Reading option 'external_ip' first.
196
  * @since 2.5.2 New param $unfiltered that can bypass the option.
197
  */
198
- function geoip_detect2_get_external_ip_adress($unfiltered = false)
199
- {
200
  $ip_cache = '';
201
 
202
  if (!$unfiltered)
19
  * @since 2.4.0 New parameter $skipCache
20
  * @since 2.5.0 Parameter $skipCache has been renamed to $options with 'skipCache' property
21
  */
22
+ function geoip_detect2_get_info_from_ip($ip, $locales = null, $options = array()) {
 
23
  _geoip_maybe_disable_pagecache();
24
  // 1) Processing the parameters.
25
 
89
  * @since 2.4.0 New parameter $skipCache
90
  * @since 2.5.0 Parameter $skipCache has been renamed to $options with 'skipCache' property
91
  */
92
+ function geoip_detect2_get_info_from_current_ip($locales = null, $options = array()) {
 
93
  return geoip_detect2_get_info_from_ip(geoip_detect2_get_client_ip(), $locales, $options);
94
  }
95
 
143
  function geoip_detect2_get_client_ip() {
144
  _geoip_maybe_disable_pagecache();
145
 
146
+ $ip = '';
147
 
148
  if (isset($_SERVER['REMOTE_ADDR']))
149
  $ip = $_SERVER['REMOTE_ADDR'];
150
 
151
+ // REMOTE_ADDR may contain multiple adresses? https://wordpress.org/support/topic/php-fatal-error-uncaught-exception-invalidargumentexception?replies=2#post-8128737
152
+ $ip_list = explode(',', $ip);
153
+ array_unshift($ip_list, '::1');
154
 
155
  if (get_option('geoip-detect-has_reverse_proxy', 0) && isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
156
  {
163
  $trusted_proxies = explode(',', $trusted_proxies);
164
 
165
  // Always trust localhost
166
+ $trusted_proxies[] = '';
167
  $trusted_proxies[] = '::1';
168
  $trusted_proxies[] = '127.0.0.1';
169
 
171
  $ip_list[] = $ip;
172
 
173
  $ip_list = array_diff($ip_list, $trusted_proxies);
174
+ }
175
+ }
176
+ // Each Proxy server append their information at the end, so the last IP is most trustworthy.
177
+ $ip = end($ip_list);
178
+ $ip = geoip_detect_normalize_ip($ip);
179
+
180
  if (!$ip)
181
  $ip = '::1'; // By default, use localhost
182
 
196
  * @since 2.4.3 Reading option 'external_ip' first.
197
  * @since 2.5.2 New param $unfiltered that can bypass the option.
198
  */
199
+ function geoip_detect2_get_external_ip_adress($unfiltered = false) {
 
200
  $ip_cache = '';
201
 
202
  if (!$unfiltered)
data-sources/manual.php CHANGED
@@ -50,9 +50,11 @@ class ManualDataSource extends AbstractDataSource {
50
  $current_value = '<br >' . sprintf(__('Current value: %s', 'geoip-detect'), get_option('geoip-detect-manual_file_validated'));
51
  }
52
 
 
 
53
  $html = <<<HTML
54
- <p>Filepath to mmdb-file: <input type="text" size="40" name="options_manual[manual_file]" value="$manual_file" /></p>
55
- <span class="detail-box">e.g. wp-content/uploads/GeoLite2-Country.mmdb or absolute filepath$current_value</span>
56
  <br />
57
  HTML;
58
 
50
  $current_value = '<br >' . sprintf(__('Current value: %s', 'geoip-detect'), get_option('geoip-detect-manual_file_validated'));
51
  }
52
 
53
+ $label = __('Filepath to mmdb-file:', 'geoip-detect');
54
+ $desc = __('e.g. wp-content/uploads/GeoLite2-Country.mmdb or absolute filepath', 'geoip-detect');
55
  $html = <<<HTML
56
+ <p>$label <input type="text" size="40" name="options_manual[manual_file]" value="$manual_file" /></p>
57
+ <span class="detail-box">$desc $current_value</span>
58
  <br />
59
  HTML;
60
 
geoip-detect-lib.php CHANGED
@@ -361,4 +361,4 @@ function _geoip_maybe_disable_pagecache() {
361
  }
362
 
363
  return true;
364
- }
361
  }
362
 
363
  return true;
364
+ }
geoip-detect.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.yellowtree.de
5
  Description: Retrieving Geo-Information using the Maxmind GeoIP (Lite) Database.
6
  Author: Yellow Tree (Benjamin Pick)
7
  Author URI: http://www.yellowtree.de
8
- Version: 2.5.6
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
  Text Domain: geoip-detect
@@ -16,7 +16,7 @@ Requires WP: 3.5
16
  Requires PHP: 5.3.1
17
  */
18
 
19
- define('GEOIP_DETECT_VERSION', '2.5.6');
20
 
21
  /*
22
  Copyright 2013-2015 Yellow Tree, Siegen, Germany
5
  Description: Retrieving Geo-Information using the Maxmind GeoIP (Lite) Database.
6
  Author: Yellow Tree (Benjamin Pick)
7
  Author URI: http://www.yellowtree.de
8
+ Version: 2.5.7
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
  Text Domain: geoip-detect
16
  Requires PHP: 5.3.1
17
  */
18
 
19
+ define('GEOIP_DETECT_VERSION', '2.5.7');
20
 
21
  /*
22
  Copyright 2013-2015 Yellow Tree, Siegen, Germany
init.php CHANGED
@@ -55,7 +55,7 @@ function geoip_detect_admin_notice_database_missing() {
55
 
56
  <h3><?php _e( 'GeoIP Detection: No database installed', 'geoip-detect' ); ?></h3>
57
  <p><?php printf(__('The Plugin %s is currently using the Webservice <a href="http://hostip.info" target="_blank">hostip.info</a> as data source. <br />You can click on the button below to download and install Maxmind GeoIPv2 Lite City now.', 'geoip-detect' ), $url); ?></p>
58
- <p><?php printf(__('This database is licenced <a href="http://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA</a>. See <a href="http://dev.maxmind.com/geoip/geoip2/geolite2/#License">License</a> for details.')); ?>
59
 
60
 
61
 
55
 
56
  <h3><?php _e( 'GeoIP Detection: No database installed', 'geoip-detect' ); ?></h3>
57
  <p><?php printf(__('The Plugin %s is currently using the Webservice <a href="http://hostip.info" target="_blank">hostip.info</a> as data source. <br />You can click on the button below to download and install Maxmind GeoIPv2 Lite City now.', 'geoip-detect' ), $url); ?></p>
58
+ <p><?php printf(__('This database is licenced <a href="http://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA</a>. See <a href="http://dev.maxmind.com/geoip/geoip2/geolite2/#License">License</a> for details.', 'geoip-detect')); ?>
59
 
60
 
61
 
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === GeoIP Detection ===
2
  Contributors: benjaminpick
3
- Tags: geoip, ip, maxmind, geolocation, locator, latitude, longitude
4
  Requires at least: 3.5
5
- Tested up to: 4.4
6
  Stable tag: trunk
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -151,12 +151,17 @@ Fixing automatic weekly updates.
151
 
152
  == Changelog ==
153
 
 
 
 
 
 
154
  = 2.5.6 =
155
  * FIX: Removed noticed concerning open_basedir.
156
 
157
  = 2.5.5 =
158
 
159
- * Clean-up changes to prepare i18n.
160
  * FIX: Only show the "no database installed" admin notice to admins (props @meitar)
161
 
162
  = 2.5.4 =
1
  === GeoIP Detection ===
2
  Contributors: benjaminpick
3
+ Tags: geoip, maxmind, geolocation, locator
4
  Requires at least: 3.5
5
+ Tested up to: 4.5
6
  Stable tag: trunk
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
151
 
152
  == Changelog ==
153
 
154
+ = 2.5.7 =
155
+ * ADD: Shortcodes can now optionally specifiy the IP: `[geoip_detect2 property="country.isoCode" ip="(ipv4 or ipv6)"]`
156
+ * ADD: Plugin is now translated into German.
157
+ * FIX: `geoip_detect2_get_info_from_current_ip()` now also handles the case when REMOTE_ADDR contains multiple IP adresses
158
+
159
  = 2.5.6 =
160
  * FIX: Removed noticed concerning open_basedir.
161
 
162
  = 2.5.5 =
163
 
164
+ * Clean-up changes to prepare plugin translation.
165
  * FIX: Only show the "no database installed" admin notice to admins (props @meitar)
166
 
167
  = 2.5.4 =
shortcode.php CHANGED
@@ -31,7 +31,8 @@ add_shortcode('geoip_detect', 'geoip_detect_shortcode');
31
  *
32
  * Examples:
33
  * `[geoip_detect2 property="country"]` -> Germany
34
- * `[geoip_detect2 property="country.isoCode"]` -> de
 
35
  *
36
  * `[geoip_detect2 property="country" lang="de"]` -> Deutschland
37
  * `[geoip_detect2 property="country" lang="fr,de"]` -> Allemagne
@@ -41,6 +42,8 @@ add_shortcode('geoip_detect', 'geoip_detect_shortcode');
41
  * @param string $lang Language(s) (optional. If not set, current site language is used.)
42
  * @param string $default Default Value that will be shown if value not set (optional)
43
  * @param string $skipCache if 'true': Do not cache value
 
 
44
  */
45
  function geoip_detect2_shortcode($attr)
46
  {
@@ -55,7 +58,9 @@ function geoip_detect2_shortcode($attr)
55
 
56
  $options = array('skipCache' => $skipCache);
57
 
58
- $userInfo = geoip_detect2_get_info_from_current_ip($locales, $options);
 
 
59
 
60
  if ($userInfo->isEmpty)
61
  return $defaultValue . '<!-- GeoIP Detect: No information found for this IP (' . geoip_detect2_get_client_ip() . ') -->';
31
  *
32
  * Examples:
33
  * `[geoip_detect2 property="country"]` -> Germany
34
+ * `[geoip_detect2 property="country.isoCode"]` -> DE
35
+ * `[geoip_detect2 property="country.isoCode" ip="8.8.8.8"]` -> US
36
  *
37
  * `[geoip_detect2 property="country" lang="de"]` -> Deutschland
38
  * `[geoip_detect2 property="country" lang="fr,de"]` -> Allemagne
42
  * @param string $lang Language(s) (optional. If not set, current site language is used.)
43
  * @param string $default Default Value that will be shown if value not set (optional)
44
  * @param string $skipCache if 'true': Do not cache value
45
+ *
46
+ * @since 2.5.7 New attribute `ip`
47
  */
48
  function geoip_detect2_shortcode($attr)
49
  {
58
 
59
  $options = array('skipCache' => $skipCache);
60
 
61
+ $ip = isset($attr['ip']) ? $attr['ip'] : geoip_detect2_get_client_ip();
62
+
63
+ $userInfo = geoip_detect2_get_info_from_ip($ip, $locales, $options);
64
 
65
  if ($userInfo->isEmpty)
66
  return $defaultValue . '<!-- GeoIP Detect: No information found for this IP (' . geoip_detect2_get_client_ip() . ') -->';
views/footer.php CHANGED
@@ -3,7 +3,7 @@
3
  <br />
4
  <?php printf(__('This extension is "charity-ware". You can use it for free but if you want to do me a favor, please <a href="%s" target="_blank">donate</a> to <a href="%s" target="_blank">this charity</a>. (See <a href="%s" target="_blank">FAQ</a> for more infos.)', 'geoip-detect'),
5
  'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BSYUZHS8FH3CL',
6
- 'http://www.jmem-hainichen.de/homepage',
7
  'https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#what-you-mean-by-this-plugin-is-charity-ware'); ?>
8
  </p>
9
  <p class="legal_notices">
@@ -14,4 +14,4 @@
14
  font-size: 80%;
15
  font-style: italic;
16
  }
17
- </style>
3
  <br />
4
  <?php printf(__('This extension is "charity-ware". You can use it for free but if you want to do me a favor, please <a href="%s" target="_blank">donate</a> to <a href="%s" target="_blank">this charity</a>. (See <a href="%s" target="_blank">FAQ</a> for more infos.)', 'geoip-detect'),
5
  'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BSYUZHS8FH3CL',
6
+ __('http://www.jmem-hainichen.de/homepage', 'geoip-detect'),
7
  'https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#what-you-mean-by-this-plugin-is-charity-ware'); ?>
8
  </p>
9
  <p class="legal_notices">
14
  font-size: 80%;
15
  font-style: italic;
16
  }
17
+ </style>
views/lookup.php CHANGED
@@ -15,9 +15,9 @@ if ($shortcode_options) {
15
  }
16
  }
17
  ?>
18
- <div class="wrap">
19
  <h1><?php _e('GeoIP Detection', 'geoip-detect');?></h1>
20
- <a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>">Options</a>
21
 
22
  <p>
23
  <?php printf(__('<b>Selected data source:</b> %s', 'geoip-detect'), geoip_detect2_get_current_source_description() ); ?>
@@ -29,7 +29,7 @@ if ($shortcode_options) {
29
  <br />
30
  </p>
31
 
32
- <h2>Test Lookup</h2>
33
  <form method="post" action="#">
34
  <?php wp_nonce_field( 'geoip_detect_lookup' ); ?>
35
  <input type="hidden" name="action" value="lookup" />
@@ -42,13 +42,13 @@ if ($shortcode_options) {
42
  </select> </label><br />
43
  <label><input type="checkbox" name="skip_cache" value="1" <?php if (!empty($_POST['skip_cache'])) echo 'checked="checked"'?>/><?php _e('Skip cache', 'geoip-detect')?></label><br />
44
  <br />
45
- <input type="submit" class="button button-secondary" value="<?php _e('Lookup', 'geoip-detect'); ?>" />
46
  </form>
47
  <?php if ($ip_lookup_result !== false) :
48
  if (is_object($ip_lookup_result)) :
49
  $record = $ip_lookup_result;
50
  ?>
51
- <h3>Lookup Result</h3>
52
  <p>
53
  <?php printf(__('The function %s returns an object:', 'geoip-detect'), "<code>\$record = geoip_detect2_get_info_from_ip('" . esc_html($request_ip) . "', " . var_export($request_locales, true) . ($request_skipCache ? ', TRUE' : '') .");</code>"); ?><br />
54
  <?php printf(__('Lookup duration: %.5f s', 'geoip-detect'), $ip_lookup_duration); ?>
@@ -130,6 +130,10 @@ if ($shortcode_options) {
130
  <?php require(GEOIP_PLUGIN_DIR . '/views/footer.php'); ?>
131
  </div>
132
  <style>
 
 
 
 
133
  .geoip_detect_error {
134
  background-color: rgb(255, 255, 255);
135
  border-left: rgb(255, 0, 0) solid 4px;
15
  }
16
  }
17
  ?>
18
+ <div class="wrap geoip-detect-wrap">
19
  <h1><?php _e('GeoIP Detection', 'geoip-detect');?></h1>
20
+ <a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>"><?php _e('Options', 'geoip-detect');?></a>
21
 
22
  <p>
23
  <?php printf(__('<b>Selected data source:</b> %s', 'geoip-detect'), geoip_detect2_get_current_source_description() ); ?>
29
  <br />
30
  </p>
31
 
32
+ <h2><?php _e('Test IP Detection Lookup ', 'geoip-detect');?></h2>
33
  <form method="post" action="#">
34
  <?php wp_nonce_field( 'geoip_detect_lookup' ); ?>
35
  <input type="hidden" name="action" value="lookup" />
42
  </select> </label><br />
43
  <label><input type="checkbox" name="skip_cache" value="1" <?php if (!empty($_POST['skip_cache'])) echo 'checked="checked"'?>/><?php _e('Skip cache', 'geoip-detect')?></label><br />
44
  <br />
45
+ <input type="submit" class="button button-primary" value="<?php _e('Lookup', 'geoip-detect'); ?>" />
46
  </form>
47
  <?php if ($ip_lookup_result !== false) :
48
  if (is_object($ip_lookup_result)) :
49
  $record = $ip_lookup_result;
50
  ?>
51
+ <h3><?php _e('Lookup Result', 'geoip-detect'); ?></h3>
52
  <p>
53
  <?php printf(__('The function %s returns an object:', 'geoip-detect'), "<code>\$record = geoip_detect2_get_info_from_ip('" . esc_html($request_ip) . "', " . var_export($request_locales, true) . ($request_skipCache ? ', TRUE' : '') .");</code>"); ?><br />
54
  <?php printf(__('Lookup duration: %.5f s', 'geoip-detect'), $ip_lookup_duration); ?>
130
  <?php require(GEOIP_PLUGIN_DIR . '/views/footer.php'); ?>
131
  </div>
132
  <style>
133
+ .geoip-detect-wrap select {
134
+ max-width: 100%;
135
+ }
136
+
137
  .geoip_detect_error {
138
  background-color: rgb(255, 255, 255);
139
  border-left: rgb(255, 0, 0) solid 4px;