]> git.openstreetmap.org Git - nominatim.git/blob - website/reverse.php
more tests for libphp - incorporate lonvias feedback
[nominatim.git] / website / reverse.php
1 <?php
2         @define('CONST_ConnectionBucket_PageType', 'Reverse');
3
4         require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
5         require_once(CONST_BasePath.'/lib/log.php');
6         require_once(CONST_BasePath.'/lib/PlaceLookup.php');
7         require_once(CONST_BasePath.'/lib/ReverseGeocode.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                         echo "Bulk User: Temporary block due to high server load\n";
17                         exit;
18                 }
19         }
20
21         $oDB =& getDB();
22         ini_set('memory_limit', '200M');
23
24         // Format for output
25         $sOutputFormat = 'xml';
26         if (isset($_GET['format']) && ($_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
27         {
28                 $sOutputFormat = $_GET['format'];
29         }
30
31         // Preferred language
32         $aLangPrefOrder = getPreferredLanguages();
33
34         $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
35
36
37         if (isset($_GET['osm_type']) && isset($_GET['osm_id']) && (int)$_GET['osm_id'] && ($_GET['osm_type'] == 'N' || $_GET['osm_type'] == 'W' || $_GET['osm_type'] == 'R'))
38         {
39                 $aLookup = array('osm_type' => $_GET['osm_type'], 'osm_id' => $_GET['osm_id']);
40         }
41         else if (isset($_GET['lat']) && isset($_GET['lon']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lat']) && preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET['lon']))
42         {
43                 $oReverseGeocode = new ReverseGeocode($oDB);
44                 $oReverseGeocode->setLanguagePreference($aLangPrefOrder);
45
46                 $oReverseGeocode->setLatLon($_GET['lat'], $_GET['lon']);
47                 $oReverseGeocode->setZoom(@$_GET['zoom']);
48
49                 $aLookup = $oReverseGeocode->lookup();
50                 if (CONST_Debug) var_dump($aLookup);
51         }
52         else
53         {
54                 $aLookup = null;
55         }
56
57         if ($aLookup)
58         {
59                 $oPlaceLookup = new PlaceLookup($oDB);
60                 $oPlaceLookup->setLanguagePreference($aLangPrefOrder);
61                 $oPlaceLookup->setIncludeAddressDetails(getParamBool('addressdetails', true));
62                 $oPlaceLookup->setIncludeExtraTags(getParamBool('extratags', false));
63                 $oPlaceLookup->setIncludeNameDetails(getParamBool('namedetails', false));
64
65                 $aPlace = $oPlaceLookup->lookupPlace($aLookup);
66         }
67         else
68         {
69                 $aPlace = null;
70         }
71
72
73         if (CONST_Debug)
74         {
75                 var_dump($aPlace);
76                 exit;
77         }
78
79         include(CONST_BasePath.'/lib/template/address-'.$sOutputFormat.'.php');