Nominatim/website/search.php

142 lines
4.7 KiB
PHP
Raw Normal View History

2010-10-27 18:05:42 +04:00
<?php
@define('CONST_ConnectionBucket_PageType', 'Search');
2010-10-27 18:05:42 +04:00
require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
require_once(CONST_BasePath.'/lib/log.php');
require_once(CONST_BasePath.'/lib/Geocode.php');
2010-10-27 18:05:42 +04:00
ini_set('memory_limit', '200M');
2010-10-27 18:05:42 +04:00
$oDB =& getDB();
// Display defaults
$fLat = CONST_Default_Lat;
$fLon = CONST_Default_Lon;
$iZoom = CONST_Default_Zoom;
2013-08-27 20:21:20 +04:00
$oGeocode =& new Geocode($oDB);
$aLangPrefOrder = getPreferredLanguages();
$oGeocode->setLanguagePreference($aLangPrefOrder);
if (CONST_Search_ReversePlanForAll
|| isset($aLangPrefOrder['name:de'])
|| isset($aLangPrefOrder['name:ru'])
|| isset($aLangPrefOrder['name:ja'])
|| isset($aLangPrefOrder['name:pl']))
{
$oGeocode->setReverseInPlan(true);
}
2010-10-27 18:05:42 +04:00
// Format for output
2013-08-27 20:21:20 +04:00
$sOutputFormat = 'html';
2010-10-27 18:05:42 +04:00
if (isset($_GET['format']) && ($_GET['format'] == 'html' || $_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
{
$sOutputFormat = $_GET['format'];
}
// Show / use polygons
2013-04-13 00:45:24 +04:00
if ($sOutputFormat == 'html')
{
2013-08-28 16:42:05 +04:00
if (isset($_GET['polygon'])) $oGeocode->setIncludePolygonAsText((bool)$_GET['polygon']);
2013-04-13 00:45:24 +04:00
}
else
{
2013-08-27 20:21:20 +04:00
$bAsPoints = (boolean)isset($_GET['polygon']) && $_GET['polygon'];
$bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson'];
$bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml'];
$bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg'];
$bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text'];
2013-08-27 20:21:20 +04:00
if ( ( ($bAsGeoJSON?1:0)
+ ($bAsKML?1:0)
+ ($bAsSVG?1:0)
+ ($bAsText?1:0)
+ ($bAsPoints?1:0)
) > CONST_PolygonOutput_MaximumTypes)
2013-04-13 00:45:24 +04:00
{
if (CONST_PolygonOutput_MaximumTypes)
{
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
2013-04-13 00:45:24 +04:00
}
else
{
userError("Polygon output is disabled");
}
exit;
}
$oGeocode->setIncludePolygonAsPoints($bAsPoints);
2013-08-27 20:21:20 +04:00
$oGeocode->setIncludePolygonAsText($bAsText);
$oGeocode->setIncludePolygonAsGeoJSON($bAsGeoJSON);
$oGeocode->setIncludePolygonAsKML($bAsKML);
$oGeocode->setIncludePolygonAsSVG($bAsSVG);
}
2010-10-27 18:05:42 +04:00
// Polygon simplification threshold (optional)
$fThreshold = 0.0;
if (isset($_GET['polygon_threshold'])) $fThreshold = (float)$_GET['polygon_threshold'];
$oGeocode->setPolygonSimplificationThreshold($fThreshold);
$oGeocode->loadParamArray($_GET);
2010-10-27 18:05:42 +04:00
if (CONST_Search_BatchMode && isset($_GET['batch']))
2010-10-27 18:05:42 +04:00
{
2013-08-27 20:21:20 +04:00
$aBatch = json_decode($_GET['batch'], true);
2013-08-28 17:58:50 +04:00
$aBatchResults = array();
foreach($aBatch as $aBatchParams)
{
$oBatchGeocode = clone $oGeocode;
$oBatchGeocode->loadParamArray($aBatchParams);
$oBatchGeocode->setQueryFromParams($aBatchParams);
2013-08-28 17:58:50 +04:00
$aSearchResults = $oBatchGeocode->lookup();
$aBatchResults[] = $aSearchResults;
2010-10-27 18:05:42 +04:00
}
2013-08-28 17:58:50 +04:00
include(CONST_BasePath.'/lib/template/search-batch-json.php');
2013-08-27 20:21:20 +04:00
exit;
}
else
{
if (!(isset($_GET['q']) && $_GET['q']) && isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/')
{
$sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1);
// reverse order of '/' separated string
$aPhrases = explode('/', $sQuery);
$aPhrases = array_reverse($aPhrases);
$sQuery = join(', ',$aPhrases);
$oGeocode->setQuery($sQuery);
}
else
{
$oGeocode->setQueryFromParams($_GET);
}
}
2010-10-27 18:05:42 +04:00
2013-08-28 17:58:50 +04:00
$hLog = logStart($oDB, 'search', $oGeocode->getQueryString(), $aLangPrefOrder);
2013-08-27 20:21:20 +04:00
$aSearchResults = $oGeocode->lookup();
if ($aSearchResults === false) $aSearchResults = array();
$sDataDate = $oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1");
2010-10-27 18:05:42 +04:00
2013-08-27 20:21:20 +04:00
logEnd($oDB, $hLog, sizeof($aSearchResults));
2010-10-27 18:05:42 +04:00
2013-08-27 20:21:20 +04:00
$bAsText = $oGeocode->getIncludePolygonAsText();
$sQuery = $oGeocode->getQueryString();
2013-08-30 16:04:33 +04:00
$sViewBox = $oGeocode->getViewBoxString();
2013-09-02 17:10:00 +04:00
$bShowPolygons = (isset($_GET['polygon']) && $_GET['polygon']);
2013-08-30 16:04:33 +04:00
$aExcludePlaceIDs = $oGeocode->getExcludedPlaceIDs();
2013-08-27 20:21:20 +04:00
$sMoreURL = CONST_Website_BaseURL.'search.php?format='.urlencode($sOutputFormat).'&exclude_place_ids='.join(',',$oGeocode->getExcludedPlaceIDs());
2012-12-09 12:35:34 +04:00
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) $sMoreURL .= '&accept-language='.$_SERVER["HTTP_ACCEPT_LANGUAGE"];
2013-08-30 16:04:33 +04:00
if ($bShowPolygons) $sMoreURL .= '&polygon=1';
2013-08-27 20:21:20 +04:00
if ($oGeocode->getIncludeAddressDetails()) $sMoreURL .= '&addressdetails=1';
if ($oGeocode->getIncludeExtraTags()) $sMoreURL .= '&extratags=1';
if ($oGeocode->getIncludeNameDetails()) $sMoreURL .= '&namedetails=1';
2013-08-30 16:04:33 +04:00
if ($sViewBox) $sMoreURL .= '&viewbox='.urlencode($sViewBox);
2010-10-27 18:05:42 +04:00
if (isset($_GET['nearlat']) && isset($_GET['nearlon'])) $sMoreURL .= '&nearlat='.(float)$_GET['nearlat'].'&nearlon='.(float)$_GET['nearlon'];
$sMoreURL .= '&q='.urlencode($sQuery);
if (CONST_Debug) exit;
2010-11-15 19:34:27 +03:00
include(CONST_BasePath.'/lib/template/search-'.$sOutputFormat.'.php');