first commit

This commit is contained in:
DESKTOP-GBA0BK8\Admin
2023-04-08 12:19:53 -04:00
commit 7c8c8b1c76
4586 changed files with 2050693 additions and 0 deletions
@@ -0,0 +1,58 @@
<div class="wrap geoip-detect-wrap">
<!-- This page cannot be translated yet, as I am not sure how it will look like in the long-term.
The goal is to have wizard helping to set all the relevant options semi-automatically. -->
<h1><?php _e('GeoIP Detection', 'geoip-detect');?> - Client IP Debug Panel</h1>
<p>
<a href="tools.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>"><?php _e('Test IP Detection Lookup', 'geoip-detect')?></a>
|
<a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>"><?php _e('Options', 'geoip-detect');?></a>
</p>
<pre>This debug panel is listing all relevant informations to debug when the detected client ip is wrong (in case of reverse proxies etc.)
Sometimes, there are proxies between your user and the wordpress server application (e.g. a <abbr title="Content Delivery Network: Amazon, Cloudflare, etc.">CDN</abbr>, reverse proxies).
This needs to be known to the plugin to choose the correct IP adress.
</pre>
<h2>Current IP informations (as detected by the plugin)</h2>
<p>
Detected client IP: <b><?php echo geoip_detect2_get_client_ip(); ?></b><br>
<span class="detail-box">This IP is used for detecting the geo-information of the user. It should be the same as the real client IP below.</span>
Real client IP (detected without the plugin): <b><span id="ajax_get_client_ip"><i>Detecting ...</i></span></b>
<span class="detail-box">This IP is detected within the browser, so reverse proxies of the server are not affected.<br></span>
External Server IP: <b><?php echo geoip_detect2_get_external_ip_adress(); ?></b><br>
<span class="detail-box">In some cases, the server is in the same network as the client (e.g. testing server). As the connection does not use Internet, this plugin uses the IP adress of the server as seen from the internet.<br>
For performance reasons, this IP is cached for <?php echo human_time_diff(0, GEOIP_DETECT_IP_CACHE_TIME); ?>.<br>
Also, for servers without internet access, this IP can be set in the options.
</span>
</p>
<p>
REMOTE_ADDR: <b><?php echo $_SERVER['REMOTE_ADDR']; ?></b><br>
<span class="detail-box">In server configurations without reverse proxy, this will equal to the "detected client IP". Otherwise, this is the IP of the reverse proxy.</span>
HTTP_X_FORWARDED_FOR: <b><?php echo isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : __('(unset)', 'geoip-detect'); ?></b><br>
<span class="detail-box">Reverse proxies usually add this header to indicate the original IP. If several IPs are given here (seperated by a comma), the correct user IP usually is the leftmost one.</span>
<?php if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && !get_option('geoip-detect-has_reverse_proxy')): ?>
<i>(Probably you should enable the reverse proxy option.)</i>
<?php endif; ?>
</p>
<h3>Settings of the plugin</h3>
<ul>
<li>Use reverse proxy: <b><?php echo get_option('geoip-detect-has_reverse_proxy', 0) ? 'yes' : 'no' ?></b>
<span class="detail-box">Enable this option if REMOTE_ADDR is not the correct client IP.</span>
</li>
<li>Whitelist for known reverse proxies (optional if only one): <b><?php echo get_option('geoip-detect-trusted_proxy_ips') ?: '(none)'; ?></b>
<span class="detail-box">All IPs in HTTP_X_FORWARDED_FOR that are not the correct client IP are probably known reverse proxies.<br>(For security reasons, this is not assumed by default: maybe the reverse proxy is not of the server, but a Man-In-The-Middle-Attack ... not very probable but possible.)</span>
</li>
</ul>
<script>
jQuery.ajax(<?php echo json_encode(_geoip_detect2_get_external_ip_services(1, true)[0]); ?>, {
type: 'GET',
dataType: 'text',
}).done(function(ret) {
jQuery('#ajax_get_client_ip').text(ret);
}).fail(function(xhr, status, ret) {
jQuery('#ajax_get_client_ip').text('Failed: ' + status + ret);
});
</script>
<?php require(GEOIP_PLUGIN_DIR . '/views/footer.php'); ?>
</div>
@@ -0,0 +1,45 @@
<br><br>
<p class="legal_notices">
<br />
<?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'),
'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BSYUZHS8FH3CL',
__('http://www.jmem-hainichen.de/homepage', 'geoip-detect'),
'https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#what-you-mean-by-this-plugin-is-charity-ware'); ?>
</p>
<p class="legal_notices">
<?php _e('This product includes GeoLite2 data created by MaxMind, available from <a href="http://www.maxmind.com/">http://www.maxmind.com</a>.', 'geoip-detect'); ?>
</p>
<style>
.legal_notices {
font-size: 80%;
font-style: italic;
}
.geoip_detect_error {
display:block;
clear: both;
background-color: rgb(255, 255, 255);
border-left: rgb(255, 0, 0) solid 4px;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
display: inline-block;
font-size: 14px;
line-height: 19px;
margin-bottom: 0;
margin-left: 2px;
margin-right: 20px;
margin-top: 25px;
padding-bottom: 11px;
padding-left: 15px;
padding-right: 15px;
padding-top: 11px;
text-align: left;
}
.detail-box {
display: block;
margin-left: 50px;
color: #777;
}
.geoip-detect-wrap select {
max-width: 100%;
}
</style>
@@ -0,0 +1,230 @@
<?php
use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
$date_format = get_option('date_format') . ' ' . get_option('time_format');
$current_source = DataSourceRegistry::getInstance()->getCurrentSource();
$is_ajax_enabled = !!get_option('geoip-detect-ajax_enabled');
// @see https://stackoverflow.com/a/35207172
function var_export_short($data, $return=true)
{
$dump = var_export($data, true);
$dump = preg_replace('#(?:\A|\n)([ ]*)array \(#i', '[', $dump); // Starts
$dump = preg_replace('#\n([ ]*)\),#', "\n$1],", $dump); // Ends
$dump = preg_replace('#=> \[\n\s+\],\n#', "=> [],\n", $dump); // Empties
if (gettype($data) == 'object') { // Deal with object states
$dump = str_replace('__set_state(array(', '__set_state([', $dump);
$dump = preg_replace('#\)\)$#', "])", $dump);
} else {
$dump = preg_replace('#\)$#', "]", $dump);
}
$dump = preg_replace('#,[\n\s]*]#m', "\n]", $dump);
if ($return===true) {
return $dump;
} else {
echo $dump;
}
}
?>
<div class="wrap geoip-detect-wrap">
<h1><?php _e('GeoIP Detection', 'geoip-detect');?></h1>
<p>
<a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>"><?php _e('Options', 'geoip-detect');?></a>
</p>
<p>
<?php printf(__('<b>Selected data source:</b> %s', 'geoip-detect'), geoip_detect2_get_current_source_description() ); ?>
</p>
<p>
<?php echo $current_source->getStatusInformationHTML(); ?>
<br />
<br />
</p>
<p>
<b><?php _e('Your current IP:', 'geoip-detect');?></b> <?php echo geoip_detect2_get_client_ip(); ?>
<a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>&geoip_detect_part=client-ip">(<?php _e('Not correct?', 'geoip-detect');?>)</a>
</p>
<h2><?php _e('Test IP Detection Lookup ', 'geoip-detect');?></h2>
<form method="post" action="#">
<?php wp_nonce_field( 'geoip_detect_lookup' ); ?>
<input type="hidden" name="action" value="lookup" />
<?php _e('IP', 'geoip-detect')?>: <input type="text" placeholder="<?php _e('Enter an IP (v4 or v6)', 'geoip-detect')?>" name="ip" value="<?php echo isset($_REQUEST['ip']) ? esc_attr($_REQUEST['ip']) : esc_attr(geoip_detect2_get_client_ip()); ?>" /><br />
<label><?php _e('Use these locales:', 'geoip-detect'); ?>
<select name="locales">
<option value="" <?php if (empty($_POST['locales'])) echo 'selected="selected"'?>><?php _e('Default (Current site language, English otherwise)', 'geoip-detect')?></option>
<option value="en" <?php if (!empty($_POST['locales']) && $_POST['locales'] == 'en') echo 'selected="selected"'?>><?php _e('English only', 'geoip-detect')?></option>
<option value="fr,en" <?php if (!empty($_POST['locales']) && $_POST['locales'] == 'fr,en') echo 'selected="selected"'?>><?php _e('French, English otherwise', 'geoip-detect')?></option>
</select>
</label><br />
<label><?php _e('Which syntax:', 'geoip-detect'); ?>
<select name="syntax">
<option value="php" <?php if (empty($_POST['syntax']) || $_POST['syntax'] === 'php') echo 'selected="selected"'?>><?= __('PHP Syntax') ?></option>
<option value="shortcode" <?php if (!empty($_POST['syntax']) && $_POST['syntax'] === 'shortcode') echo 'selected="selected"'?>><?= __('Shortcode Syntax') ?></option>
<option value="js" <?php if (!empty($_POST['syntax']) && $_POST['syntax'] === 'js') echo 'selected="selected"'?>><?= __('JS Syntax') ?></option>
</select>
</label><br>
<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 />
<br />
<input type="submit" class="button button-primary" value="<?php _e('Lookup', 'geoip-detect'); ?>" />
</form>
<?php if ($ip_lookup_result !== false) :
if (is_object($ip_lookup_result)) :
$record = $ip_lookup_result;
$data = _geoip_detect_improve_data_for_lookup($record->jsonSerialize());
$data_short = _geoip_detect_improve_data_for_lookup($record->jsonSerialize(), true);
?>
<h3><?php _e('Lookup Result', 'geoip-detect'); ?></h3>
<p>
<?php if ($_POST['syntax'] == 'php') : ?>
<?php printf(__('The function %s returns an object:', 'geoip-detect'), "<code>\$record = geoip_detect2_get_info_from_ip('" . esc_html($request_ip) . "', " . var_export_short($request_locales, true) . ($request_skipCache ? ', [ \'skipCache\' => TRUE ]' : '') .");</code>"); ?><br />
<?= sprintf(__('See %s for more information.', 'geoip-detect'), '<a href="https://github.com/yellowtree/geoip-detect/wiki/API:-PHP">API: PHP</a>'); ?>
<?php elseif ($_POST['syntax'] == 'shortcode') : ?>
<?= sprintf(__('You can use the following shortcodes.', 'geoip-detect')); ?><br />
<?= sprintf(__('See %s for more information.', 'geoip-detect'), '<a href="https://github.com/yellowtree/geoip-detect/wiki/API:-Shortcodes">API: Shortcodes</a>'); ?>
<?php elseif ($_POST['syntax'] == 'js') : ?>
<?= sprintf(__('AJAX and JS must be enabled in the preferences!', 'geoip-detect')); ?><br />
<?= sprintf(__('See %s for more information.', 'geoip-detect'), '<a href="https://github.com/yellowtree/geoip-detect/wiki/API:-AJAX">API: AJAX</a>'); ?>
<?php endif; ?>
</p>
<p>
<?php printf(__('Lookup duration: %.5f s', 'geoip-detect'), $ip_lookup_duration); ?>
<?php if ($record->extra->cached) : ?>
<br /><?php printf(__('(Served from cache. Was cached %s ago)', 'geoip-detect'), human_time_diff($record->extra->cached));?>
<?php endif; ?>
</p>
<?php if ($record->extra->error) : ?>
<p class="geoip_detect_error">
<?php echo nl2br(esc_html($record->extra->error)); ?>
</p>
<?php endif; ?>
<table>
<tr>
<th></th>
<th style="text-align: left"><?php _e('Value', 'geoip-detect'); ?></th>
</tr>
<?php
function show_row($record, $key_1, $key_2, $value = null, $class = '') {
if (is_array($value)) {
if ($key_2 === 'names') {
show_row($record, $key_1, 'name', null, $class);
return;
}
if ($key_1 === 'subdivisions') {
foreach ($value as $key_3 => $v) {
show_row($record, 'most_specific_subdivision', $key_3, $v, $class);
}
return;
}
}
$camel_key_1 = _geoip_dashes_to_camel_case($key_1);
$camel_key_2 = _geoip_dashes_to_camel_case($key_2);
try {
if (is_object($record) ) {
$value = $record->$camel_key_1;
if (is_object($value)) {
$value = $value->$camel_key_2;
}
}
} catch(\RuntimeException $e) {
return; // Access did not work.
}
if (!is_string($value)) {
$value = var_export_short($value, true);
}
switch($_POST['syntax']) {
case 'shortcode':
$extra = '';
if (!empty($_POST['locales']) && $key_2 === 'name') {
$extra .= ' lang="' . $_POST['locales'] . '"';
}
if (!empty($_POST['skip_cache'])) {
$extra .= ' skip_cache="true"';
}
$access = '[geoip_detect2 property="' . $camel_key_1 . '.' . $camel_key_2 . '"' . $extra . ']';
break;
case 'js':
$prop = '"' . $key_1 . '.' . $key_2 . '"';
if (!empty($_POST['locales']) && $key_2 === 'name') {
$access = 'record.get_with_locales(' . $prop . ', ' . json_encode(explode(',', $_POST['locales'])) . ')';
} else {
$access = 'record.get(' . $prop . ')';
}
break;
case 'php':
default:
$access = '$record->' . $camel_key_1 . '->' . $camel_key_2;
break;
}
?>
<tr class="<?= $class ?>">
<td><code><?= esc_html($access) ?></code></td>
<td><?= esc_html($value);?></td>
</tr>
<?php
}
foreach($data as $key_1 => $value_1) {
if (is_array($value_1)) {
foreach($value_1 as $key_2 => $value_2) {
show_row($record, $key_1, $key_2, $value_2, 'all');
}
}
}
foreach($data_short as $key_1 => $value_1) {
if (is_array($value_1)) {
foreach($value_1 as $key_2 => $value_2) {
show_row($record, $key_1, $key_2, $value_2, 'short');
}
}
}
?>
</table>
<p class="all"><a href="#" onclick="geoip_properties_toggle('short', 'all'); return false;"><?= __('Show only the most common properties', 'geoip-detect') ?></a></p>
<p class="short"><a href="#" onclick="geoip_properties_toggle('all', 'short'); return false;"><?= __('Show all available properties', 'geoip-detect') ?></a></p>
<p><?= __('(More properties might be available for other IPs and with other data sources.)', 'geoip-detect'); ?></p>
<?php if (WP_DEBUG) { var_Dump($data); } ?>
<?php elseif ($ip_lookup_result === 0 || is_null($ip_lookup_result)) : ?>
<p>
<?php _e('No information found about this IP.', 'geoip-detect')?>
</p>
<?php endif; ?>
<?php endif; ?>
<p>
<?php printf(__('See %s for more documentation.', 'geoip-detect'), '<a href="http://dev.maxmind.com/geoip/geoip2/web-services/" target="_blank">http://dev.maxmind.com/geoip/geoip2/web-services/</a>');?>
</p>
<?php require(GEOIP_PLUGIN_DIR . '/views/footer.php'); ?>
</div>
<script>
function geoip_properties_toggle(show, hide) {
jQuery('.' + show).show();
jQuery('.' + hide).hide();
}
jQuery('document').ready(function() {
jQuery('.all').hide();
})
</script>
@@ -0,0 +1,123 @@
<?php
$options = $currentSource->getParameterHTML();
$currentSourceId = $currentSource->getId();
?>
<div class="wrap">
<h1><?php _e('GeoIP Detection', 'geoip-detect');?></h1>
<p><a href="tools.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>"><?php _e('Test IP Detection Lookup', 'geoip-detect')?></a></p>
<?php if (!empty($message)): ?>
<p class="geoip_detect_error">
<?php echo $message; ?>
</p>
<?php endif; ?>
<p>
<?php printf(__('<b>Selected data source:</b> %s', 'geoip-detect'), geoip_detect2_get_current_source_description() ); ?>
</p>
<p>
<?php echo $currentSource->getStatusInformationHTML(); ?>
</p>
<?php if ($options) : ?>
<h2><?php _e('Options for this data source', 'geoip-detect'); ?></h2>
<p>
<form method="post" action="#">
<input type="hidden" name="action" value="options-source" />
<?php wp_nonce_field( 'geoip_detect_options-source' ); ?>
<p><?php echo $options; ?></p>
<p>
<input type="submit" class="button button-primary" value="<?php _e('Save', 'geoip-detect'); ?>" />
</p>
</form>
</p>
<?php endif; ?>
<br/>
<br /><br />
<form method="post" action="#">
<input type="hidden" name="action" value="choose" />
<?php wp_nonce_field( 'geoip_detect_choose' ); ?>
<h2><?php _e('Choose data source:', 'geoip-detect'); ?></h2>
<a href="https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#which-data-source-should-i-choose"><?php _e('Help', 'geoip-detect'); ?></a>
<?php foreach ($sources as $s) : $id = $s->getId();?>
<p><label><input type="radio" name="options[source]" value="<?php echo $id ?>" <?php if ($currentSourceId == $id) { echo 'checked="checked"'; } ?> /><?php echo $s->getLabel(); ?></label></p>
<span class="detail-box">
<?php echo $s->getDescriptionHTML(); ?>
</span>
<?php endforeach; ?>
<br />
<input type="submit" class="button button-primary" value="<?php _e('Save', 'geoip-detect'); ?>" />
</form>
<form method="post" action="#">
<input type="hidden" name="action" value="options" />
<?php wp_nonce_field( 'geoip_detect_options' ); ?>
<h3><?php _e('General Options', 'geoip-detect'); ?></h3>
<p>
<label><input type="checkbox" name="options[set_css_country]" value="1" <?php if (!empty($wp_options['set_css_country'])) { echo 'checked="checked"'; } ?>>&nbsp;<?php _e('Add a country-specific CSS class to the &lt;body&gt;-Tag.', 'geoip-detect'); ?></label><br />
</p>
<p>
<label><input type="checkbox" name="options[disable_pagecache]" value="1" <?php if (!empty($wp_options['disable_pagecache'])) { echo 'checked="checked"'; } ?>>&nbsp;<?php _e('Disable caching a page that contains a shortcode or API call to geo-dependent functions.', 'geoip-detect'); ?></label><br />
<span class="detail-box">
<?php _e('At least WP SuperCache, W3TotalCache and ZenCache are supported.', 'geoip-detect'); ?>
</span>
<?php if (!empty($wp_options['set_css_country']) && !empty($wp_options['disable_pagecache']) && empty($wp_options['ajax_enabled'])): ?>
<span class="geoip_detect_error"><?php _e('Warning: As the CSS option above is active, this means that all pages are not cached.', 'geoip-detect'); ?></span>
<?php endif; ?>
</p>
<p>
<label><input type="checkbox" name="options[ajax_enabled]" value="1" <?php if (!empty($wp_options['ajax_enabled'])) { echo 'checked="checked"'; } ?>>BETA: &nbsp;<?php _e('Enable AJAX endpoint to get the information for the current IP even on cached pages.', 'geoip-detect'); ?></label>
</p>
<?php if (in_array($currentSourceId, array('precision', 'ipstack')) && !empty($wp_options['ajax_enabled'])): ?>
<span class="geoip_detect_error" style="margin-top: 0;"><?php printf(__('Warning: In theory, other websites could use your API credits over AJAX, this cannot be prevented completely (see <a href="%s" target="_blank">documentation</a> for more infos). You should use a different data source or disable AJAX.', 'geoip-detect'), 'https://github.com/yellowtree/geoip-detect/wiki/JS-API-Documentation'); ?></span>
<?php endif; ?>
<p style="margin-left: 20px;">
<label><input type="checkbox" name="options[ajax_enqueue_js]" value="1" <?php if (!empty($wp_options['ajax_enqueue_js'])) { echo 'checked="checked"'; } ?>>BETA: &nbsp;<?php _e('Add JS to make the access to the AJAX endpoint easier.', 'geoip-detect'); ?></label>
<span class="detail-box">
<?php _e('You will need to code JS (see <a href="https://github.com/yellowtree/geoip-detect/wiki/API%3A-AJAX">documentation</a>) in order to make this work. Shortcodes are not automatically converted to their AJAX equivalent.', 'geoip-detect'); ?>
</span>
</p>
<p>
<label><input type="checkbox" name="options[has_reverse_proxy]" value="1" <?php if (!empty($wp_options['has_reverse_proxy'])) { echo 'checked="checked"'; } ?>>&nbsp;<?php _e('The server is behind a reverse proxy', 'geoip-detect')?></label>
<a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>&geoip_detect_part=client-ip">(<?php _e('Client IP debug panel', 'geoip-detect');?>)</a>
<span class="detail-box">
<?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) : ?>
<?php printf(__('(With Proxy: %s - Without Proxy: %s - Client IP with current configuration: %s)', 'geoip-detect'), $_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR'], geoip_detect2_get_client_ip()); ?><br />
<?php else: ?>
<?php echo __("(This doesn't seem to be the case.)", 'geoip-detect'); ?>
<?php endif; ?>
</span>
</p>
<p>
<label><?php _e('IPs of trusted proxies:', 'geoip-detect'); ?><input type="text" name="options[trusted_proxy_ips]" <?php echo esc_attr($wp_options['trusted_proxy_ips']); ?>" placeholder="1.1.1.1, 1234::1, 2.2.2.2/24" />
<span class="detail-box">
<?php _e('If specified, only IPs in this list will be treated as proxy.', 'geoip-detect'); ?><br>
<?php _e('Make sure to add both IPv4 and IPv6 adresses of the proxy!', 'geoip-detect'); ?>
</span>
</p>
<p>
<label><?php _e('External IP of this server:', 'geoip-detect'); ?> <input type="text" name="options[external_ip]" value="<?php echo esc_attr($wp_options['external_ip']); ?>" placeholder="<?php _e('detect automatically', 'geoip-detect'); ?>" /></label>
<span class="detail-box">
<?php _e('Current value:', 'geoip-detect'); ?> <?php echo geoip_detect2_get_external_ip_adress(); ?><br />
<?php _e('If empty: Try to use an ip service to detect it (Internet connection is necessary). If this is not possible, 0.0.0.0 will be returned.', 'geoip-detect'); ?><br />
<?php _e('(This external adress will be used when the request IP adress is not a public IP, e.g. 127.0.0.1)', 'geoip-detect'); ?>
</span>
</p>
<p>
<input type="submit" class="button button-primary" value="<?php _e('Save', 'geoip-detect'); ?>" />
</p>
</form>
<?php if (!$ipv6_supported) : ?>
<div class="geoip_detect_error">
<h3><?php _e('IPv6 not supported', 'geoip-detect'); ?></h3>
<p>
<?php _e('Your version of PHP is compiled without IPv6-support, so it is not possible to lookup adresses like "2001:4860:4801:5::91". For more information see <a href="https://php.net/manual/en/function.inet-pton.php">PHP documentation & user comments</a>.', 'geoip-detect'); ?>
</p>
</div>
<?php endif; ?>
<?php require(GEOIP_PLUGIN_DIR . '/views/footer.php'); ?>
</div>
@@ -0,0 +1,185 @@
<?php
$date_format = get_option('date_format') . ' ' . get_option('time_format')
?>
<div class="wrap">
<h2><?php _e('GeoIP Detection', 'geoip-detect');?></h2>
<?php if (!empty($message)): ?>
<p class="geoip_detect_error">
<?php echo $message; ?>
</p>
<?php endif; ?>
<p>
<?php printf(__('Selected data source: %s', 'geoip-detect'), geoip_detect2_get_current_source_description() ); ?>
</p>
<?php if ($last_update_db) : ?>
<p>
<?php printf(__('Database data from: %s', 'geoip-detect'), date_i18n($date_format, $last_update_db) ); ?>
</p>
<?php endif; ?>
<?php if ($options['source'] == 'hostinfo') : ?>
<p>
You can choose a Maxmind database below.
</p>
<?php endif; ?>
<?php if ($options['source'] == 'auto') : ?>
<p>
<?php printf(__('Last updated: %s', 'geoip-detect'), $last_update ? date_i18n($date_format, $last_update) : __('Never', 'geoip-detect')); ?>
<?php if (GEOIP_DETECT_UPDATER_INCLUDED && (!defined('GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED') || !GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED)) : ?>
<br />
<?php printf(__('Next update: %s', 'geoip-detect'), $next_cron_update ? date_i18n($date_format, $next_cron_update) : __('Never', 'geoip-detect')); ?><br />
<em><?php _e('(The file is updated automatically once a month.)', 'geoip-detect'); ?></em>
<?php endif; ?>
</p>
<?php if (GEOIP_DETECT_UPDATER_INCLUDED) : ?>
<form method="post" action="#">
<input type="hidden" name="action" value="update" />
<input type="submit" class="button button-primary" value="<?php _e('Update now'); ?>" />
</form>
<?php endif; ?>
<?php endif; ?>
<br/>
<h3>Test GeoIP Lookup manually</h3>
<form method="post" action="#">
<input type="hidden" name="action" value="lookup" />
<input type="text" placeholder="Enter an IP (v4 or v6)" name="ip" value="<?php echo isset($_REQUEST['ip']) ? esc_attr($_REQUEST['ip']) : esc_attr(geoip_detect2_get_client_ip()); ?>" />
<input type="submit" class="button button-secondary" value="<?php _e('Lookup', 'geoip-detect'); ?>" />
</form>
<?php if ($ip_lookup_result !== false) :
if (is_object($ip_lookup_result)) : $record = $ip_lookup_result; ?>
<p>
<?php printf(__('The function %s returns an object:', 'geoip-detect'), "<code>\$record = geoip_detect2_get_info_from_ip('" . esc_html($_POST['ip']) . "')</code>"); ?>
</p>
<table>
<tr>
<th><?php _e('Key', 'geoip-detect'); ?></th>
<th><?php _e('Value', 'geoip-detect'); ?></th>
</tr>
<tr>
<td><code>$record-&gt;city-&gt;name</code></td>
<td><?php echo esc_html($record->city->name);?></td>
</tr>
<tr>
<td><code>$record-&gt;mostSpecificSubdivision-&gt;isoCode</code></td>
<td><?php echo esc_html($record->mostSpecificSubdivision->name);?></td>
</tr>
<tr>
<td><code>$record-&gt;mostSpecificSubdivision-&gt;name</code></td>
<td><?php echo esc_html($record->mostSpecificSubdivision->name);?></td>
</tr>
<tr>
<td><code>$record-&gt;country-&gt;isoCode</code></td>
<td><?php echo esc_html($record->country->isoCode);?></td>
</tr>
<tr>
<td><code>$record-&gt;country-&gt;name</code></td>
<td><?php echo esc_html($record->country->name);?></td>
</tr>
<tr>
<td><code>$record-&gt;location-&gt;latitude</code></td>
<td><?php echo esc_html($record->location->latitude);?></td>
</tr>
<tr>
<td><code>$record-&gt;location-&gt;longitude</code></td>
<td><?php echo esc_html($record->location->longitude);?></td>
</tr>
<tr>
<td><code>$record-&gt;continent-&gt;code</code></td>
<td><?php echo esc_html($record->continent->code);?></td>
</tr>
<tr>
<td><code>$record-&gt;location-&gt;timeZone</code></td>
<td><?php echo esc_html($record->location->timeZone);?></td>
</tr>
</table>
<?php elseif ($ip_lookup_result === 0 || is_null($ip_lookup_result)) : ?>
<p>
<?php _e('No information found about this IP.', 'geoip-detect')?>
</p>
<?php endif; ?>
<?php endif; ?>
<p>
<?php printf(__('See %s for more documentation.', 'geoip-detect'), '<a href="http://dev.maxmind.com/geoip/geoip2/web-services/" target="_blank">http://dev.maxmind.com/geoip/geoip2/web-services/</a>');?>
</p>
<br /><br />
<h3>Options</h3>
<form method="post" action="#">
<input type="hidden" name="action" value="options" />
<p>
<input type="checkbox" name="options[set_css_country]" value="1" <?php if ($options['set_css_country']) { echo 'checked="checked"'; } ?>>&nbsp;<?php _e('Add a country-specific CSS class to the &lt;body&gt;-Tag.', 'geoip-detect'); ?><br />
</p>
<p>
<input type="checkbox" name="options[has_reverse_proxy]" value="1" <?php if ($options['has_reverse_proxy']) { echo 'checked="checked"'; } ?>>&nbsp;The server is behind a reverse proxy<em>
<span class="detail-box">
<?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) : ?>
<?php printf(__('(With Proxy: %s - Without Proxy: %s)', 'geoip-detect'), $_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']); ?><br />
<?php else: ?>
<?php echo "(This doesn't seem to be the case.)"; ?>
<?php endif; ?>
</em>
</span>
</p>
<h4>Data source: </h4>
<?php if (GEOIP_DETECT_UPDATER_INCLUDED) : ?>
<p><input type="radio" name="options[source]" value="auto" <?php if ($options['source'] == 'auto') { echo 'checked="checked"'; } ?> />Automatic download &amp; update of Maxmind GeoIP Lite City</p>
<span class="detail-box">
(License: Creative Commons Attribution-ShareAlike 3.0 Unported. See <a href="https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#the-maxmind-lite-databases-are-licensed-creative-commons-sharealike-attribution-when-do-i-need-to-give-attribution" target="_blank">Licensing FAQ</a> for more details.)
</span>
<?php else : ?>
<p><input type="radio" name="options[source]" value="auto" disabled="disabled"/>Automatic download &amp; update <em>(only available in Github version)</em></p>
<?php endif; ?>
<p><input type="radio" name="options[source]" value="manual" <?php if ($options['source'] == 'manual') { echo 'checked="checked"'; } ?> />Manual download &amp; update of a Maxmind City or Country database<br />
<span class="detail-box">
Filepath to mmdb-file: <input type="text" size="40" name="options[manual_file]" value="<?php echo esc_attr($options['manual_file']); ?>" /><br />
<a href="http://dev.maxmind.com/geoip/geoip2/geolite2/" target="_blank">Free version</a> - <a href="https://www.maxmind.com/en/geoip2-country-database" target="_blank">Commercial Version</a>
</span>
<p><input type="radio" name="options[source]" value="hostinfo" <?php if ($options['source'] == 'hostinfo') { echo 'checked="checked"'; } ?> />HostIp.info<br />
<span class="detail-box">
(only English names, only country, country ID and city are populated)
</span>
</p>
<p>
<input type="submit" class="button button-primary" value="<?php _e('Save', 'geoip-detect'); ?>" />
</p>
</form>
<p>
<br />
<small><em>This product includes GeoLite2 data created by MaxMind, available from <a href="http://www.maxmind.com/">http://www.maxmind.com</a>.</em></small>
</p>
</div>
<style>
.geoip_detect_error {
background-color: rgb(255, 255, 255);
border-left: rgb(255, 0, 0) solid 4px;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
display: inline-block;
font-size: 14px;
line-height: 19px;
margin-bottom: 0;
margin-left: 2px;
margin-right: 20px;
margin-top: 25px;
padding-bottom: 11px;
padding-left: 15px;
padding-right: 15px;
padding-top: 11px;
text-align: left;
}
.detail-box {
display: block;
margin-left: 50px;
color: #777;
}
</style>