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');
9 if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
11 $fLoadAvg = getLoadAverage();
12 if ($fLoadAvg > 2) sleep(60);
13 if ($fLoadAvg > 4) sleep(120);
16 userError("Bulk User: Temporary block due to high server load");
22 ini_set('memory_limit', '200M');
25 $sOutputFormat = getParamSet('format', array('xml', 'json'), 'xml');
28 $aLangPrefOrder = getPreferredLanguages();
30 $hLog = logStart($oDB, 'place', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
32 $aSearchResults = array();
33 $aCleanedQueryParts = array();
35 $oPlaceLookup = new PlaceLookup($oDB);
36 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
37 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
38 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
39 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
41 $aOsmIds = explode(',', $getParamString('osm_ids', ''));
43 if (count($aOsmIds) > CONST_Places_Max_ID_count)
45 userError('Bulk User: Only ' . CONST_Places_Max_ID_count . " ids are allowed in one request.");
48 foreach ($aOsmIds AS $sItem)
51 if (empty($sItem)) continue;
54 $iId = (int) substr($sItem, 1);
55 if ( $iId > 0 && ($sType == 'N' || $sType == 'W' || $sType == 'R') )
57 $aCleanedQueryParts[] = $sType . $iId;
58 $oPlaceLookup->setOSMID($sType, $iId);
59 $oPlace = $oPlaceLookup->lookup();
61 // we want to use the search-* output templates, so we need to fill
62 // $aSearchResults and slightly change the (reverse search) oPlace
65 unset($oResult['aAddress']);
66 if (isset($oPlace['aAddress'])) $oResult['address'] = $oPlace['aAddress'];
67 unset($oResult['langaddress']);
68 $oResult['name'] = $oPlace['langaddress'];
69 $aSearchResults[] = $oResult;
75 if (CONST_Debug) exit;
77 $sXmlRootTag = 'lookupresults';
78 $sQuery = join(',',$aCleanedQueryParts);
79 // we initialize these to avoid warnings in our logfile
82 $aExcludePlaceIDs = [];
85 include(CONST_BasePath.'/lib/template/search-'.$sOutputFormat.'.php');