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