fix indentation and misc errors according to PSR2 coding style guide

This commit is contained in:
Marc Tobias Metten
2016-09-14 03:16:46 +02:00
parent 74c06ef877
commit 4a321487f3
21 changed files with 406 additions and 374 deletions

View File

@@ -48,6 +48,7 @@ class Geocode
protected $sQuery = false;
protected $aStructuredQuery = false;
function Geocode(&$oDB)
{
$this->oDB =& $oDB;
@@ -131,18 +132,18 @@ class Geocode
function setFeatureType($sFeatureType)
{
switch ($sFeatureType) {
case 'country':
$this->setRankRange(4, 4);
break;
case 'state':
$this->setRankRange(8, 8);
break;
case 'city':
$this->setRankRange(14, 16);
break;
case 'settlement':
$this->setRankRange(8, 20);
break;
case 'country':
$this->setRankRange(4, 4);
break;
case 'state':
$this->setRankRange(8, 8);
break;
case 'city':
$this->setRankRange(14, 16);
break;
case 'settlement':
$this->setRankRange(8, 20);
break;
}
}
@@ -397,7 +398,7 @@ class Geocode
$sSQL .= ",extratags->'place' ";
if (30 >= $this->iMinAddressRank && 30 <= $this->iMaxAddressRank) {
//only Tiger housenumbers and interpolation lines need to be interpolated, because they are saved as lines
// only Tiger housenumbers and interpolation lines need to be interpolated, because they are saved as lines
// with start- and endnumber, the common osm housenumbers are usually saved as points
$sHousenumbers = "";
$i = 0;
@@ -408,7 +409,7 @@ class Geocode
if ($i<$length) $sHousenumbers .= ", ";
}
if (CONST_Use_US_Tiger_Data) {
//Tiger search only if a housenumber was searched and if it was found (i.e. aPlaceIDs[placeID] = housenumber != -1) (realized through a join)
// Tiger search only if a housenumber was searched and if it was found (i.e. aPlaceIDs[placeID] = housenumber != -1) (realized through a join)
$sSQL .= " union";
$sSQL .= " select 'T' as osm_type, place_id as osm_id, 'place' as class, 'house' as type, null as admin_level, 30 as rank_search, 30 as rank_address, min(place_id) as place_id, min(parent_place_id) as parent_place_id, 'us' as country_code";
$sSQL .= ", get_address_by_language(place_id, housenumber_for_place, $sLanguagePrefArraySQL) as langaddress ";
@@ -421,7 +422,7 @@ class Geocode
$sSQL .= ", (select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(blub.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance ";
$sSQL .= ", null as extra_place ";
$sSQL .= " from (select place_id";
//interpolate the Tiger housenumbers here
// interpolate the Tiger housenumbers here
$sSQL .= ", ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) as centroid, parent_place_id, housenumber_for_place";
$sSQL .= " from (location_property_tiger ";
$sSQL .= " join (values ".$sHousenumbers.") as housenumbers(place_id, housenumber_for_place) using(place_id)) ";
@@ -444,7 +445,7 @@ class Geocode
$sSQL .= " where s.place_id = min(blub.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance,";
$sSQL .= " null as extra_place ";
$sSQL .= " from (select place_id, calculated_country_code ";
//interpolate the housenumbers here
// interpolate the housenumbers here
$sSQL .= ", CASE WHEN startnumber != endnumber THEN ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) ";
$sSQL .= " ELSE ST_LineInterpolatePoint(linegeo, 0.5) END as centroid";
$sSQL .= ", parent_place_id, housenumber_for_place ";
@@ -476,7 +477,8 @@ class Geocode
$sSQL .= " order by importance desc";
if (CONST_Debug) {
echo "<hr>"; var_dump($sSQL);
echo "<hr>";
var_dump($sSQL);
}
$aSearchResults = chksql(
$this->oDB->getAll($sSQL),
@@ -738,6 +740,8 @@ class Geocode
name: full name (currently the same as langaddress)
foundorder: secondary ordering for places with same importance
*/
function lookup()
{
if (!$this->sQuery && !$this->aStructuredQuery) return false;
@@ -939,7 +943,7 @@ class Geocode
}
} elseif (!isset($aValidTokens[$sToken]) && preg_match('/^([0-9]{5}) [0-9]{4}$/', $sToken, $aData)) {
// US ZIP+4 codes - if there is no token,
// merge in the 5-digit ZIP code
// merge in the 5-digit ZIP code
if (isset($aValidTokens[$aData[1]])) {
foreach ($aValidTokens[$aData[1]] as $aToken) {
if (!$aToken['class']) {
@@ -1413,7 +1417,8 @@ class Geocode
}
if (CONST_Debug) {
echo "<br><b>Place IDs:</b> "; var_Dump($aPlaceIDs);
echo "<br><b>Place IDs:</b> ";
var_Dump($aPlaceIDs);
}
foreach ($aPlaceIDs as $iPlaceID) {
@@ -1495,7 +1500,8 @@ class Geocode
}
if (CONST_Debug) {
echo '<i>Recheck words:<\i>'; var_dump($aRecheckWords);
echo '<i>Recheck words:<\i>';
var_dump($aRecheckWords);
}
$oPlaceLookup = new PlaceLookup($this->oDB);
@@ -1577,15 +1583,15 @@ class Geocode
$aResult['name'] = $aResult['langaddress'];
// secondary ordering (for results with same importance (the smaller the better):
// - approximate importance of address parts
// - approximate importance of address parts
$aResult['foundorder'] = -$aResult['addressimportance']/10;
// - number of exact matches from the query
// - number of exact matches from the query
if (isset($this->exactMatchCache[$aResult['place_id']])) {
$aResult['foundorder'] -= $this->exactMatchCache[$aResult['place_id']];
} elseif (isset($this->exactMatchCache[$aResult['parent_place_id']])) {
$aResult['foundorder'] -= $this->exactMatchCache[$aResult['parent_place_id']];
}
// - importance of the class/type
// - importance of the class/type
if (isset($aClassType[$aResult['class'].':'.$aResult['type']]['importance'])
&& $aClassType[$aResult['class'].':'.$aResult['type']]['importance']
) {
@@ -1625,9 +1631,5 @@ class Geocode
}
return $aSearchResults;
} // end lookup()
} // end class

View File

@@ -4,9 +4,10 @@ class ParameterParser
{
private $aParams;
function __construct($aParams = NULL)
function __construct($aParams = null)
{
$this->aParams = ($aParams === NULL) ? $_GET : $aParams;
$this->aParams = ($aParams === null) ? $_GET : $aParams;
}
function getBool($sName, $bDefault = false)
@@ -77,9 +78,9 @@ class ParameterParser
return $aDefault;
}
function getPreferredLanguages($sFallback = NULL)
function getPreferredLanguages($sFallback = null)
{
if ($sFallback === NULL && isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
if ($sFallback === null && isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
$sFallback = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
}

View File

@@ -237,15 +237,18 @@ class PlaceLookup
// returns an array which will contain the keys
// aBoundingBox
// and may also contain one or more of the keys
// asgeojson
// askml
// assvg
// astext
// lat
// lon
/* returns an array which will contain the keys
* aBoundingBox
* and may also contain one or more of the keys
* asgeojson
* askml
* assvg
* astext
* lat
* lon
*/
function getOutlines($iPlaceID, $fLon = null, $fLat = null, $fRadius = null)
{
@@ -301,7 +304,7 @@ class PlaceLookup
(string)$aPointPolygon['maxlon']
);
}
} // CONST_Search_AreaPolygons
}
// as a fallback we generate a bounding box without knowing the size of the geometry
if ((!isset($aOutlineResult['aBoundingBox'])) && isset($fLon)) {

View File

@@ -5,11 +5,13 @@ class ReverseGeocode
protected $oDB;
protected $iMaxRank = 28;
function ReverseGeocode(&$oDB)
{
$this->oDB =& $oDB;
}
function setZoom($iZoom)
{
// Zoom to rank, this could probably be calculated but a lookup gives fine control
@@ -38,8 +40,13 @@ class ReverseGeocode
$this->iMaxRank = (isset($iZoom) && isset($aZoomRank[$iZoom]))?$aZoomRank[$iZoom]:28;
}
// returns { place_id =>, type => '(osm|tiger)' }
// fails if no place was found
/* lookup()
* returns { place_id =>, type => '(osm|tiger)' }
* fails if no place was found
*/
function lookup($fLat, $fLon, $bDoInterpolation = true)
{
$sPointSQL = 'ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326)';
@@ -111,7 +118,7 @@ class ReverseGeocode
if ($aPlaceLine) {
if (CONST_Debug) var_dump('found housenumber in interpolation lines table', $aPlaceLine);
if ($aPlace['rank_search'] == 30) {
// if a house was already found in placex, we have to find out,
// if a house was already found in placex, we have to find out,
// if the placex house or the interpolated house are closer to the searched point
// distance between point and placex house
$sSQL = 'SELECT ST_distance('.$sPointSQL.', house.geometry) as distance FROM placex as house WHERE house.place_id='.$iPlaceID;
@@ -204,5 +211,4 @@ class ReverseGeocode
'fraction' => ($bPlaceIsTiger || $bPlaceIsLine) ? $fFraction : -1
);
}
}

View File

@@ -1,5 +1,6 @@
<?php
function getCmdOpt($aArg, $aSpec, &$aResult, $bExitOnError = false, $bExitOnUnknown = false)
{
$aQuick = array();

View File

@@ -2,6 +2,7 @@
require_once('DB.php');
function &getDB($bNew = false, $bPersistent = false)
{
// Get the database object

View File

@@ -9,6 +9,7 @@ require_once('ParameterParser.php');
*
*/
function chksql($oSql, $sMsg = "Database request failed")
{
if (!PEAR::isError($oSql)) return $oSql;
@@ -95,4 +96,3 @@ if (CONST_NoAccessControl) {
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit;
if (CONST_Debug) header('Content-type: text/html; charset=utf-8');

View File

@@ -1,5 +1,6 @@
<?php
function fail($sError, $sUserError = false)
{
if (!$sUserError) $sUserError = $sError;
@@ -98,10 +99,6 @@ function getTokensFromSets($aSets)
}
/*
GB Postcode functions
*/
function gbPostcodeCalculate($sPostcode, $sPostcodeSector, $sPostcodeEnd, &$oDB)
{
// Try an exact match on the gb_postcode table
@@ -599,72 +596,78 @@ function addQuotes($s)
return "'".$s."'";
}
// returns boolean
function validLatLon($fLat, $fLon)
{
return ($fLat <= 90.1 && $fLat >= -90.1 && $fLon <= 180.1 && $fLon >= -180.1);
}
// Do we have anything that looks like a lat/lon pair?
// returns array(lat,lon,query_with_lat_lon_removed)
// or null
function looksLikeLatLonPair($sQuery)
{
// Do we have anything that looks like a lat/lon pair?
// returns array(lat,lon,query_with_lat_lon_removed)
// or null
$sFound = null;
$fQueryLat = null;
$fQueryLon = null;
if (preg_match('/\\b([NS])[ ]+([0-9]+[0-9.]*)[° ]+([0-9.]+)?[\']*[, ]+([EW])[ ]+([0-9]+)[° ]+([0-9]+[0-9.]*)[\']*?\\b/', $sQuery, $aData)) {
// 1 2 3 4 5 6
// degrees decimal minutes
// N 40 26.767, W 79 58.933
// N 40°26.767, W 79°58.933
/* 1 2 3 4 5 6
* degrees decimal minutes
* N 40 26.767, W 79 58.933
* N 40°26.767, W 79°58.933
*/
$sFound = $aData[0];
$fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2] + $aData[3]/60);
$fQueryLon = ($aData[4]=='E'?1:-1) * ($aData[5] + $aData[6]/60);
} elseif (preg_match('/\\b([0-9]+)[° ]+([0-9]+[0-9.]*)?[\']*[ ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+[0-9.]*)?[\' ]+([EW])\\b/', $sQuery, $aData)) {
// 1 2 3 4 5 6
// degrees decimal minutes
// 40 26.767 N, 79 58.933 W
// 40° 26.767 N 79° 58.933 W
/* 1 2 3 4 5 6
* degrees decimal minutes
* 40 26.767 N, 79 58.933 W
* 40° 26.767 N 79° 58.933 W
*/
$sFound = $aData[0];
$fQueryLat = ($aData[3]=='N'?1:-1) * ($aData[1] + $aData[2]/60);
$fQueryLon = ($aData[6]=='E'?1:-1) * ($aData[4] + $aData[5]/60);
} elseif (preg_match('/\\b([NS])[ ]([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″"]*[, ]+([EW])[ ]([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″"]*\\b/', $sQuery, $aData)) {
// 1 2 3 4 5 6 7 8
// degrees decimal seconds
// N 40 26 46 W 79 58 56
// N 40° 26 46″, W 79° 58 56″
/* 1 2 3 4 5 6 7 8
* degrees decimal seconds
* N 40 26 46 W 79 58 56
* N 40° 26 46″, W 79° 58 56″
*/
$sFound = $aData[0];
$fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2] + $aData[3]/60 + $aData[4]/3600);
$fQueryLon = ($aData[5]=='E'?1:-1) * ($aData[6] + $aData[7]/60 + $aData[8]/3600);
} elseif (preg_match('/\\b([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″" ]+([NS])[, ]+([0-9]+)[° ]+([0-9]+)[\' ]+([0-9]+)[″" ]+([EW])\\b/', $sQuery, $aData)) {
// 1 2 3 4 5 6 7 8
// degrees decimal seconds
// 40 26 46 N 79 58 56 W
// 40° 26 46″ N, 79° 58 56″ W
/* 1 2 3 4 5 6 7 8
* degrees decimal seconds
* 40 26 46 N 79 58 56 W
* 40° 26 46″ N, 79° 58 56″ W
*/
$sFound = $aData[0];
$fQueryLat = ($aData[4]=='N'?1:-1) * ($aData[1] + $aData[2]/60 + $aData[3]/3600);
$fQueryLon = ($aData[8]=='E'?1:-1) * ($aData[5] + $aData[6]/60 + $aData[7]/3600);
} elseif (preg_match('/\\b([NS])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*[, ]+([EW])[ ]([0-9]+[0-9]*\\.[0-9]+)[°]*\\b/', $sQuery, $aData)) {
// 1 2 3 4
// degrees decimal
// N 40.446° W 79.982°
/* 1 2 3 4
* degrees decimal
* N 40.446° W 79.982°
*/
$sFound = $aData[0];
$fQueryLat = ($aData[1]=='N'?1:-1) * ($aData[2]);
$fQueryLon = ($aData[3]=='E'?1:-1) * ($aData[4]);
} elseif (preg_match('/\\b([0-9]+[0-9]*\\.[0-9]+)[° ]+([NS])[, ]+([0-9]+[0-9]*\\.[0-9]+)[° ]+([EW])\\b/', $sQuery, $aData)) {
// 1 2 3 4
// degrees decimal
// 40.446° N 79.982° W
/* 1 2 3 4
* degrees decimal
* 40.446° N 79.982° W
*/
$sFound = $aData[0];
$fQueryLat = ($aData[2]=='N'?1:-1) * ($aData[1]);
$fQueryLon = ($aData[4]=='E'?1:-1) * ($aData[3]);
} elseif (preg_match('/(\\[|^|\\b)(-?[0-9]+[0-9]*\\.[0-9]+)[, ]+(-?[0-9]+[0-9]*\\.[0-9]+)(\\]|$|\\b)/', $sQuery, $aData)) {
// 1 2 3 4
// degrees decimal
// 12.34, 56.78
// [12.456,-78.90]
/* 1 2 3 4
* degrees decimal
* 12.34, 56.78
* [12.456,-78.90]
*/
$sFound = $aData[0];
$fQueryLat = $aData[2];
$fQueryLon = $aData[3];
@@ -679,7 +682,7 @@ function looksLikeLatLonPair($sQuery)
function geometryText2Points($geometry_as_text, $fRadius)
{
$aPolyPoints = NULL;
$aPolyPoints = null;
if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch)) {
//
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);

View File

@@ -1,5 +1,6 @@
<?php
function logStart(&$oDB, $sType = '', $sQuery = '', $aLanguageList = array())
{
$fStartTime = microtime(true);
@@ -70,5 +71,4 @@ function logEnd(&$oDB, $hLog, $iNumResults)
);
file_put_contents(CONST_Log_File, $aOutdata, FILE_APPEND | LOCK_EX);
}
}

View File

@@ -1,5 +1,6 @@
<?php
function formatOSMType($sType, $bIncludeExternal = true)
{
if ($sType == 'N') return 'node';
@@ -38,4 +39,3 @@ function detailsLink($aFeature, $sTitle = false)
return '<a href="details.php?place_id='.$aFeature['place_id'].'">'.($sTitle?$sTitle:$aFeature['place_id']).'</a>';
}