X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fgeoloc.inc.php;h=ea905100c44b9e6d15fbcd49d69a6c00be211c83;hb=90eba1aa65266aebb3234beff3db11d084cc55b3;hp=c23f7266660847fe33d22741d2435a2513c5488b;hpb=edfc872d991eb77da9da22cad52636ab9cbfa014;p=platal.git diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index c23f726..ea90510 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -64,6 +64,16 @@ function _geoloc_region_smarty($params){ $GLOBALS['page']->register_function('geoloc_region', '_geoloc_region_smarty'); // }}} +function geoloc_is_utf8($text) +{ + return (iconv('utf-8', 'utf-8', $text) == $text); +} + +function geoloc_utf8_decode($text) +{ + return geoloc_is_utf8($text) ? utf8_decode($text) : $text; +} + // {{{ get_address_infos($txt) /** retrieve the infos on a text address * store on the fly the info of the city concerned @@ -76,11 +86,21 @@ 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] = geoloc_utf8_decode($val); + } + } + } if ($infos['sql']) XDB::execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']); if ($infos['display']) - XDB::execute("UPDATE geoloc_pays SET display = {?} WHERE a2 = {?}", $infos['display'], $infos['country']); + XDB::execute("UPDATE geoloc_pays SET display = {?} WHERE a2 = {?}", $infos['display'], $infos['country']); + fix_cities_not_on_map(1, $infos['cityid']); return $infos; } // }}} @@ -127,6 +147,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 @@ -258,9 +279,9 @@ function localize_addresses($uid) { // }}} // {{{ function fix_cities_not_on_map($limit) -function fix_cities_not_on_map($limit=false) +function fix_cities_not_on_map($limit=false, $cityid=false) { - $missing = XDB::query("SELECT c.id FROM geoloc_city AS c LEFT JOIN geoloc_city_in_maps AS m ON(c.id = m.city_id) WHERE m.city_id IS NULL".($limit?" LIMIT $limit":"")); + $missing = XDB::query("SELECT c.id FROM geoloc_city AS c LEFT JOIN geoloc_city_in_maps AS m ON(c.id = m.city_id) WHERE m.city_id IS NULL".($cityid?(" AND c.id = '".$cityid."'"):"").($limit?" LIMIT $limit":"")); $maps = get_cities_maps($missing->fetchColumn()); if ($maps) { @@ -329,6 +350,10 @@ function geoloc_getData_subcities($mapid, $SFields, &$cities, $direct=true) { if ($c['pop'] > 0) { $city = $c; + // $city['name'] = geoloc_utf8_decode($city['name']); + if (!geoloc_is_utf8($city['name'])) { + $city['name'] = utf8_encode($city['name']); + } $city['x'] = geoloc_to_x($c['x'], $c['y']); $city['y'] = geoloc_to_y($c['x'], $c['y']); $city['size'] = size_of_city($c['pop']);