Small improvement
[platal.git] / include / geoloc.inc.php
index c23da8c..77399e5 100644 (file)
@@ -76,7 +76,16 @@ function get_address_infos($txt) {
     $keys = explode('|',fgets($f));
     $vals = explode('|',fgets($f));
     $infos = array();
-    foreach ($keys as $i=>$key) if($vals[$i]) $infos[$key] = ($key == 'sql')?$vals[$i]:utf8_decode(strtr($vals[$i], array(chr(197).chr(147) => "œ")));
+    foreach ($keys as $i=>$key) {
+        if($vals[$i]) {
+            if ($key == 'sql') {
+                $infos[$key] = $vals[$i];
+            } else {
+                $val = strtr($vals[$i], array(chr(197).chr(147) => "œ"));
+                $infos[$key] = (iconv('utf-8', 'utf-8', $val) == $val)  ? utf8_decode($val) : $val;
+            }
+        }
+    }
     if ($infos['sql'])
        XDB::execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']);
     if ($infos['display'])
@@ -127,6 +136,7 @@ function get_new_maps($url)
     XDB::execute('INSERT INTO geoloc_maps VALUES '.substr($s, 1));
     return true;
 }
+// }}}
 
 // {{{ get_address_text($adr)
 /** make the text of an address that can be read by a mailman
@@ -350,6 +360,8 @@ function geoloc_getData_subcountries($mapid, $SFields, $minentities) {
         FROM    geoloc_maps AS gm
         ".$wheremapid, Env::v('mapid',''));
 
+    global $globals;
+
     while ($c = $submapres->next())
     {
         $country = $c;