Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Composer compliant geoipregionvars array
Browse files Browse the repository at this point in the history
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
loranger committed Dec 2, 2013
1 parent af5e7c3 commit 8e05482
Show file tree
Hide file tree
Showing 3 changed files with 4,644 additions and 4,445 deletions.
38 changes: 38 additions & 0 deletions admin/build_geoipregionvars.php
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 modified admin/generate_geoipregionvars.php
100644 → 100755
Empty file.
Loading

0 comments on commit 8e05482

Please sign in to comment.