X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fgeoloc.inc.php;h=00e8fa979da05ff89c76a68ccda997ba0cc52a9a;hb=2553b7686e0678b8e27858a7c377e73ecb410aec;hp=e3ee25259965db94414277a63d2a6a46ac20c219;hpb=780422c5a6f5029a30db0d42fd93f67869ced3ee;p=platal.git diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index e3ee252..00e8fa9 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -1,6 +1,6 @@ geoloc->webservice_url."address.php?precise=1&txt=" . urlencode($txt); - if (!($f = @fopen($url, 'r'))) return false; + if ($globals->debug & DEBUG_BT) { + if (!isset(PlBacktrace::$bt['Geoloc'])) { + new PlBacktrace('Geoloc'); + } + PlBacktrace::$bt['Geoloc']->start($url); + } + $f = @fopen($url, 'r'); + if ($f === false) { + if ($globals->debug & DEBUG_BT) { + PlBacktrace::$bt['Geoloc']->stop(0, 'Can\'t fetch result'); + } + return false; + } $keys = explode('|',fgets($f)); $vals = explode('|',fgets($f)); + if ($globals->debug & DEBUG_BT) { + $data = array(); + for ($i = 0 ; $i < count($keys) ; ++$i) { + $data[] = array($keys[$i], $vals[$i]); + } + PlBacktrace::$bt['Geoloc']->stop(count($keys), null, $data); + } $infos = empty_address(); foreach ($keys as $i=>$key) { if($vals[$i]) { @@ -96,9 +116,21 @@ function get_address_infos($txt) if (empty($infos['country'])) { $infos['country'] = '00'; } - if (isset($infos['sql']) && $infos['sql']) - XDB::execute("REPLACE INTO geoloc_city - VALUES ".$infos['sql']); + if (isset($infos['sql']) && $infos['sql']) { + $sql = explode(', ', trim($infos['sql'], '()')); + if (count($sql) == 16) { + for ($i = 0 ; $i < 16 ; ++$i) { + $sql[$i] = stripslashes(trim($sql[$i], ' \'')); + } + XDB::execute("REPLACE INTO geoloc_city + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, + {?}, {?}, {?}, {?}, {?}, {?}, + {?}, {?}, {?}, {?})", + $sql[0], $sql[1], $sql[2], $sql[3], $sql[4], $sql[5], + $sql[6], $sql[7], $sql[8], $sql[9], $sql[10], $sql[11], + $sql[12], $sql[13], $sql[14], $sql[15]); + } + } if (isset($infos['display']) && $infos['display']) XDB::execute("UPDATE geoloc_pays SET display = {?}