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