2 @define('CONST_ConnectionBucket_PageType', 'Reverse');
4 require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
5 require_once(CONST_BasePath.'/lib/log.php');
6 require_once(CONST_BasePath.'/lib/PlaceLookup.php');
8 if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
10 $fLoadAvg = getLoadAverage();
11 if ($fLoadAvg > 2) sleep(60);
12 if ($fLoadAvg > 4) sleep(120);
15 userError("Bulk User: Temporary block due to high server load");
21 ini_set('memory_limit', '200M');
24 $sOutputFormat = 'xml';
25 if (isset($_GET['format']) && ($_GET['format'] == 'xml' || $_GET['format'] == 'json'))
27 $sOutputFormat = $_GET['format'];
30 // Show address breakdown
31 $bShowAddressDetails = true;
32 if (isset($_GET['addressdetails'])) $bShowAddressDetails = (bool)$_GET['addressdetails'];
35 $aLangPrefOrder = getPreferredLanguages();
37 $hLog = logStart($oDB, 'place', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
39 $aSearchResults = array();
40 $aCleanedQueryParts = array();
41 if (isset($_GET['osm_ids']))
43 $oPlaceLookup = new PlaceLookup($oDB);
44 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
45 $oPlaceLookup->setIncludeAddressDetails($bShowAddressDetails);
47 $aOsmIds = explode(',', $_GET['osm_ids']);
49 if ( count($aOsmIds) > CONST_Places_Max_ID_count )
51 userError('Bulk User: Only ' . CONST_Places_Max_ID_count . " ids are allowed in one request.");
55 foreach ($aOsmIds AS $sItem)
58 if (empty($sItem)) continue;
61 $iId = (int) substr($sItem, 1);
62 if ( $iId > 0 && ($sType == 'N' || $sType == 'W' || $sType == 'R') )
64 $aCleanedQueryParts[] = $sType . $iId;
65 $oPlaceLookup->setOSMID($sType, $iId);
66 $oPlace = $oPlaceLookup->lookup();
68 // we want to use the search-* output templates, so we need to fill
69 // $aSearchResults and slightly change the (reverse search) oPlace
72 unset($oResult['aAddress']);
73 if (isset($oPlace['aAddress'])) $oResult['address'] = $oPlace['aAddress'];
74 unset($oResult['langaddress']);
75 $oResult['name'] = $oPlace['langaddress'];
76 $aSearchResults[] = $oResult;
83 if (CONST_Debug) exit;
85 $sXmlRootTag = 'lookupresults';
86 $sQuery = join(',',$aCleanedQueryParts);
87 // we initialize these to avoid warnings in our logfile
90 $aExcludePlaceIDs = [];
93 include(CONST_BasePath.'/lib/template/search-'.$sOutputFormat.'.php');