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