mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-15 07:24:09 +00:00
harmonize formatting of frontend php
This commit is contained in:
51
lib/lib.php
51
lib/lib.php
@@ -11,10 +11,12 @@
|
||||
if (CONST_Debug)
|
||||
{
|
||||
echo "<hr><h2>Debugging Information</h2><br>";
|
||||
if ($sSQL) {
|
||||
if ($sSQL)
|
||||
{
|
||||
echo "<h3>SQL query</h3><code>".$sSQL."</code>";
|
||||
}
|
||||
if ($vDumpVar) {
|
||||
if ($vDumpVar)
|
||||
{
|
||||
echo "<h3>Result</h3> <code>";
|
||||
var_dump($vDumpVar);
|
||||
echo "</code>";
|
||||
@@ -22,9 +24,9 @@
|
||||
}
|
||||
echo "\n</body></html>\n";
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function userError($sError)
|
||||
{
|
||||
header('HTTP/1.0 400 Bad Request');
|
||||
@@ -35,9 +37,9 @@
|
||||
echo '<p>If you feel this error is incorrect feel free to report the bug in the <a href="http://trac.openstreetmap.org">OSM bug database</a>. Please include the error message above and the URL you used.</p>';
|
||||
echo "\n</body></html>\n";
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fail($sError, $sUserError = false)
|
||||
{
|
||||
if (!$sUserError) $sUserError = $sError;
|
||||
@@ -46,6 +48,7 @@
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function getBlockingProcesses()
|
||||
{
|
||||
$sStats = file_get_contents('/proc/stat');
|
||||
@@ -56,6 +59,7 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
function getLoadAverage()
|
||||
{
|
||||
$sLoadAverage = file_get_contents('/proc/loadavg');
|
||||
@@ -63,6 +67,7 @@
|
||||
return (float)$aLoadAverage[0];
|
||||
}
|
||||
|
||||
|
||||
function getProcessorCount()
|
||||
{
|
||||
$sCPU = file_get_contents('/proc/cpuinfo');
|
||||
@@ -70,6 +75,7 @@
|
||||
return sizeof($aMatches[0]);
|
||||
}
|
||||
|
||||
|
||||
function getTotalMemoryMB()
|
||||
{
|
||||
$sCPU = file_get_contents('/proc/meminfo');
|
||||
@@ -77,6 +83,7 @@
|
||||
return (int)($aMatches[1]/1024);
|
||||
}
|
||||
|
||||
|
||||
function getCacheMemoryMB()
|
||||
{
|
||||
$sCPU = file_get_contents('/proc/meminfo');
|
||||
@@ -84,12 +91,14 @@
|
||||
return (int)($aMatches[1]/1024);
|
||||
}
|
||||
|
||||
|
||||
function bySearchRank($a, $b)
|
||||
{
|
||||
if ($a['iSearchRank'] == $b['iSearchRank']) return 0;
|
||||
return ($a['iSearchRank'] < $b['iSearchRank']?-1:1);
|
||||
}
|
||||
|
||||
|
||||
function byImportance($a, $b)
|
||||
{
|
||||
if ($a['importance'] != $b['importance'])
|
||||
@@ -107,6 +116,7 @@
|
||||
return ($a['foundorder'] < $b['foundorder']?-1:1);
|
||||
}
|
||||
|
||||
|
||||
function getPreferredLanguages()
|
||||
{
|
||||
// If we have been provided the value in $_GET it overrides browser value
|
||||
@@ -116,7 +126,8 @@
|
||||
}
|
||||
|
||||
$aLanguages = array();
|
||||
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
|
||||
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
|
||||
{
|
||||
if (preg_match_all('/(([a-z]{1,8})(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $aLanguagesParse, PREG_SET_ORDER))
|
||||
{
|
||||
foreach($aLanguagesParse as $iLang => $aLanguage)
|
||||
@@ -153,6 +164,7 @@
|
||||
return $aLangPrefOrder;
|
||||
}
|
||||
|
||||
|
||||
function getWordSets($aWords)
|
||||
{
|
||||
$aResult = array(array(join(' ',$aWords)));
|
||||
@@ -170,6 +182,7 @@
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
|
||||
function getTokensFromSets($aSets)
|
||||
{
|
||||
$aTokens = array();
|
||||
@@ -185,6 +198,7 @@
|
||||
return $aTokens;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
GB Postcode functions
|
||||
*/
|
||||
@@ -216,6 +230,7 @@
|
||||
return abs(($aValues[$s1[0]]*21+$aValues[$s1[1]]) - ($aValues[$s2[0]]*21+$aValues[$s2[1]]));
|
||||
}
|
||||
|
||||
|
||||
function gbPostcodeCalculate($sPostcode, $sPostcodeSector, $sPostcodeEnd, &$oDB)
|
||||
{
|
||||
// Try an exact match on the gb_postcode table
|
||||
@@ -235,6 +250,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function usPostcodeCalculate($sPostcode, &$oDB)
|
||||
{
|
||||
$iZipcode = (int)$sPostcode;
|
||||
@@ -294,6 +310,7 @@
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
function getClassTypes()
|
||||
{
|
||||
return array(
|
||||
@@ -600,6 +617,7 @@
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function getClassTypesWithImportance()
|
||||
{
|
||||
$aOrders = getClassTypes();
|
||||
@@ -611,25 +629,31 @@
|
||||
return $aOrders;
|
||||
}
|
||||
|
||||
|
||||
function javascript_renderData($xVal)
|
||||
{
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
|
||||
$jsonout = json_encode($xVal);
|
||||
|
||||
if( ! isset($_GET['json_callback'])) {
|
||||
if( ! isset($_GET['json_callback']))
|
||||
{
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
echo $jsonout;
|
||||
} else {
|
||||
if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u',$_GET['json_callback'])) {
|
||||
} else
|
||||
{
|
||||
if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u',$_GET['json_callback']))
|
||||
{
|
||||
header("Content-Type: application/javascript; charset=UTF-8");
|
||||
echo $_GET['json_callback'].'('.$jsonout.')';
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
header('HTTP/1.0 400 Bad Request');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function _debugDumpGroupedSearches($aData, $aTokens)
|
||||
{
|
||||
$aWordsIDs = array();
|
||||
@@ -713,7 +737,7 @@
|
||||
function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCode = false, $bRaw = false)
|
||||
{
|
||||
$sSQL = "select *,get_name_by_language(name,$sLanguagePrefArraySQL) as localname from get_addressdata($iPlaceID)";
|
||||
IF (!$bRaw) $sSQL .= " WHERE isaddress OR type = 'country_code'";
|
||||
if (!$bRaw) $sSQL .= " WHERE isaddress OR type = 'country_code'";
|
||||
$sSQL .= " order by rank_address desc,isaddress desc";
|
||||
|
||||
$aAddressLines = $oDB->getAll($sSQL);
|
||||
@@ -758,6 +782,7 @@
|
||||
return $aAddress;
|
||||
}
|
||||
|
||||
|
||||
function getWordSuggestions(&$oDB, $sWord)
|
||||
{
|
||||
$sWordQuoted = getDBQuoted(trim($sWord));
|
||||
@@ -771,6 +796,7 @@
|
||||
return $aSimilar;
|
||||
}
|
||||
|
||||
|
||||
function geocodeReverse($fLat, $fLon, $iZoom=18)
|
||||
{
|
||||
$oDB =& getDB();
|
||||
@@ -876,7 +902,8 @@
|
||||
$sValue = trim($_GET[$sKey]);
|
||||
if (!$sValue) return false;
|
||||
$aStructuredQuery[$sKey] = $sValue;
|
||||
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30) {
|
||||
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30)
|
||||
{
|
||||
$iMinAddressRank = $iNewMinAddressRank;
|
||||
$iMaxAddressRank = $iNewMaxAddressRank;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,8 @@
|
||||
// The point we found might be too small - use the address to find what it is a child of
|
||||
if ($iPlaceID && $iMaxRank < 28)
|
||||
{
|
||||
if ($aPlace['rank_search'] > 28 && $iParentPlaceID) {
|
||||
if ($aPlace['rank_search'] > 28 && $iParentPlaceID)
|
||||
{
|
||||
$iPlaceID = $iParentPlaceID;
|
||||
}
|
||||
$sSQL = "select address_place_id from place_addressline where place_id = $iPlaceID order by abs(cached_rank_address - $iMaxRank) asc,cached_rank_address desc,isaddress desc,distance desc limit 1";
|
||||
|
||||
@@ -37,13 +37,16 @@
|
||||
|
||||
// Show / use polygons
|
||||
$bShowPolygons = (boolean)isset($_GET['polygon']) && $_GET['polygon'];
|
||||
if ($sOutputFormat == 'html') {
|
||||
if ($sOutputFormat == 'html')
|
||||
{
|
||||
$bAsText = $bShowPolygons;
|
||||
$bShowPolygons = false;
|
||||
$bAsGeoJSON = false;
|
||||
$bAsKML = false;
|
||||
$bAsSVG = false;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$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'];
|
||||
@@ -53,10 +56,14 @@
|
||||
+ ($bAsKML?1:0)
|
||||
+ ($bAsSVG?1:0)
|
||||
+ ($bAsText?1:0)
|
||||
) > CONST_PolygonOutput_MaximumTypes) {
|
||||
if (CONST_PolygonOutput_MaximumTypes) {
|
||||
) > CONST_PolygonOutput_MaximumTypes)
|
||||
{
|
||||
if (CONST_PolygonOutput_MaximumTypes)
|
||||
{
|
||||
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
userError("Polygon output is disabled");
|
||||
}
|
||||
exit;
|
||||
@@ -138,7 +145,8 @@
|
||||
$sValue = trim($_GET[$sKey]);
|
||||
if (!$sValue) return false;
|
||||
$aStructuredQuery[$sKey] = $sValue;
|
||||
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30) {
|
||||
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30)
|
||||
{
|
||||
$iMinAddressRank = $iNewMinAddressRank;
|
||||
$iMaxAddressRank = $iNewMaxAddressRank;
|
||||
}
|
||||
@@ -161,7 +169,8 @@
|
||||
{
|
||||
loadStructuredAddressElement($aStructuredQuery, $iMinAddressRank, $iMaxAddressRank, $_GET, $aStructuredOption[0], $aStructuredOption[1], $aStructuredOption[2]);
|
||||
}
|
||||
if (sizeof($aStructuredQuery) > 0) {
|
||||
if (sizeof($aStructuredQuery) > 0)
|
||||
{
|
||||
$sQuery = join(', ', $aStructuredQuery);
|
||||
if ($iMaxAddressRank < 30)
|
||||
{
|
||||
@@ -201,7 +210,9 @@
|
||||
$aCoOrdinates[1] += $fWidth;
|
||||
$aCoOrdinates[3] -= $fWidth;
|
||||
$sViewboxLargeSQL = "ST_SetSRID(ST_MakeBox2D(ST_Point(".(float)$aCoOrdinates[0].",".(float)$aCoOrdinates[1]."),ST_Point(".(float)$aCoOrdinates[2].",".(float)$aCoOrdinates[3].")),4326)";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$bBoundingBoxSearch = false;
|
||||
}
|
||||
if (isset($_GET['route']) && $_GET['route'] && isset($_GET['routewidth']) && $_GET['routewidth'])
|
||||
@@ -404,10 +415,8 @@
|
||||
if (CONST_Debug) var_Dump($sSQL);
|
||||
|
||||
$aValidTokens = array();
|
||||
if (sizeof($aTokens))
|
||||
$aDatabaseWords = $oDB->getAll($sSQL);
|
||||
else
|
||||
$aDatabaseWords = array();
|
||||
if (sizeof($aTokens)) $aDatabaseWords = $oDB->getAll($sSQL);
|
||||
else $aDatabaseWords = array();
|
||||
if (PEAR::IsError($aDatabaseWords))
|
||||
{
|
||||
failInternalError("Could not get word tokens.", $sSQL, $aDatabaseWords);
|
||||
@@ -701,14 +710,8 @@
|
||||
foreach($aNewPhraseSearches as $iSearch => $aSearch)
|
||||
{
|
||||
$sHash = serialize($aSearch);
|
||||
if (isset($aSearchHash[$sHash]))
|
||||
{
|
||||
unset($aNewPhraseSearches[$iSearch]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$aSearchHash[$sHash] = 1;
|
||||
}
|
||||
if (isset($aSearchHash[$sHash])) unset($aNewPhraseSearches[$iSearch]);
|
||||
else $aSearchHash[$sHash] = 1;
|
||||
}
|
||||
|
||||
$aNewPhraseSearches = array_slice($aNewPhraseSearches, 0, 50);
|
||||
@@ -963,7 +966,6 @@
|
||||
if (sizeof($aSearch['aFullNameAddress']))
|
||||
$aOrder[] = '(select count(*) from (select unnest(ARRAY['.join($aSearch['aFullNameAddress'],",").']) INTERSECT select unnest(nameaddress_vector))s) DESC';
|
||||
|
||||
|
||||
if (sizeof($aTerms))
|
||||
{
|
||||
$sSQL = "select place_id";
|
||||
@@ -1051,7 +1053,6 @@
|
||||
if ($aSearch['sClass'] && sizeof($aPlaceIDs))
|
||||
{
|
||||
$sPlaceIDs = join(',',$aPlaceIDs);
|
||||
|
||||
$aClassPlaceIDs = array();
|
||||
|
||||
if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'name')
|
||||
@@ -1380,7 +1381,8 @@
|
||||
if ($bAsSVG) $aResult['assvg'] = $aPointPolygon['assvg'];
|
||||
if ($bAsText) $aResult['astext'] = $aPointPolygon['astext'];
|
||||
|
||||
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null ) {
|
||||
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null )
|
||||
{
|
||||
$aResult['lat'] = $aPointPolygon['centrelat'];
|
||||
$aResult['lon'] = $aPointPolygon['centrelon'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user