]> git.openstreetmap.org Git - nominatim.git/blob - website/lookup.php
Merge pull request #506 from mtmail/primary-vagrant-vm
[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         require_once(CONST_BasePath.'/lib/output.php');
9
10         $oDB =& getDB();
11         ini_set('memory_limit', '200M');
12
13         // Format for output
14         $sOutputFormat = getParamSet('format', array('xml', 'json'), 'xml');
15
16         // Preferred language
17         $aLangPrefOrder = getPreferredLanguages();
18
19         $hLog = logStart($oDB, 'place', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
20
21         $aSearchResults = array();
22         $aCleanedQueryParts = array();
23
24         $oPlaceLookup = new PlaceLookup($oDB);
25         $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
26         $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
27         $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
28         $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
29
30         $aOsmIds = explode(',', getParamString('osm_ids', ''));
31
32         if (count($aOsmIds) > CONST_Places_Max_ID_count)
33         {
34                 userError('Bulk User: Only ' . CONST_Places_Max_ID_count . " ids are allowed in one request.");
35         }
36
37         foreach ($aOsmIds AS $sItem)
38         {
39                 // Skip empty sItem
40                 if (empty($sItem)) continue;
41                 
42                 $sType = $sItem[0];
43                 $iId = (int) substr($sItem, 1);
44                 if ( $iId > 0 && ($sType == 'N' || $sType == 'W' || $sType == 'R') )
45                 {
46                         $aCleanedQueryParts[] = $sType . $iId;
47                         $oPlace = $oPlaceLookup->lookupOSMID($sType, $iId);
48                         if ($oPlace){
49                                 // we want to use the search-* output templates, so we need to fill
50                                 // $aSearchResults and slightly change the (reverse search) oPlace
51                                 // key names
52                                 $oResult = $oPlace;
53                                 unset($oResult['aAddress']);
54                                 if (isset($oPlace['aAddress'])) $oResult['address'] = $oPlace['aAddress'];
55                                 unset($oResult['langaddress']);
56                                 $oResult['name'] = $oPlace['langaddress'];
57                                 $aSearchResults[] = $oResult;
58                         }
59                 }
60         }
61
62
63         if (CONST_Debug) exit;
64
65         $sXmlRootTag = 'lookupresults';
66         $sQuery = join(',',$aCleanedQueryParts);
67         // we initialize these to avoid warnings in our logfile
68         $sViewBox = '';
69         $bShowPolygons = '';
70         $aExcludePlaceIDs = [];
71         $sMoreURL = '';
72
73         include(CONST_BasePath.'/lib/template/search-'.$sOutputFormat.'.php');