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