"Drenthe",
'FL' => "Flevoland",
'FR' => "Friesland",
'GE' => "Gelderland",
'GR' => "Groningen",
'LI' => "Limburg",
'NB' => "Noord Brabant",
'NH' => "Noord Holland",
'OV' => "Overijssel",
'UT' => "Utrecht",
'ZE' => "Zeeland",
'ZH' => "Zuid Holland");
}
/**
* DB retrieve/update
*/
/**
* The himbuv.com page allows 8 lookups per hour.
*/
define('_S_URL', 'http://www.himbuv.com/cgi-bin/geo/post2degr.pl?postcode=');
define('_S_HIMBUV_ERROR', "Sorry
Om misbruik te voorkomen kunt u niet meer dan 8 keer per uur deze pagina opvragen
Home");
define('_S_HIMBUV_LAT', 'Breedtegraad:');
define('_S_HIMBUV_LON', 'Lengtegraad:');
define('_S_HIMBUV_CITY', 'Postcode-regio');
function location_get_postalcode_data_nl($location = array()) {
if (!isset($location['postal_code'])) {
return NULL;
}
$result = db_query("SELECT * FROM {zipcodes} WHERE country = '%s' AND zip = '%s'", $location['country'], $location['postal_code']);
if ($row = db_fetch_object($result)) {
return array('lat' => $row->latitude, 'lon' => $row->longitude, 'city' => $row->city, 'province' => $row->state, 'country' => $row->country);
}
else {
return _location_get_postalcode_data_nl($location);
}
}
function _location_get_postalcode_data_nl($location = array()) {
if (!isset($location['postal_code'])) {
return NULL;
}
$_s_himbuv = '';
$_a_regkeys = array("\n", "?table[^>]*>", "(?tr>)+");
$_a_lines = array();
$_a_return = array('lat' => '', 'lon' => '', 'city' => '', 'province' => '', 'country' => 'nl');
/**
* retrieve himbuv page
*/
$_o_himbuv = fopen(_S_URL . $location['postal_code'], 'r');
do {
$_s_tmp = fread($_o_himbuv, 8192);
if (strlen($_s_tmp) == 0) {
break;
}
$_s_himbuv .= $_s_tmp;
} while (true);
fclose($_o_himbuv);
if (stristr($_s_himbuv, _S_HIMBUV_ERROR)) {
drupal_set_message(t('Sorry, himbuv.com allows only 8 lookups per hour. Try again later for Drupal to add the coordinates to its database.'));
return NULL;
}
/**
* parse himbuv page
*/
while ((stristr($_s_himbuv, _S_HIMBUV_LON) && stristr($_s_himbuv, _S_HIMBUV_LAT)) && count($_a_regkeys)) {
$_a_lines = split(array_shift($_a_regkeys), $_s_himbuv);
foreach ($_a_lines as $_key => $_value) {
//print $_key ." : ". $_value . "\n";
if (stristr($_value, _S_HIMBUV_LON) && stristr($_value, _S_HIMBUV_LAT)) {
$_s_himbuv = $_value;
break;
}
}
//print "\n";
}
foreach ($_a_lines as $_key => $_value) {
$_a_lines[$_key] = split("(?td>)+", $_value);
if (count($_a_lines[$_key]) != 4) {
unset($_a_lines[$_key]);
}
}
/**
* parse values
*/
foreach ($_a_lines as $_key => $_value) {
if (stristr($_value[1], _S_HIMBUV_LON)) {
$_a_return['lon'] = substr($_value[2],0,strlen($_value[2] - 1));
}
if (stristr($_value[1], _S_HIMBUV_LAT)) {
$_a_return['lat'] = substr($_value[2],0,strlen($_value[2] - 1));
}
if (stristr($_value[1], _S_HIMBUV_CITY)) {
$_a_return['city'] = $_value[2];
}
}
/**
* if lat/lon exist, insert into {zipcodes} table and return location
*/
if (($_a_return['lat'] != '') && ($_a_return['lon'] != '')) {
$result = db_query("INSERT INTO {zipcodes} SET zip='%s', city='%s', state='%s', latitude='%s', longitude='%s', timezone='%d', dst='%d', country='%s'", $location['postal_code'], $_a_return['city'], $location['province'], $_a_return['lat'], $_a_return['lon'], 2, 1, $location['country']);
drupal_set_message(t('Coordinates added to database.'));
return $_a_return;
}
/**
* All that work, and all for NULL
*/
return NULL;
}
/**
* Map Links
*/
function location_map_link_nl_providers() {
return array(
// 'google' => array('name' => 'Google Maps', 'url' => 'http://maps.google.com', 'tos' => 'http://www.google.com/help/terms_local.html'),
'himbuv' => array('name' => 'himbuv', 'url' => 'http://www.himbuv.com/postcode.htm', 'tos' => 'http://www.himbuv.com/postcode.htm')
);
}
function location_map_link_nl_default_providers() {
return array();
}
function location_map_link_nl_google($location = array()) {
$query_params = array();
foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) {
if (isset($location[$field])) {
$query_params[] = $location[$field];
}
}
if (count($query_params)) {
return ('http://maps.google.com?q='. urlencode(implode(", ", $query_params)));
}
else {
return NULL;
}
}
function location_map_link_nl_himbuv($location = array()) {
if (!isset($location['postal_code'])) {
return NULL;
}
return ('http://www.himbuv.com/cgi-bin/geo/post2degr.pl?postcode='. urlencode($location['postal_code']));
}
?>