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