'Amazon AWS CloudFront',
'cloudflare' => 'Cloudflare',
);
public function country($ip) {
$r = array();
$isoCode = '';
switch ($this->options['provider']) {
case 'aws':
if (isset($_SERVER['CloudFront-Viewer-Country'])) {
$isoCode = $_SERVER['CloudFront-Viewer-Country'];
}
break;
case 'cloudflare';
if (isset($_SERVER["HTTP_CF_IPCOUNTRY"])) {
$isoCode = $_SERVER["HTTP_CF_IPCOUNTRY"];
if ($isoCode == 'xx' /* not a country / unknown */)
$isoCode = '';
}
break;
}
$country = '';
if (!$isoCode) {
return null;
}
$r['country']['iso_code'] = strtoupper($isoCode);
$r['traits']['ip_address'] = $ip;
$record = new \GeoIp2\Model\City($r, array('en'));
return $record;
}
}
class HeaderDataSource extends AbstractDataSource {
public function getId() { return 'header'; }
public function getLabel() { return __('Special Hosting Providers (Cloudflare, Amazon AWS CloudFront)', 'geoip-detect'); }
public function getDescriptionHTML() { return __('These servers already do geodetection, but only of the visitor\'s country.', 'geoip-detect'); }
public function getStatusInformationHTML() {
$provider = get_option('geoip-detect-header-provider');
$html = '';
$link = '';
if ($provider == 'cloudflare') {
$link = 'https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-CloudFlare-IP-Geolocation-do-';
} elseif ($provider == 'aws') {
$link = 'https://aws.amazon.com/blogs/aws/enhanced-cloudfront-customization/';
}
if ($link)
$html = sprintf(__('This needs to be enabled in the admin panel: see Help.', 'geoip-detect'), $link);
return $html;
}
public function getParameterHTML() {
$provider = get_option('geoip-detect-header-provider');
$checked_cloudflare = $provider == 'cloudflare' ? 'checked' : '';
$checked_aws = $provider == 'aws' ? 'checked' : '';
$label = __('Which Hosting Provider:', 'geoip-detect');
$html = <<$label