2 @define('CONST_ConnectionBucket_PageType', 'Reverse');
4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-website.php');
6 require_once(CONST_BasePath.'/lib/log.php');
7 require_once(CONST_BasePath.'/lib/PlaceLookup.php');
8 require_once(CONST_BasePath.'/lib/output.php');
10 if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
12 $fLoadAvg = getLoadAverage();
13 if ($fLoadAvg > 2) sleep(60);
14 if ($fLoadAvg > 4) sleep(120);
17 userError("Bulk User: Temporary block due to high server load");
23 ini_set('memory_limit', '200M');
26 $sOutputFormat = getParamSet('format', array('xml', 'json'), 'xml');
29 $aLangPrefOrder = getPreferredLanguages();
31 $hLog = logStart($oDB, 'place', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
33 $aSearchResults = array();
34 $aCleanedQueryParts = array();
36 $oPlaceLookup = new PlaceLookup($oDB);
37 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
38 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
39 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
40 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
42 $aOsmIds = explode(',', getParamString('osm_ids', ''));
44 if (count($aOsmIds) > CONST_Places_Max_ID_count)
46 userError('Bulk User: Only ' . CONST_Places_Max_ID_count . " ids are allowed in one request.");
49 foreach ($aOsmIds AS $sItem)
52 if (empty($sItem)) continue;
55 $iId = (int) substr($sItem, 1);
56 if ( $iId > 0 && ($sType == 'N' || $sType == 'W' || $sType == 'R') )
58 $aCleanedQueryParts[] = $sType . $iId;
59 $oPlaceLookup->setOSMID($sType, $iId);
60 $oPlace = $oPlaceLookup->lookup();
62 // we want to use the search-* output templates, so we need to fill
63 // $aSearchResults and slightly change the (reverse search) oPlace
66 unset($oResult['aAddress']);
67 if (isset($oPlace['aAddress'])) $oResult['address'] = $oPlace['aAddress'];
68 unset($oResult['langaddress']);
69 $oResult['name'] = $oPlace['langaddress'];
70 $aSearchResults[] = $oResult;
76 if (CONST_Debug) exit;
78 $sXmlRootTag = 'lookupresults';
79 $sQuery = join(',',$aCleanedQueryParts);
80 // we initialize these to avoid warnings in our logfile
83 $aExcludePlaceIDs = [];
86 include(CONST_BasePath.'/lib/template/search-'.$sOutputFormat.'.php');