2010-10-27 18:05:42 +04:00
|
|
|
<?php
|
2012-12-09 01:39:24 +04:00
|
|
|
@define('CONST_ConnectionBucket_PageType', 'Search');
|
|
|
|
|
2016-03-09 02:07:46 +03:00
|
|
|
require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
|
|
|
|
require_once(CONST_BasePath.'/lib/init-website.php');
|
2010-10-27 18:05:42 +04:00
|
|
|
require_once(CONST_BasePath.'/lib/log.php');
|
2014-02-28 02:48:12 +04:00
|
|
|
require_once(CONST_BasePath.'/lib/Geocode.php');
|
2016-06-12 13:39:09 +03:00
|
|
|
require_once(CONST_BasePath.'/lib/output.php');
|
2010-10-27 18:05:42 +04:00
|
|
|
|
|
|
|
ini_set('memory_limit', '200M');
|
2012-12-12 05:44:39 +04:00
|
|
|
|
2010-10-27 18:05:42 +04:00
|
|
|
$oDB =& getDB();
|
|
|
|
|
2016-03-13 04:06:46 +03:00
|
|
|
$oGeocode = new Geocode($oDB);
|
2013-08-27 20:21:20 +04:00
|
|
|
|
|
|
|
$aLangPrefOrder = getPreferredLanguages();
|
|
|
|
$oGeocode->setLanguagePreference($aLangPrefOrder);
|
|
|
|
|
2015-08-11 23:30:07 +03:00
|
|
|
if (CONST_Search_ReversePlanForAll
|
|
|
|
|| isset($aLangPrefOrder['name:de'])
|
|
|
|
|| isset($aLangPrefOrder['name:ru'])
|
|
|
|
|| isset($aLangPrefOrder['name:ja'])
|
|
|
|
|| isset($aLangPrefOrder['name:pl']))
|
|
|
|
{
|
|
|
|
$oGeocode->setReverseInPlan(true);
|
|
|
|
}
|
2013-09-16 02:05:26 +04:00
|
|
|
|
2010-10-27 18:05:42 +04:00
|
|
|
// Format for output
|
2016-06-12 00:07:06 +03:00
|
|
|
$sOutputFormat = getParamSet('format', array('html', 'xml', 'json', 'jsonv2'), 'html');
|
2010-10-27 18:05:42 +04:00
|
|
|
|
|
|
|
// Show / use polygons
|
2013-04-13 00:45:24 +04:00
|
|
|
if ($sOutputFormat == 'html')
|
|
|
|
{
|
2016-06-12 00:07:06 +03:00
|
|
|
$oGeocode->setIncludePolygonAsText(getParamBool('polygon'));
|
2013-04-13 00:45:24 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-12 00:07:06 +03:00
|
|
|
$bAsPoints = getParamBool('polygon');
|
|
|
|
$bAsGeoJSON = getParamBool('polygon_geojson');
|
|
|
|
$bAsKML = getParamBool('polygon_kml');
|
|
|
|
$bAsSVG = getParamBool('polygon_svg');
|
|
|
|
$bAsText = getParamBool('polygon_text');
|
2013-08-27 20:21:20 +04:00
|
|
|
if ( ( ($bAsGeoJSON?1:0)
|
2016-01-19 14:29:07 +03:00
|
|
|
+ ($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)
|
|
|
|
{
|
2012-11-10 01:35:45 +04:00
|
|
|
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
|
2013-04-13 00:45:24 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-10 01:35:45 +04:00
|
|
|
userError("Polygon output is disabled");
|
|
|
|
}
|
|
|
|
exit;
|
2012-11-06 17:10:25 +04:00
|
|
|
}
|
2013-09-02 19:44:40 +04:00
|
|
|
$oGeocode->setIncludePolygonAsPoints($bAsPoints);
|
2013-08-27 20:21:20 +04:00
|
|
|
$oGeocode->setIncludePolygonAsText($bAsText);
|
|
|
|
$oGeocode->setIncludePolygonAsGeoJSON($bAsGeoJSON);
|
|
|
|
$oGeocode->setIncludePolygonAsKML($bAsKML);
|
|
|
|
$oGeocode->setIncludePolygonAsSVG($bAsSVG);
|
2012-11-06 17:06:46 +04:00
|
|
|
}
|
2010-10-27 18:05:42 +04:00
|
|
|
|
2015-04-29 17:13:39 +03:00
|
|
|
// Polygon simplification threshold (optional)
|
2016-06-12 00:07:06 +03:00
|
|
|
$oGeocode->setPolygonSimplificationThreshold(getParamFloat('polygon_threshold', 0.0));
|
2015-04-29 17:13:39 +03:00
|
|
|
|
2014-02-28 02:48:12 +04:00
|
|
|
$oGeocode->loadParamArray($_GET);
|
2010-10-27 18:05:42 +04:00
|
|
|
|
2013-09-12 19:16:00 +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;
|
2014-02-28 02:48:12 +04:00
|
|
|
$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;
|
2016-01-19 14:29:07 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-12 00:07:06 +03:00
|
|
|
if (!getParamString('q') && isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'][0] == '/')
|
2016-01-19 14:29:07 +03:00
|
|
|
{
|
2016-03-02 03:22:19 +03:00
|
|
|
$sQuery = substr(rawurldecode($_SERVER['PATH_INFO']), 1);
|
2016-01-19 14:29:07 +03:00
|
|
|
|
2016-03-02 03:22:19 +03:00
|
|
|
// reverse order of '/' separated string
|
|
|
|
$aPhrases = explode('/', $sQuery);
|
|
|
|
$aPhrases = array_reverse($aPhrases);
|
|
|
|
$sQuery = join(', ',$aPhrases);
|
|
|
|
$oGeocode->setQuery($sQuery);
|
2016-01-19 14:29:07 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-02 03:22:19 +03:00
|
|
|
$oGeocode->setQueryFromParams($_GET);
|
2016-01-19 14:29:07 +03:00
|
|
|
}
|
|
|
|
}
|
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();
|
|
|
|
|
2016-03-02 03:22:19 +03:00
|
|
|
if ($sOutputFormat=='html')
|
|
|
|
{
|
2016-06-12 15:34:57 +03:00
|
|
|
$sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate - '2 minutes'::interval,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
|
2016-03-02 03:22:19 +03: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
|
|
|
|
2015-08-12 00:09:50 +03: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';
|
2015-08-10 22:42:40 +03:00
|
|
|
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');
|