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