harmonize formatting of frontend php

This commit is contained in:
Sarah Hoffmann
2013-04-12 22:45:24 +02:00
parent 01bcb59e44
commit fb0d219c7b
7 changed files with 868 additions and 838 deletions

View File

@@ -11,10 +11,12 @@
if (CONST_Debug) if (CONST_Debug)
{ {
echo "<hr><h2>Debugging Information</h2><br>"; echo "<hr><h2>Debugging Information</h2><br>";
if ($sSQL) { if ($sSQL)
{
echo "<h3>SQL query</h3><code>".$sSQL."</code>"; echo "<h3>SQL query</h3><code>".$sSQL."</code>";
} }
if ($vDumpVar) { if ($vDumpVar)
{
echo "<h3>Result</h3> <code>"; echo "<h3>Result</h3> <code>";
var_dump($vDumpVar); var_dump($vDumpVar);
echo "</code>"; echo "</code>";
@@ -22,9 +24,9 @@
} }
echo "\n</body></html>\n"; echo "\n</body></html>\n";
exit; exit;
} }
function userError($sError) function userError($sError)
{ {
header('HTTP/1.0 400 Bad Request'); 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 '<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"; echo "\n</body></html>\n";
exit; exit;
} }
function fail($sError, $sUserError = false) function fail($sError, $sUserError = false)
{ {
if (!$sUserError) $sUserError = $sError; if (!$sUserError) $sUserError = $sError;
@@ -46,6 +48,7 @@
exit; exit;
} }
function getBlockingProcesses() function getBlockingProcesses()
{ {
$sStats = file_get_contents('/proc/stat'); $sStats = file_get_contents('/proc/stat');
@@ -56,6 +59,7 @@
return 0; return 0;
} }
function getLoadAverage() function getLoadAverage()
{ {
$sLoadAverage = file_get_contents('/proc/loadavg'); $sLoadAverage = file_get_contents('/proc/loadavg');
@@ -63,6 +67,7 @@
return (float)$aLoadAverage[0]; return (float)$aLoadAverage[0];
} }
function getProcessorCount() function getProcessorCount()
{ {
$sCPU = file_get_contents('/proc/cpuinfo'); $sCPU = file_get_contents('/proc/cpuinfo');
@@ -70,6 +75,7 @@
return sizeof($aMatches[0]); return sizeof($aMatches[0]);
} }
function getTotalMemoryMB() function getTotalMemoryMB()
{ {
$sCPU = file_get_contents('/proc/meminfo'); $sCPU = file_get_contents('/proc/meminfo');
@@ -77,6 +83,7 @@
return (int)($aMatches[1]/1024); return (int)($aMatches[1]/1024);
} }
function getCacheMemoryMB() function getCacheMemoryMB()
{ {
$sCPU = file_get_contents('/proc/meminfo'); $sCPU = file_get_contents('/proc/meminfo');
@@ -84,12 +91,14 @@
return (int)($aMatches[1]/1024); return (int)($aMatches[1]/1024);
} }
function bySearchRank($a, $b) function bySearchRank($a, $b)
{ {
if ($a['iSearchRank'] == $b['iSearchRank']) return 0; if ($a['iSearchRank'] == $b['iSearchRank']) return 0;
return ($a['iSearchRank'] < $b['iSearchRank']?-1:1); return ($a['iSearchRank'] < $b['iSearchRank']?-1:1);
} }
function byImportance($a, $b) function byImportance($a, $b)
{ {
if ($a['importance'] != $b['importance']) if ($a['importance'] != $b['importance'])
@@ -107,6 +116,7 @@
return ($a['foundorder'] < $b['foundorder']?-1:1); return ($a['foundorder'] < $b['foundorder']?-1:1);
} }
function getPreferredLanguages() function getPreferredLanguages()
{ {
// If we have been provided the value in $_GET it overrides browser value // If we have been provided the value in $_GET it overrides browser value
@@ -116,7 +126,8 @@
} }
$aLanguages = array(); $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)) 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) foreach($aLanguagesParse as $iLang => $aLanguage)
@@ -153,6 +164,7 @@
return $aLangPrefOrder; return $aLangPrefOrder;
} }
function getWordSets($aWords) function getWordSets($aWords)
{ {
$aResult = array(array(join(' ',$aWords))); $aResult = array(array(join(' ',$aWords)));
@@ -170,6 +182,7 @@
return $aResult; return $aResult;
} }
function getTokensFromSets($aSets) function getTokensFromSets($aSets)
{ {
$aTokens = array(); $aTokens = array();
@@ -185,6 +198,7 @@
return $aTokens; return $aTokens;
} }
/* /*
GB Postcode functions GB Postcode functions
*/ */
@@ -216,6 +230,7 @@
return abs(($aValues[$s1[0]]*21+$aValues[$s1[1]]) - ($aValues[$s2[0]]*21+$aValues[$s2[1]])); return abs(($aValues[$s1[0]]*21+$aValues[$s1[1]]) - ($aValues[$s2[0]]*21+$aValues[$s2[1]]));
} }
function gbPostcodeCalculate($sPostcode, $sPostcodeSector, $sPostcodeEnd, &$oDB) function gbPostcodeCalculate($sPostcode, $sPostcodeSector, $sPostcodeEnd, &$oDB)
{ {
// Try an exact match on the gb_postcode table // Try an exact match on the gb_postcode table
@@ -235,6 +250,7 @@
return false; return false;
} }
function usPostcodeCalculate($sPostcode, &$oDB) function usPostcodeCalculate($sPostcode, &$oDB)
{ {
$iZipcode = (int)$sPostcode; $iZipcode = (int)$sPostcode;
@@ -294,6 +310,7 @@
*/ */
} }
function getClassTypes() function getClassTypes()
{ {
return array( return array(
@@ -600,6 +617,7 @@
); );
} }
function getClassTypesWithImportance() function getClassTypesWithImportance()
{ {
$aOrders = getClassTypes(); $aOrders = getClassTypes();
@@ -611,25 +629,31 @@
return $aOrders; return $aOrders;
} }
function javascript_renderData($xVal) function javascript_renderData($xVal)
{ {
header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Origin: *");
$jsonout = json_encode($xVal); $jsonout = json_encode($xVal);
if( ! isset($_GET['json_callback'])) { if( ! isset($_GET['json_callback']))
{
header("Content-Type: application/json; charset=UTF-8"); header("Content-Type: application/json; charset=UTF-8");
echo $jsonout; echo $jsonout;
} else { } else
if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u',$_GET['json_callback'])) { {
if (preg_match('/^[$_\p{L}][$_\p{L}\p{Nd}.[\]]*$/u',$_GET['json_callback']))
{
header("Content-Type: application/javascript; charset=UTF-8"); header("Content-Type: application/javascript; charset=UTF-8");
echo $_GET['json_callback'].'('.$jsonout.')'; echo $_GET['json_callback'].'('.$jsonout.')';
} else { }
else
{
header('HTTP/1.0 400 Bad Request'); header('HTTP/1.0 400 Bad Request');
} }
} }
} }
function _debugDumpGroupedSearches($aData, $aTokens) function _debugDumpGroupedSearches($aData, $aTokens)
{ {
$aWordsIDs = array(); $aWordsIDs = array();
@@ -713,7 +737,7 @@
function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCode = false, $bRaw = false) function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCode = false, $bRaw = false)
{ {
$sSQL = "select *,get_name_by_language(name,$sLanguagePrefArraySQL) as localname from get_addressdata($iPlaceID)"; $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"; $sSQL .= " order by rank_address desc,isaddress desc";
$aAddressLines = $oDB->getAll($sSQL); $aAddressLines = $oDB->getAll($sSQL);
@@ -758,6 +782,7 @@
return $aAddress; return $aAddress;
} }
function getWordSuggestions(&$oDB, $sWord) function getWordSuggestions(&$oDB, $sWord)
{ {
$sWordQuoted = getDBQuoted(trim($sWord)); $sWordQuoted = getDBQuoted(trim($sWord));
@@ -771,6 +796,7 @@
return $aSimilar; return $aSimilar;
} }
function geocodeReverse($fLat, $fLon, $iZoom=18) function geocodeReverse($fLat, $fLon, $iZoom=18)
{ {
$oDB =& getDB(); $oDB =& getDB();
@@ -876,7 +902,8 @@
$sValue = trim($_GET[$sKey]); $sValue = trim($_GET[$sKey]);
if (!$sValue) return false; if (!$sValue) return false;
$aStructuredQuery[$sKey] = $sValue; $aStructuredQuery[$sKey] = $sValue;
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30) { if ($iMinAddressRank == 0 && $iMaxAddressRank == 30)
{
$iMinAddressRank = $iNewMinAddressRank; $iMinAddressRank = $iNewMinAddressRank;
$iMaxAddressRank = $iNewMaxAddressRank; $iMaxAddressRank = $iNewMaxAddressRank;
} }

View File

@@ -115,7 +115,8 @@
// The point we found might be too small - use the address to find what it is a child of // The point we found might be too small - use the address to find what it is a child of
if ($iPlaceID && $iMaxRank < 28) if ($iPlaceID && $iMaxRank < 28)
{ {
if ($aPlace['rank_search'] > 28 && $iParentPlaceID) { if ($aPlace['rank_search'] > 28 && $iParentPlaceID)
{
$iPlaceID = $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"; $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";

View File

@@ -37,13 +37,16 @@
// Show / use polygons // Show / use polygons
$bShowPolygons = (boolean)isset($_GET['polygon']) && $_GET['polygon']; $bShowPolygons = (boolean)isset($_GET['polygon']) && $_GET['polygon'];
if ($sOutputFormat == 'html') { if ($sOutputFormat == 'html')
{
$bAsText = $bShowPolygons; $bAsText = $bShowPolygons;
$bShowPolygons = false; $bShowPolygons = false;
$bAsGeoJSON = false; $bAsGeoJSON = false;
$bAsKML = false; $bAsKML = false;
$bAsSVG = false; $bAsSVG = false;
} else { }
else
{
$bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson']; $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson'];
$bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml']; $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml'];
$bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg']; $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg'];
@@ -53,10 +56,14 @@
+ ($bAsKML?1:0) + ($bAsKML?1:0)
+ ($bAsSVG?1:0) + ($bAsSVG?1:0)
+ ($bAsText?1:0) + ($bAsText?1:0)
) > CONST_PolygonOutput_MaximumTypes) { ) > CONST_PolygonOutput_MaximumTypes)
if (CONST_PolygonOutput_MaximumTypes) { {
if (CONST_PolygonOutput_MaximumTypes)
{
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option"); userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
} else { }
else
{
userError("Polygon output is disabled"); userError("Polygon output is disabled");
} }
exit; exit;
@@ -138,7 +145,8 @@
$sValue = trim($_GET[$sKey]); $sValue = trim($_GET[$sKey]);
if (!$sValue) return false; if (!$sValue) return false;
$aStructuredQuery[$sKey] = $sValue; $aStructuredQuery[$sKey] = $sValue;
if ($iMinAddressRank == 0 && $iMaxAddressRank == 30) { if ($iMinAddressRank == 0 && $iMaxAddressRank == 30)
{
$iMinAddressRank = $iNewMinAddressRank; $iMinAddressRank = $iNewMinAddressRank;
$iMaxAddressRank = $iNewMaxAddressRank; $iMaxAddressRank = $iNewMaxAddressRank;
} }
@@ -161,7 +169,8 @@
{ {
loadStructuredAddressElement($aStructuredQuery, $iMinAddressRank, $iMaxAddressRank, $_GET, $aStructuredOption[0], $aStructuredOption[1], $aStructuredOption[2]); loadStructuredAddressElement($aStructuredQuery, $iMinAddressRank, $iMaxAddressRank, $_GET, $aStructuredOption[0], $aStructuredOption[1], $aStructuredOption[2]);
} }
if (sizeof($aStructuredQuery) > 0) { if (sizeof($aStructuredQuery) > 0)
{
$sQuery = join(', ', $aStructuredQuery); $sQuery = join(', ', $aStructuredQuery);
if ($iMaxAddressRank < 30) if ($iMaxAddressRank < 30)
{ {
@@ -201,7 +210,9 @@
$aCoOrdinates[1] += $fWidth; $aCoOrdinates[1] += $fWidth;
$aCoOrdinates[3] -= $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)"; $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; $bBoundingBoxSearch = false;
} }
if (isset($_GET['route']) && $_GET['route'] && isset($_GET['routewidth']) && $_GET['routewidth']) if (isset($_GET['route']) && $_GET['route'] && isset($_GET['routewidth']) && $_GET['routewidth'])
@@ -404,10 +415,8 @@
if (CONST_Debug) var_Dump($sSQL); if (CONST_Debug) var_Dump($sSQL);
$aValidTokens = array(); $aValidTokens = array();
if (sizeof($aTokens)) if (sizeof($aTokens)) $aDatabaseWords = $oDB->getAll($sSQL);
$aDatabaseWords = $oDB->getAll($sSQL); else $aDatabaseWords = array();
else
$aDatabaseWords = array();
if (PEAR::IsError($aDatabaseWords)) if (PEAR::IsError($aDatabaseWords))
{ {
failInternalError("Could not get word tokens.", $sSQL, $aDatabaseWords); failInternalError("Could not get word tokens.", $sSQL, $aDatabaseWords);
@@ -701,14 +710,8 @@
foreach($aNewPhraseSearches as $iSearch => $aSearch) foreach($aNewPhraseSearches as $iSearch => $aSearch)
{ {
$sHash = serialize($aSearch); $sHash = serialize($aSearch);
if (isset($aSearchHash[$sHash])) if (isset($aSearchHash[$sHash])) unset($aNewPhraseSearches[$iSearch]);
{ else $aSearchHash[$sHash] = 1;
unset($aNewPhraseSearches[$iSearch]);
}
else
{
$aSearchHash[$sHash] = 1;
}
} }
$aNewPhraseSearches = array_slice($aNewPhraseSearches, 0, 50); $aNewPhraseSearches = array_slice($aNewPhraseSearches, 0, 50);
@@ -963,7 +966,6 @@
if (sizeof($aSearch['aFullNameAddress'])) if (sizeof($aSearch['aFullNameAddress']))
$aOrder[] = '(select count(*) from (select unnest(ARRAY['.join($aSearch['aFullNameAddress'],",").']) INTERSECT select unnest(nameaddress_vector))s) DESC'; $aOrder[] = '(select count(*) from (select unnest(ARRAY['.join($aSearch['aFullNameAddress'],",").']) INTERSECT select unnest(nameaddress_vector))s) DESC';
if (sizeof($aTerms)) if (sizeof($aTerms))
{ {
$sSQL = "select place_id"; $sSQL = "select place_id";
@@ -1051,7 +1053,6 @@
if ($aSearch['sClass'] && sizeof($aPlaceIDs)) if ($aSearch['sClass'] && sizeof($aPlaceIDs))
{ {
$sPlaceIDs = join(',',$aPlaceIDs); $sPlaceIDs = join(',',$aPlaceIDs);
$aClassPlaceIDs = array(); $aClassPlaceIDs = array();
if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'name') if (!$aSearch['sOperator'] || $aSearch['sOperator'] == 'name')
@@ -1380,7 +1381,8 @@
if ($bAsSVG) $aResult['assvg'] = $aPointPolygon['assvg']; if ($bAsSVG) $aResult['assvg'] = $aPointPolygon['assvg'];
if ($bAsText) $aResult['astext'] = $aPointPolygon['astext']; 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['lat'] = $aPointPolygon['centrelat'];
$aResult['lon'] = $aPointPolygon['centrelon']; $aResult['lon'] = $aPointPolygon['centrelon'];
} }