This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Composer compliant geoipregionvars array
Lighter builder (and downloader in case of missing sources) and globl prefix for $GEOIP_REGION_NAME in order to make it magically loadable with composer
- Loading branch information
Showing
3 changed files
with
4,644 additions
and
4,445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/php -q | ||
<?php | ||
|
||
function download_and_open($url) | ||
{ | ||
$file = basename($url); | ||
if ( !file_exists( sprintf('%s/%s', __DIR__, $file) ) ) { | ||
$ch = curl_init(); | ||
$timeout = 5; | ||
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); | ||
$data = curl_exec($ch); | ||
curl_close($ch); | ||
file_put_contents( $file, $data); | ||
} | ||
return file($file); | ||
} | ||
|
||
$fips10_4 = download_and_open('https://raw.github.com/maxmind/geoip-api-c/master/regioncode/fips10_4.txt'); | ||
array_shift($fips10_4); | ||
$iso3166_2 = download_and_open('https://raw.github.com/maxmind/geoip-api-c/master/regioncode/iso3166_2.txt'); | ||
array_shift($iso3166_2); | ||
$countries = array_merge($fips10_4, $iso3166_2); | ||
|
||
$array = array(); | ||
foreach ($countries as $line) { | ||
$datas = explode(',', $line); | ||
$array[$datas[0]][trim(preg_replace('/"/im', '', $datas[2]))] = sprintf("%s", $datas[1]); | ||
} | ||
$array = array_map('array_flip', $array); | ||
|
||
date_default_timezone_set("UTC"); | ||
$output .= "<?php\n"; | ||
$output .= sprintf("# Copyright %s MaxMind, Inc. All Rights Reserved\n", date('Y')); | ||
$output .= 'Global $GEOIP_REGION_NAME = ' . var_export($array, true); | ||
|
||
file_put_contents( __DIR__ . '/../src/geoipregionvars.php', $output); |
Empty file.
Oops, something went wrong.