]> git.openstreetmap.org Git - nominatim.git/blob - website/lookup.php
Merge pull request #447 from lonvia/fix-array-expression
[nominatim.git] / website / lookup.php
1 <?php
2         @define('CONST_ConnectionBucket_PageType', 'Reverse');
3
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
9         if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
10         {
11                 $fLoadAvg = getLoadAverage();
12                 if ($fLoadAvg > 2) sleep(60);
13                 if ($fLoadAvg > 4) sleep(120);
14                 if ($fLoadAvg > 6)
15                 {
16                         userError("Bulk User: Temporary block due to high server load");
17                         exit;
18                 }
19         }
20
21         $oDB =& getDB();
22         ini_set('memory_limit', '200M');
23
24         // Format for output
25         $sOutputFormat = 'xml';
26         if (isset($_GET['format']) && ($_GET['format'] == 'xml' || $_GET['format'] == 'json'))
27         {
28                 $sOutputFormat = $_GET['format'];
29         }
30
31         // Preferred language
32         $aLangPrefOrder = getPreferredLanguages();
33
34         $hLog = logStart($oDB, 'place', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
35
36         $aSearchResults = array();
37         $aCleanedQueryParts = array();
38         if (isset($_GET['osm_ids']))
39         {
40                 $oPlaceLookup = new PlaceLookup($oDB);
41                 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
42                 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
43                 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
44                 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
45                 
46                 $aOsmIds = explode(',', $_GET['osm_ids']);
47                 
48                 if ( count($aOsmIds) > CONST_Places_Max_ID_count ) 
49                 {
50                         userError('Bulk User: Only ' . CONST_Places_Max_ID_count . " ids are allowed in one request.");
51                         exit;
52                 }
53                 
54                 foreach ($aOsmIds AS $sItem) 
55                 {
56                         // Skip empty sItem
57                         if (empty($sItem)) continue;
58                         
59                         $sType = $sItem[0];
60                         $iId = (int) substr($sItem, 1);
61                         if ( $iId > 0 && ($sType == 'N' || $sType == 'W' || $sType == 'R') )
62                         {
63                                 $aCleanedQueryParts[] = $sType . $iId;
64                                 $oPlaceLookup->setOSMID($sType, $iId);
65                                 $oPlace = $oPlaceLookup->lookup();
66                                 if ($oPlace){
67                                         // we want to use the search-* output templates, so we need to fill
68                                         // $aSearchResults and slightly change the (reverse search) oPlace
69                                         // key names
70                                         $oResult = $oPlace;
71                                         unset($oResult['aAddress']);
72                                         if (isset($oPlace['aAddress'])) $oResult['address'] = $oPlace['aAddress'];
73                                         unset($oResult['langaddress']);
74                                         $oResult['name'] = $oPlace['langaddress'];
75                                         $aSearchResults[] = $oResult;
76                                 }
77                         }
78                 }
79         }
80
81
82         if (CONST_Debug) exit;
83
84         $sXmlRootTag = 'lookupresults';
85         $sQuery = join(',',$aCleanedQueryParts);
86         // we initialize these to avoid warnings in our logfile
87         $sViewBox = '';
88         $bShowPolygons = '';
89         $aExcludePlaceIDs = [];
90         $sMoreURL = '';
91
92         include(CONST_BasePath.'/lib/template/search-'.$sOutputFormat.'.php');