From: Sarah Hoffmann Date: Fri, 27 Oct 2017 21:01:11 +0000 (+0200) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Tag: deploy~349 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/a8a700e16d286971c43c013b322a1fd4a339de4d?hp=c3940466b817a4c10a956f61c43d6bee3214dd40 Merge remote-tracking branch 'upstream/master' --- diff --git a/lib/Geocode.php b/lib/Geocode.php index 97fc6371..8276fe98 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -525,12 +525,12 @@ class Geocode $sNormQuery = $this->normTerm($this->sQuery); $sLanguagePrefArraySQL = getArraySQL( - array_map("getDBQuoted", $this->aLangPrefOrder) + array_map('getDBQuoted', $this->aLangPrefOrder) ); $sQuery = $this->sQuery; if (!preg_match('//u', $sQuery)) { - userError("Query string is not UTF-8 encoded."); + userError('Query string is not UTF-8 encoded.'); } // Conflicts between US state abreviations and various words for 'the' in different languages @@ -577,7 +577,7 @@ class Geocode $sSpecialTerm = pg_escape_string($sSpecialTerm); $sToken = chksql( $this->oDB->getOne("SELECT make_standard_name('$sSpecialTerm')"), - "Cannot decode query. Wrong encoding?" + 'Cannot decode query. Wrong encoding?' ); $sSQL = 'SELECT class, type FROM word '; $sSQL .= ' WHERE word_token in (\' '.$sToken.'\')'; @@ -618,7 +618,7 @@ class Geocode foreach ($aInPhrases as $iPhrase => $sPhrase) { $sPhrase = chksql( $this->oDB->getOne('SELECT make_standard_name('.getDBQuoted($sPhrase).')'), - "Cannot normalize query string (is it a UTF-8 string?)" + 'Cannot normalize query string (is it a UTF-8 string?)' ); if (trim($sPhrase)) { $oPhrase = new Phrase($sPhrase, is_string($iPhrase) ? $iPhrase : ''); @@ -631,14 +631,14 @@ class Geocode // Check which tokens we have, get the ID numbers $sSQL = 'SELECT word_id, word_token, word, class, type, country_code, operator, search_name_count'; $sSQL .= ' FROM word '; - $sSQL .= ' WHERE word_token in ('.join(',', array_map("getDBQuoted", $aTokens)).')'; + $sSQL .= ' WHERE word_token in ('.join(',', array_map('getDBQuoted', $aTokens)).')'; if (CONST_Debug) var_Dump($sSQL); $aValidTokens = array(); $aDatabaseWords = chksql( $this->oDB->getAll($sSQL), - "Could not get word tokens." + 'Could not get word tokens.' ); $aWordFrequencyScores = array(); foreach ($aDatabaseWords as $aToken) { @@ -780,15 +780,15 @@ class Geocode if ($sPlaceIds) { $sSQL = 'SELECT place_id FROM placex '; $sSQL .= 'WHERE place_id in ('.$sPlaceIds.') '; - $sSQL .= " AND ("; + $sSQL .= ' AND ('; $sSQL .= " placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank "; if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) { $sSQL .= " OR (extratags->'place') = 'city'"; } if ($this->aAddressRankList) { - $sSQL .= " OR placex.rank_address in (".join(',', $this->aAddressRankList).")"; + $sSQL .= ' OR placex.rank_address in ('.join(',', $this->aAddressRankList).')'; } - $sSQL .= ")"; + $sSQL .= ')'; $aFilterSql[] = $sSQL; } $sPlaceIds = Result::joinIdsByTable($aResults, Result::TABLE_POSTCODE); @@ -797,9 +797,9 @@ class Geocode $sSQL .= 'WHERE place_id in ('.$sPlaceIds.') '; $sSQL .= " AND (lp.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank "; if ($this->aAddressRankList) { - $sSQL .= " OR lp.rank_address in (".join(',', $this->aAddressRankList).")"; + $sSQL .= ' OR lp.rank_address in ('.join(',', $this->aAddressRankList).')'; } - $sSQL .= ") "; + $sSQL .= ') '; $aFilterSql[] = $sSQL; } @@ -835,7 +835,7 @@ class Geocode $oLookup = $oReverse->lookupPoint($oCtx->sqlNear, false); - if (CONST_Debug) var_dump("Reverse search", $aLookup); + if (CONST_Debug) var_dump('Reverse search', $aLookup); if ($oLookup) { $aResults = array($oLookup->iId => $oLookup); @@ -932,7 +932,7 @@ class Geocode foreach ($aRecheckWords as $i => $sWord) { if (stripos($sAddress, $sWord)!==false) { $iCountWords++; - if (preg_match("/(^|,)\s*".preg_quote($sWord, '/')."\s*(,|$)/", $sAddress)) $iCountWords += 0.1; + if (preg_match('/(^|,)\s*'.preg_quote($sWord, '/').'\s*(,|$)/', $sAddress)) $iCountWords += 0.1; } } diff --git a/lib/ParameterParser.php b/lib/ParameterParser.php index 5177a08e..2eed1629 100644 --- a/lib/ParameterParser.php +++ b/lib/ParameterParser.php @@ -82,8 +82,8 @@ class ParameterParser public function getPreferredLanguages($sFallback = null) { - if ($sFallback === null && isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) { - $sFallback = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; + if ($sFallback === null && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + $sFallback = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } $aLanguages = array(); diff --git a/lib/PlaceLookup.php b/lib/PlaceLookup.php index 6d190c2a..4fce7e36 100644 --- a/lib/PlaceLookup.php +++ b/lib/PlaceLookup.php @@ -76,9 +76,9 @@ class PlaceLookup ($this->bIncludePolygonAsSVG ? 1 : 0); if ($iWantedTypes > 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 { - userError("Polygon output is disabled"); + userError('Polygon output is disabled'); } } } @@ -216,7 +216,7 @@ class PlaceLookup if ($this->sAddressRankListSql) { $sSQL .= ' OR placex.rank_address in '.$this->sAddressRankListSql; } - $sSQL .= " ) "; + $sSQL .= ' ) '; if ($this->sAllowedTypesSQLList) { $sSQL .= 'AND placex.class in '.$this->sAllowedTypesSQLList; } @@ -248,22 +248,22 @@ class PlaceLookup if ($sPlaceIDs) { $sSQL = 'SELECT'; $sSQL .= " 'P' as osm_type,"; - $sSQL .= " (SELECT osm_id from placex p WHERE p.place_id = lp.parent_place_id) as osm_id,"; + $sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id = lp.parent_place_id) as osm_id,'; $sSQL .= " 'place' as class, 'postcode' as type,"; $sSQL .= ' null as admin_level, rank_search, rank_address,'; $sSQL .= ' place_id, parent_place_id,'; $sSQL .= ' null as housenumber,'; $sSQL .= ' country_code,'; $sSQL .= $this->langAddressSql('-1'); - $sSQL .= " postcode as placename,"; - $sSQL .= " postcode as ref,"; - if ($this->bExtraTags) $sSQL .= "null AS extra,"; - if ($this->bNameDetails) $sSQL .= "null AS names,"; - $sSQL .= " ST_x(geometry) AS lon, ST_y(geometry) AS lat,"; - $sSQL .= " (0.75-(rank_search::float/40)) AS importance, "; + $sSQL .= ' postcode as placename,'; + $sSQL .= ' postcode as ref,'; + if ($this->bExtraTags) $sSQL .= 'null AS extra,'; + if ($this->bNameDetails) $sSQL .= 'null AS names,'; + $sSQL .= ' ST_x(geometry) AS lon, ST_y(geometry) AS lat,'; + $sSQL .= ' (0.75-(rank_search::float/40)) AS importance, '; $sSQL .= $this->addressImportanceSql('geometry', 'lp.parent_place_id'); - $sSQL .= " null AS extra_place "; - $sSQL .= "FROM location_postcode lp"; + $sSQL .= ' null AS extra_place '; + $sSQL .= 'FROM location_postcode lp'; $sSQL .= " WHERE place_id in ($sPlaceIDs) "; $sSQL .= " AND lp.rank_address between $iMinRank and $iMaxRank"; @@ -279,9 +279,9 @@ class PlaceLookup $sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_TIGER); // Tiger search only if a housenumber was searched and if it was found // (realized through a join) - $sSQL = " SELECT "; + $sSQL = ' SELECT '; $sSQL .= " 'T' AS osm_type, "; - $sSQL .= " (SELECT osm_id from placex p WHERE p.place_id=blub.parent_place_id) as osm_id, "; + $sSQL .= ' (SELECT osm_id from placex p WHERE p.place_id=blub.parent_place_id) as osm_id, '; $sSQL .= " 'place' AS class, "; $sSQL .= " 'house' AS type, "; $sSQL .= ' null AS admin_level, '; @@ -292,27 +292,27 @@ class PlaceLookup $sSQL .= ' housenumber_for_place as housenumber,'; $sSQL .= " 'us' AS country_code, "; $sSQL .= $this->langAddressSql('housenumber_for_place'); - $sSQL .= " null AS placename, "; - $sSQL .= " null AS ref, "; - if ($this->bExtraTags) $sSQL .= "null AS extra,"; - if ($this->bNameDetails) $sSQL .= "null AS names,"; - $sSQL .= " st_x(centroid) AS lon, "; - $sSQL .= " st_y(centroid) AS lat,"; - $sSQL .= " -1.15 AS importance, "; + $sSQL .= ' null AS placename, '; + $sSQL .= ' null AS ref, '; + if ($this->bExtraTags) $sSQL .= 'null AS extra,'; + if ($this->bNameDetails) $sSQL .= 'null AS names,'; + $sSQL .= ' st_x(centroid) AS lon, '; + $sSQL .= ' st_y(centroid) AS lat,'; + $sSQL .= ' -1.15 AS importance, '; $sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id'); - $sSQL .= " null AS extra_place "; - $sSQL .= " FROM ("; - $sSQL .= " SELECT place_id, "; // interpolate the Tiger housenumbers here - $sSQL .= " ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) AS centroid, "; - $sSQL .= " parent_place_id, "; - $sSQL .= " housenumber_for_place"; - $sSQL .= " FROM ("; - $sSQL .= " location_property_tiger "; - $sSQL .= " JOIN (values ".$sHousenumbers.") AS housenumbers(place_id, housenumber_for_place) USING(place_id)) "; - $sSQL .= " WHERE "; - $sSQL .= " housenumber_for_place >= startnumber"; - $sSQL .= " AND housenumber_for_place <= endnumber"; - $sSQL .= " ) AS blub"; //postgres wants an alias here + $sSQL .= ' null AS extra_place '; + $sSQL .= ' FROM ('; + $sSQL .= ' SELECT place_id, '; // interpolate the Tiger housenumbers here + $sSQL .= ' ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) AS centroid, '; + $sSQL .= ' parent_place_id, '; + $sSQL .= ' housenumber_for_place'; + $sSQL .= ' FROM ('; + $sSQL .= ' location_property_tiger '; + $sSQL .= ' JOIN (values '.$sHousenumbers.') AS housenumbers(place_id, housenumber_for_place) USING(place_id)) '; + $sSQL .= ' WHERE '; + $sSQL .= ' housenumber_for_place >= startnumber'; + $sSQL .= ' AND housenumber_for_place <= endnumber'; + $sSQL .= ' ) AS blub'; //postgres wants an alias here $aSubSelects[] = $sSQL; } @@ -324,9 +324,9 @@ class PlaceLookup $sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_OSMLINE); // interpolation line search only if a housenumber was searched // (realized through a join) - $sSQL = "SELECT "; + $sSQL = 'SELECT '; $sSQL .= " 'W' AS osm_type, "; - $sSQL .= " osm_id, "; + $sSQL .= ' osm_id, '; $sSQL .= " 'place' AS class, "; $sSQL .= " 'house' AS type, "; $sSQL .= ' 15 AS admin_level, '; @@ -344,27 +344,27 @@ class PlaceLookup $sSQL .= ' st_x(centroid) AS lon, '; $sSQL .= ' st_y(centroid) AS lat, '; // slightly smaller than the importance for normal houses - $sSQL .= " -0.1 AS importance, "; + $sSQL .= ' -0.1 AS importance, '; $sSQL .= $this->addressImportanceSql('centroid', 'blub.parent_place_id'); - $sSQL .= " null AS extra_place "; - $sSQL .= " FROM ("; - $sSQL .= " SELECT "; - $sSQL .= " osm_id, "; - $sSQL .= " place_id, "; - $sSQL .= " country_code, "; - $sSQL .= " CASE "; // interpolate the housenumbers here - $sSQL .= " WHEN startnumber != endnumber "; - $sSQL .= " THEN ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) "; - $sSQL .= " ELSE ST_LineInterpolatePoint(linegeo, 0.5) "; - $sSQL .= " END as centroid, "; - $sSQL .= " parent_place_id, "; - $sSQL .= " housenumber_for_place "; - $sSQL .= " FROM ("; - $sSQL .= " location_property_osmline "; - $sSQL .= " JOIN (values ".$sHousenumbers.") AS housenumbers(place_id, housenumber_for_place) USING(place_id)"; - $sSQL .= " ) "; - $sSQL .= " WHERE housenumber_for_place >= 0 "; - $sSQL .= " ) as blub"; //postgres wants an alias here + $sSQL .= ' null AS extra_place '; + $sSQL .= ' FROM ('; + $sSQL .= ' SELECT '; + $sSQL .= ' osm_id, '; + $sSQL .= ' place_id, '; + $sSQL .= ' country_code, '; + $sSQL .= ' CASE '; // interpolate the housenumbers here + $sSQL .= ' WHEN startnumber != endnumber '; + $sSQL .= ' THEN ST_LineInterpolatePoint(linegeo, (housenumber_for_place-startnumber::float)/(endnumber-startnumber)::float) '; + $sSQL .= ' ELSE ST_LineInterpolatePoint(linegeo, 0.5) '; + $sSQL .= ' END as centroid, '; + $sSQL .= ' parent_place_id, '; + $sSQL .= ' housenumber_for_place '; + $sSQL .= ' FROM ('; + $sSQL .= ' location_property_osmline '; + $sSQL .= ' JOIN (values '.$sHousenumbers.') AS housenumbers(place_id, housenumber_for_place) USING(place_id)'; + $sSQL .= ' ) '; + $sSQL .= ' WHERE housenumber_for_place >= 0 '; + $sSQL .= ' ) as blub'; //postgres wants an alias here $aSubSelects[] = $sSQL; } @@ -373,9 +373,9 @@ class PlaceLookup $sPlaceIDs = Result::joinIdsByTable($aResults, Result::TABLE_AUX); if ($sPlaceIDs) { $sHousenumbers = Result::sqlHouseNumberTable($aResults, Result::TABLE_AUX); - $sSQL = " SELECT "; + $sSQL = ' SELECT '; $sSQL .= " 'L' AS osm_type, "; - $sSQL .= " place_id AS osm_id, "; + $sSQL .= ' place_id AS osm_id, '; $sSQL .= " 'place' AS class,"; $sSQL .= " 'house' AS type, "; $sSQL .= ' null AS admin_level, '; @@ -386,19 +386,19 @@ class PlaceLookup $sSQL .= ' housenumber,'; $sSQL .= " 'us' AS country_code, "; $sSQL .= $this->langAddressSql('-1'); - $sSQL .= " null AS placename, "; - $sSQL .= " null AS ref, "; - if ($this->bExtraTags) $sSQL .= "null AS extra, "; - if ($this->bNameDetails) $sSQL .= "null AS names, "; - $sSQL .= " ST_X(centroid) AS lon, "; - $sSQL .= " ST_Y(centroid) AS lat, "; - $sSQL .= " -1.10 AS importance, "; + $sSQL .= ' null AS placename, '; + $sSQL .= ' null AS ref, '; + if ($this->bExtraTags) $sSQL .= 'null AS extra, '; + if ($this->bNameDetails) $sSQL .= 'null AS names, '; + $sSQL .= ' ST_X(centroid) AS lon, '; + $sSQL .= ' ST_Y(centroid) AS lat, '; + $sSQL .= ' -1.10 AS importance, '; $sSQL .= $this->addressImportanceSql( 'centroid', 'location_property_aux.parent_place_id' ); - $sSQL .= " null AS extra_place "; - $sSQL .= " FROM location_property_aux "; + $sSQL .= ' null AS extra_place '; + $sSQL .= ' FROM location_property_aux '; $sSQL .= " WHERE place_id in ($sPlaceIDs) "; $aSubSelects[] = $sSQL; @@ -414,7 +414,7 @@ class PlaceLookup $aPlaces = chksql( $this->oDB->getAll(join(' UNION ', $aSubSelects)), - "Could not lookup place" + 'Could not lookup place' ); $aClassType = getClassTypes(); @@ -534,22 +534,22 @@ class PlaceLookup if (CONST_Search_AreaPolygons) { // Get the bounding box and outline polygon - $sSQL = "select place_id,0 as numfeatures,st_area(geometry) as area,"; - $sSQL .= "ST_Y(centroid) as centrelat,ST_X(centroid) as centrelon,"; - $sSQL .= "ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,"; - $sSQL .= "ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon"; - if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ",ST_AsGeoJSON(geometry) as asgeojson"; - if ($this->bIncludePolygonAsKML) $sSQL .= ",ST_AsKML(geometry) as askml"; - if ($this->bIncludePolygonAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg"; - if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ",ST_AsText(geometry) as astext"; - $sFrom = " from placex where place_id = ".$iPlaceID; + $sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,'; + $sSQL .= 'ST_Y(centroid) as centrelat,ST_X(centroid) as centrelon,'; + $sSQL .= 'ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,'; + $sSQL .= 'ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon'; + if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson'; + if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml'; + if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg'; + if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ',ST_AsText(geometry) as astext'; + $sFrom = ' from placex where place_id = '.$iPlaceID; if ($this->fPolygonSimplificationThreshold > 0) { - $sSQL .= " from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,".$this->fPolygonSimplificationThreshold.") as geometry".$sFrom.") as plx"; + $sSQL .= ' from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry'.$sFrom.') as plx'; } else { $sSQL .= $sFrom; } - $aPointPolygon = chksql($this->oDB->getRow($sSQL), "Could not get outline"); + $aPointPolygon = chksql($this->oDB->getRow($sSQL), 'Could not get outline'); if ($aPointPolygon['place_id']) { if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) { diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index ce2ee5e5..e538620a 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -65,7 +65,7 @@ class ReverseGeocode return chksql( $this->oDB->getRow($sSQL), - "Could not determine closest housenumber on an osm interpolation line." + 'Could not determine closest housenumber on an osm interpolation line.' ); } @@ -132,16 +132,17 @@ class ReverseGeocode $sSQL .= ' LIMIT 1000) as p WHERE'; } $sSQL .= ' rank_search != 28 and rank_search >= '.$iMaxRank; - $sSQL .= ' and (name is not null or housenumber is not null)'; + $sSQL .= ' and (name is not null or housenumber is not null'; + $sSQL .= ' or rank_search between 26 and 27)'; $sSQL .= ' and class not in (\'waterway\',\'railway\',\'tunnel\',\'bridge\',\'man_made\')'; - $sSQL .= ' and indexed_status = 0 '; + $sSQL .= ' and indexed_status = 0 and linked_place_id is null'; $sSQL .= ' and (ST_GeometryType(geometry) not in (\'ST_Polygon\',\'ST_MultiPolygon\') '; $sSQL .= ' OR ST_DWithin('.$sPointSQL.', centroid, '.$fSearchDiam.'))'; $sSQL .= ' ORDER BY distance ASC limit 1'; if (CONST_Debug) var_dump($sSQL); $aPlace = chksql( $this->oDB->getRow($sSQL), - "Could not determine closest place." + 'Could not determine closest place.' ); if ($aPlace) { $oResult = new Result($aPlace['place_id']); @@ -186,7 +187,7 @@ class ReverseGeocode $aPlaceTiger = chksql( $this->oDB->getRow($sSQL), - "Could not determine closest Tiger place." + 'Could not determine closest Tiger place.' ); if ($aPlaceTiger) { if (CONST_Debug) var_dump('found Tiger housenumber', $aPlaceTiger); @@ -205,12 +206,12 @@ class ReverseGeocode } else { $iPlaceID = $oResult->iId; } - $sSQL = 'select address_place_id'; - $sSQL .= ' FROM place_addressline'; - $sSQL .= " WHERE place_id = $iPlaceID"; + $sSQL = 'select coalesce(p.linked_place_id, a.address_place_id)'; + $sSQL .= ' FROM place_addressline a, placex p'; + $sSQL .= " WHERE a.place_id = $iPlaceID and a.place_id = p.place_id"; $sSQL .= " ORDER BY abs(cached_rank_address - $iMaxRank) asc,cached_rank_address desc,isaddress desc,distance desc"; $sSQL .= ' LIMIT 1'; - $iPlaceID = chksql($this->oDB->getOne($sSQL), "Could not get parent for place."); + $iPlaceID = chksql($this->oDB->getOne($sSQL), 'Could not get parent for place.'); if ($iPlaceID) { $oResult = new Result($iPlaceID); } diff --git a/lib/SearchContext.php b/lib/SearchContext.php index 134b138f..3e722d87 100644 --- a/lib/SearchContext.php +++ b/lib/SearchContext.php @@ -146,11 +146,11 @@ class SearchContext $this->sqlViewboxCentre .= ")'::geometry,4326)"; $sSQL = 'ST_BUFFER('.$this->sqlViewboxCentre.','.($fRouteWidth/69).')'; - $sGeom = chksql($oDB->getOne("select ".$sSQL), "Could not get small viewbox"); + $sGeom = chksql($oDB->getOne('select '.$sSQL), 'Could not get small viewbox'); $this->sqlViewboxSmall = "'".$sGeom."'::geometry"; $sSQL = 'ST_BUFFER('.$this->sqlViewboxCentre.','.($fRouteWidth/30).')'; - $sGeom = chksql($oDB->getOne("select ".$sSQL), "Could not get large viewbox"); + $sGeom = chksql($oDB->getOne('select '.$sSQL), 'Could not get large viewbox'); $this->sqlViewboxLarge = "'".$sGeom."'::geometry"; } diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index edf4d059..bf45dada 100644 --- a/lib/SearchDescription.php +++ b/lib/SearchDescription.php @@ -240,7 +240,7 @@ class SearchDescription $oSearch->sHouseNumber = trim($aSearchTerm['word_token']); // sanity check: if the housenumber is not mainly made // up of numbers, add a penalty - if (preg_match_all("/[^0-9]/", $oSearch->sHouseNumber, $aMatches) > 2) { + if (preg_match_all('/[^0-9]/', $oSearch->sHouseNumber, $aMatches) > 2) { $oSearch->iSearchRank++; } if (!isset($aSearchTerm['word_id'])) { @@ -450,7 +450,7 @@ class SearchDescription } if (CONST_Debug) { - echo "
Place IDs: "; + echo '
Place IDs: '; var_dump(array_keys($aResults)); } @@ -469,7 +469,7 @@ class SearchDescription } $aResults = $aNewResults; if (CONST_Debug) { - echo "
Place IDs after postcode filtering: "; + echo '
Place IDs after postcode filtering: '; var_dump(array_keys($aResults)); } } @@ -488,7 +488,7 @@ class SearchDescription if ($this->oContext->bViewboxBounded) { $sSQL .= ' AND ST_Intersects('.$this->oContext->sqlViewboxSmall.', geometry)'; } - $sSQL .= " ORDER BY st_area(geometry) DESC LIMIT 1"; + $sSQL .= ' ORDER BY st_area(geometry) DESC LIMIT 1'; if (CONST_Debug) var_dump($sSQL); @@ -543,7 +543,7 @@ class SearchDescription if ($this->oContext->sqlCountryList) { $sSQL .= ' AND country_code in '.$this->oContext->sqlCountryList; } - $sSQL .= ' ORDER BY '.$this->oContext->distanceSQL('centroid')." ASC"; + $sSQL .= ' ORDER BY '.$this->oContext->distanceSQL('centroid').' ASC'; $sSQL .= " LIMIT $iLimit"; if (CONST_Debug) var_dump($sSQL); $aDBResults = chksql($oDB->getCol($sSQL)); @@ -638,13 +638,13 @@ class SearchDescription } if ($this->sHouseNumber) { - $aTerms[] = "address_rank between 16 and 27"; + $aTerms[] = 'address_rank between 16 and 27'; } elseif (!$this->sClass || $this->iOperator == Operator::NAME) { if ($iMinAddressRank > 0) { - $aTerms[] = "address_rank >= ".$iMinAddressRank; + $aTerms[] = 'address_rank >= '.$iMinAddressRank; } if ($iMaxAddressRank < 30) { - $aTerms[] = "address_rank <= ".$iMaxAddressRank; + $aTerms[] = 'address_rank <= '.$iMaxAddressRank; } } @@ -710,7 +710,7 @@ class SearchDescription $aDBResults = chksql( $oDB->getAll($sSQL), - "Could not get places for search terms." + 'Could not get places for search terms.' ); foreach ($aDBResults as $aResult) { @@ -762,8 +762,8 @@ class SearchDescription $sSQL .= "interpolationtype='odd'"; } $sSQL .= " or interpolationtype='all') and "; - $sSQL .= $iHousenumber.">=startnumber and "; - $sSQL .= $iHousenumber."<=endnumber"; + $sSQL .= $iHousenumber.'>=startnumber and '; + $sSQL .= $iHousenumber.'<=endnumber'; $sSQL .= $this->oContext->excludeSQL(' AND place_id'); $sSQL .= " limit $iLimit"; @@ -801,8 +801,8 @@ class SearchDescription $sSQL .= "interpolationtype='odd'"; } $sSQL .= " or interpolationtype='all') and "; - $sSQL .= $iHousenumber.">=startnumber and "; - $sSQL .= $iHousenumber."<=endnumber"; + $sSQL .= $iHousenumber.'>=startnumber and '; + $sSQL .= $iHousenumber.'<=endnumber'; $sSQL .= $this->oContext->excludeSQL(' AND place_id'); $sSQL .= " limit $iLimit"; @@ -835,9 +835,9 @@ class SearchDescription $sSQL .= " WHERE place_id in ($sPlaceIDs)"; $sSQL .= " AND class='".$this->sClass."' "; $sSQL .= " AND type='".$this->sType."'"; - $sSQL .= " AND linked_place_id is null"; + $sSQL .= ' AND linked_place_id is null'; $sSQL .= $this->oContext->excludeSQL(' AND place_id'); - $sSQL .= " ORDER BY rank_search ASC "; + $sSQL .= ' ORDER BY rank_search ASC '; $sSQL .= " LIMIT $iLimit"; if (CONST_Debug) var_dump($sSQL); @@ -865,8 +865,8 @@ class SearchDescription $sSQL .= " WHERE place_id in ($sPlaceIDs)"; $sSQL .= " AND rank_search < $iMaxRank + 5"; $sSQL .= " AND ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon')"; - $sSQL .= " ORDER BY rank_search ASC "; - $sSQL .= " LIMIT 1"; + $sSQL .= ' ORDER BY rank_search ASC '; + $sSQL .= ' LIMIT 1'; if (CONST_Debug) var_dump($sSQL); $sPlaceGeom = chksql($oDB->getOne($sSQL)); } @@ -892,7 +892,7 @@ class SearchDescription if ($this->oContext->hasNearPoint()) { $sOrderBySQL = $this->oContext->distanceSQL('l.centroid'); } elseif ($sPlaceIDs) { - $sOrderBySQL = "ST_Distance(l.centroid, f.geometry)"; + $sOrderBySQL = 'ST_Distance(l.centroid, f.geometry)'; } elseif ($sPlaceGeom) { $sOrderBySQL = "ST_Distance(st_centroid('".$sPlaceGeom."'), l.centroid)"; } @@ -908,7 +908,7 @@ class SearchDescription $sSQL .= ' from '.$sClassTable.' as l'; if ($sPlaceIDs) { - $sSQL .= ",placex as f WHERE "; + $sSQL .= ',placex as f WHERE '; $sSQL .= "f.place_id in ($sPlaceIDs) "; $sSQL .= " AND ST_DWithin(l.centroid, f.centroid, $fRange)"; } elseif ($sPlaceGeom) { @@ -936,7 +936,7 @@ class SearchDescription if ($this->oContext->hasNearPoint()) { $sOrderBySQL = $this->oContext->distanceSQL('l.geometry'); } else { - $sOrderBySQL = "ST_Distance(l.geometry, f.geometry)"; + $sOrderBySQL = 'ST_Distance(l.geometry, f.geometry)'; } $sSQL = 'SELECT distinct l.place_id'; @@ -950,7 +950,7 @@ class SearchDescription $sSQL .= " AND l.type='".$this->sType."'"; $sSQL .= $this->oContext->excludeSQL(' AND l.place_id'); if ($sOrderBySQL) { - $sSQL .= "ORDER BY orderterm ASC"; + $sSQL .= 'ORDER BY orderterm ASC'; } $sSQL .= " limit $iLimit"; @@ -1005,19 +1005,19 @@ class SearchDescription return $aWordIDs[$k]; }; - echo ""; + echo ''; echo "$this->iSearchRank"; - echo "".join(', ', array_map($kf, $this->aName)).""; - echo "".join(', ', array_map($kf, $this->aNameNonSearch)).""; - echo "".join(', ', array_map($kf, $this->aAddress)).""; - echo "".join(', ', array_map($kf, $this->aAddressNonSearch)).""; - echo "".$this->sCountryCode.""; - echo "".Operator::toString($this->iOperator).""; - echo "".$this->sClass.""; - echo "".$this->sType.""; - echo "".$this->sPostcode.""; - echo "".$this->sHouseNumber.""; - - echo ""; + echo ''.join(', ', array_map($kf, $this->aName)).''; + echo ''.join(', ', array_map($kf, $this->aNameNonSearch)).''; + echo ''.join(', ', array_map($kf, $this->aAddress)).''; + echo ''.join(', ', array_map($kf, $this->aAddressNonSearch)).''; + echo ''.$this->sCountryCode.''; + echo ''.Operator::toString($this->iOperator).''; + echo ''.$this->sClass.''; + echo ''.$this->sType.''; + echo ''.$this->sPostcode.''; + echo ''.$this->sHouseNumber.''; + + echo ''; } } diff --git a/lib/cmd.php b/lib/cmd.php index 898fbe95..a1084938 100644 --- a/lib/cmd.php +++ b/lib/cmd.php @@ -99,7 +99,7 @@ function showUsage($aSpec, $bExit = false, $sError = false) echo 'Try `'.basename($_SERVER['argv'][0]).' --help` for more information.'."\n"; exit; } - echo "Usage: ".basename($_SERVER['argv'][0])."\n"; + echo 'Usage: '.basename($_SERVER['argv'][0])."\n"; $bFirst = true; foreach ($aSpec as $aLine) { if (is_array($aLine)) { diff --git a/lib/db.php b/lib/db.php index 01fc344b..493d25f5 100644 --- a/lib/db.php +++ b/lib/db.php @@ -8,7 +8,7 @@ function &getDB($bNew = false, $bPersistent = false) // Get the database object $oDB = chksql( DB::connect(CONST_Database_DSN.($bNew?'?new_link=true':''), $bPersistent), - "Failed to establish database connection" + 'Failed to establish database connection' ); $oDB->setFetchMode(DB_FETCHMODE_ASSOC); $oDB->query("SET DateStyle TO 'sql,european'"); diff --git a/lib/init-website.php b/lib/init-website.php index 7d5cef1a..d8c012a4 100644 --- a/lib/init-website.php +++ b/lib/init-website.php @@ -10,7 +10,7 @@ require_once('ParameterParser.php'); */ -function chksql($oSql, $sMsg = "Database request failed") +function chksql($oSql, $sMsg = 'Database request failed') { if (!PEAR::isError($oSql)) return $oSql; @@ -38,10 +38,10 @@ INTERNALFAIL; if (CONST_Debug) { var_dump($oSql); } else { - echo "
\n".$oSql->getUserInfo()."
"; + echo "
\n".$oSql->getUserInfo().'
'; } - echo "

"; + echo '

'; exit; } @@ -49,20 +49,20 @@ function failInternalError($sError, $sSQL = false, $vDumpVar = false) { header('HTTP/1.0 500 Internal Server Error'); header('Content-type: text/html; charset=utf-8'); - echo "

Internal Server Error

"; + echo '

Internal Server Error

'; echo '

Nominatim has encountered an internal error while processing your request. This is most likely because of a bug in the software.

'; - echo "

Details: ".$sError,"

"; + echo '

Details: '.$sError,'

'; echo '

Feel free to file an issue on Github. '; echo 'Please include the error message above and the URL you used.

'; if (CONST_Debug) { - echo "

Debugging Information


"; + echo '

Debugging Information


'; if ($sSQL) { - echo "

SQL query

".$sSQL.""; + echo '

SQL query

'.$sSQL.''; } if ($vDumpVar) { - echo "

Result

"; + echo '

Result

'; var_dump($vDumpVar); - echo ""; + echo '
'; } } echo "\n\n"; @@ -74,9 +74,9 @@ function userError($sError) { header('HTTP/1.0 400 Bad Request'); header('Content-type: text/html; charset=utf-8'); - echo "

Bad Request

"; + echo '

Bad Request

'; echo '

Nominatim has encountered an error with your request.

'; - echo "

Details: ".$sError."

"; + echo '

Details: '.$sError.'

'; echo '

If you feel this error is incorrect feel file an issue on Github. '; echo 'Please include the error message above and the URL you used.

'; echo "\n\n"; @@ -89,10 +89,10 @@ function userError($sError) */ if (CONST_NoAccessControl) { - header("Access-Control-Allow-Origin: *"); - header("Access-Control-Allow-Methods: OPTIONS,GET"); + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: OPTIONS,GET'); if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) { - header("Access-Control-Allow-Headers: ".$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']); + header('Access-Control-Allow-Headers: '.$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']); } } if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit; diff --git a/lib/lib.php b/lib/lib.php index 9bf15964..6c56d5d9 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -38,7 +38,7 @@ function getDatabaseDate(&$oDB) // Find the newest node in the DB $iLastOSMID = $oDB->getOne("select max(osm_id) from place where osm_type = 'N'"); // Lookup the timestamp that node was created - $sLastNodeURL = 'https://www.openstreetmap.org/api/0.6/node/'.$iLastOSMID."/1"; + $sLastNodeURL = 'https://www.openstreetmap.org/api/0.6/node/'.$iLastOSMID.'/1'; $sLastNodeXML = file_get_contents($sLastNodeURL); if ($sLastNodeXML === false) { @@ -413,11 +413,11 @@ function javascript_renderData($xVal, $iOptions = 0) $jsonout = json_encode($xVal, $iOptions); if (!isset($_GET['json_callback'])) { - header("Content-Type: application/json; charset=UTF-8"); + header('Content-Type: application/json; charset=UTF-8'); echo $jsonout; } else { 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.')'; } else { header('HTTP/1.0 400 Bad Request'); @@ -439,16 +439,16 @@ function _debugDumpGroupedSearches($aData, $aTokens) } } } - echo ""; - echo ""; - echo ""; - echo ""; + echo '
rankName TokensName NotAddress TokensAddress Notcountryoperatorclasstypepostcodehousenumber
'; + echo ''; + echo ''; + echo ''; foreach ($aData as $iRank => $aRankedSet) { foreach ($aRankedSet as $aRow) { $aRow->dumpAsHtmlTableRow($aWordsIDs); } } - echo "
rankName TokensName NotAddress TokensAddress Notcountryoperatorclasstypepostcodehousenumber
"; + echo ''; } @@ -456,7 +456,7 @@ function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCo { $sSQL = "select *,get_name_by_language(name,$sLanguagePrefArraySQL) as localname from get_addressdata($iPlaceID, $housenumber)"; 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 = chksql($oDB->getAll($sSQL)); if ($bRaw) return $aAddressLines; diff --git a/lib/log.php b/lib/log.php index 9a064b9b..97d7d9c9 100644 --- a/lib/log.php +++ b/lib/log.php @@ -20,7 +20,7 @@ function logStart(&$oDB, $sType = '', $sQuery = '', $aLanguageList = array()) $hLog = array( date('Y-m-d H:i:s', $aStartTime[0]).'.'.$aStartTime[1], - $_SERVER["REMOTE_ADDR"], + $_SERVER['REMOTE_ADDR'], $_SERVER['QUERY_STRING'], $sOutQuery, $sType, diff --git a/phpcs.xml b/phpcs.xml index 2f4bc118..8f92f7c9 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -129,6 +129,23 @@ + + + + + + + + + 0 + + + + + + diff --git a/sql/functions.sql b/sql/functions.sql index 97baf52b..e5e189a8 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -2509,7 +2509,7 @@ BEGIN from place_addressline join placex on (address_place_id = placex.place_id) where place_addressline.place_id = for_place_id and (cached_rank_address > 0 AND cached_rank_address < searchrankaddress) - and address_place_id != for_place_id + and address_place_id != for_place_id and linked_place_id is null and (placex.country_code IS NULL OR searchcountrycode IS NULL OR placex.country_code = searchcountrycode) order by rank_address desc,isaddress desc,fromarea desc,distance asc,rank_search desc LOOP diff --git a/test/php/Nominatim/NominatimTest.php b/test/php/Nominatim/NominatimTest.php index cae3ebb8..60770208 100644 --- a/test/php/Nominatim/NominatimTest.php +++ b/test/php/Nominatim/NominatimTest.php @@ -24,9 +24,9 @@ class NominatimTest extends \PHPUnit_Framework_TestCase $this->assertEquals( array( - 'label' => "Country", + 'label' => 'Country', 'frequency' => 0, - 'icon' => "poi_boundary_administrative", + 'icon' => 'poi_boundary_administrative', 'defzoom' => 6, 'defdiameter' => 15, 'importance' => 3 @@ -192,4 +192,33 @@ class NominatimTest extends \PHPUnit_Framework_TestCase $this->assertEquals($sQuery, $aRes[0]); } } + + private function closestHouseNumberEvenOddOther($startnumber, $endnumber, $fraction, $aExpected) + { + foreach (['even', 'odd', 'other'] as $itype) { + $this->assertEquals( + $aExpected[$itype], + closestHouseNumber([ + 'startnumber' => $startnumber, + 'endnumber' => $endnumber, + 'fraction' => $fraction, + 'interpolationtype' => $itype + ]), + "$startnumber => $endnumber, $fraction, $itype" + ); + } + } + + public function testClosestHouseNumber() + { + $this->closestHouseNumberEvenOddOther(50, 100, 0.5, ['even' => 76, 'odd' => 75, 'other' => 75]); + // upper bound + $this->closestHouseNumberEvenOddOther(50, 100, 1.5, ['even' => 100, 'odd' => 100, 'other' => 100]); + // lower bound + $this->closestHouseNumberEvenOddOther(50, 100, -0.5, ['even' => 50, 'odd' => 50, 'other' => 50]); + // fraction 0 + $this->closestHouseNumberEvenOddOther(50, 100, 0, ['even' => 50, 'odd' => 51, 'other' => 50]); + // start == end + $this->closestHouseNumberEvenOddOther(50, 50, 0.5, ['even' => 50, 'odd' => 50, 'other' => 50]); + } } diff --git a/utils/blocks.php b/utils/blocks.php index b213e454..602df0bc 100755 --- a/utils/blocks.php +++ b/utils/blocks.php @@ -7,7 +7,7 @@ ini_set('memory_limit', '800M'); $aCMDOptions = array( - "Manage service blocks / restrictions", + 'Manage service blocks / restrictions', array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), @@ -29,8 +29,8 @@ if ($aResult['list']) { $aBlocks = getBucketBlocks(); echo "\n"; - printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", "Key", "Total Blocks", "Current", "Still Blocked", "Last Block Time", "Sleeping"); - printf(" %'--40s-|-%'-12s-|-%'-7s-|-%'-13s-|-%'-31s-|-%'-8s\n", "", "", "", "", "", ""); + printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", 'Key', 'Total Blocks', 'Current', 'Still Blocked', 'Last Block Time', 'Sleeping'); + printf(" %'--40s-|-%'-12s-|-%'-7s-|-%'-13s-|-%'-31s-|-%'-8s\n", '', '', '', '', '', ''); foreach ($aBlocks as $sKey => $aDetails) { printf( " %-40s | %12s | %7s | %13s | %31s | %8s\n", @@ -38,7 +38,7 @@ if ($aResult['list']) { $aDetails['totalBlocks'], (int)$aDetails['currentBucketSize'], $aDetails['currentlyBlocked']?'Y':'N', - date("r", $aDetails['lastBlockTimestamp']), + date('r', $aDetails['lastBlockTimestamp']), $aDetails['isSleeping']?'Y':'N' ); } diff --git a/utils/country_languages.php b/utils/country_languages.php index 5608247e..5ca61184 100755 --- a/utils/country_languages.php +++ b/utils/country_languages.php @@ -9,7 +9,7 @@ ini_set('display_errors', 'stderr'); $aCMDOptions = array( - "Import country language data from osm wiki", + 'Import country language data from osm wiki', array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), diff --git a/utils/importWikipedia.php b/utils/importWikipedia.php index 5271d233..5a6e6e04 100755 --- a/utils/importWikipedia.php +++ b/utils/importWikipedia.php @@ -7,7 +7,7 @@ ini_set('memory_limit', '800M'); $aCMDOptions = array( - "Create and setup nominatim search system", + 'Create and setup nominatim search system', array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), @@ -379,7 +379,7 @@ if (isset($aCMDResult['link'])) { $sURL = $sNominatimBaseURL.'?format=xml&accept-language=en'; - echo "\n-- ".$aRecord['name'].", ".$aRecord['infobox_type']."\n"; + echo "\n-- ".$aRecord['name'].', '.$aRecord['infobox_type']."\n"; $fMaxDist = 0.0000001; $bUnknown = false; switch (strtolower($aRecord['infobox_type'])) { @@ -387,15 +387,15 @@ if (isset($aCMDResult['link'])) { continue 2; case 'sea': $fMaxDist = 60; // effectively turn it off - $sURL .= "&viewbox=".($aRecord['lon']-$fMaxDist).",".($aRecord['lat']+$fMaxDist).",".($aRecord['lon']+$fMaxDist).",".($aRecord['lat']-$fMaxDist); + $sURL .= '&viewbox='.($aRecord['lon']-$fMaxDist).','.($aRecord['lat']+$fMaxDist).','.($aRecord['lon']+$fMaxDist).','.($aRecord['lat']-$fMaxDist); break; case 'country': case 'island': case 'islands': case 'continent': $fMaxDist = 60; // effectively turn it off - $sURL .= "&featuretype=country"; - $sURL .= "&viewbox=".($aRecord['lon']-$fMaxDist).",".($aRecord['lat']+$fMaxDist).",".($aRecord['lon']+$fMaxDist).",".($aRecord['lat']-$fMaxDist); + $sURL .= '&featuretype=country'; + $sURL .= '&viewbox='.($aRecord['lon']-$fMaxDist).','.($aRecord['lat']+$fMaxDist).','.($aRecord['lon']+$fMaxDist).','.($aRecord['lat']-$fMaxDist); break; case 'prefecture japan': $aRecord['name'] = trim(str_replace(' Prefecture', ' ', $aRecord['name'])); @@ -415,14 +415,14 @@ if (isset($aCMDResult['link'])) { case '#australia state or territory': case 'russian federal subject': $fMaxDist = 4; - $sURL .= "&featuretype=state"; - $sURL .= "&viewbox=".($aRecord['lon']-$fMaxDist).",".($aRecord['lat']+$fMaxDist).",".($aRecord['lon']+$fMaxDist).",".($aRecord['lat']-$fMaxDist); + $sURL .= '&featuretype=state'; + $sURL .= '&viewbox='.($aRecord['lon']-$fMaxDist).','.($aRecord['lat']+$fMaxDist).','.($aRecord['lon']+$fMaxDist).','.($aRecord['lat']-$fMaxDist); break; case 'protected area': $fMaxDist = 1; - $sURL .= "&nearlat=".$aRecord['lat']; - $sURL .= "&nearlon=".$aRecord['lon']; - $sURL .= "&viewbox=".($aRecord['lon']-$fMaxDist).",".($aRecord['lat']+$fMaxDist).",".($aRecord['lon']+$fMaxDist).",".($aRecord['lat']-$fMaxDist); + $sURL .= '&nearlat='.$aRecord['lat']; + $sURL .= '&nearlon='.$aRecord['lon']; + $sURL .= '&viewbox='.($aRecord['lon']-$fMaxDist).','.($aRecord['lat']+$fMaxDist).','.($aRecord['lon']+$fMaxDist).','.($aRecord['lat']-$fMaxDist); break; case 'settlement': $bUnknown = true; @@ -444,8 +444,8 @@ if (isset($aCMDResult['link'])) { case 'russian city': case 'city': $fMaxDist = 0.2; - $sURL .= "&featuretype=settlement"; - $sURL .= "&viewbox=".($aRecord['lon']-0.5).",".($aRecord['lat']+0.5).",".($aRecord['lon']+0.5).",".($aRecord['lat']-0.5); + $sURL .= '&featuretype=settlement'; + $sURL .= '&viewbox='.($aRecord['lon']-0.5).','.($aRecord['lat']+0.5).','.($aRecord['lon']+0.5).','.($aRecord['lat']-0.5); break; case 'mountain': case 'mountain pass': @@ -453,33 +453,33 @@ if (isset($aCMDResult['link'])) { case 'lake': case 'airport': $fMaxDist = 0.2; - $sURL .= "&viewbox=".($aRecord['lon']-0.5).",".($aRecord['lat']+0.5).",".($aRecord['lon']+0.5).",".($aRecord['lat']-0.5); + $sURL .= '&viewbox='.($aRecord['lon']-0.5).','.($aRecord['lat']+0.5).','.($aRecord['lon']+0.5).','.($aRecord['lat']-0.5); break; case 'ship begin': $fMaxDist = 0.1; $aTypes = array('wreck'); - $sURL .= "&viewbox=".($aRecord['lon']-0.01).",".($aRecord['lat']+0.01).",".($aRecord['lon']+0.01).",".($aRecord['lat']-0.01); - $sURL .= "&nearlat=".$aRecord['lat']; - $sURL .= "&nearlon=".$aRecord['lon']; + $sURL .= '&viewbox='.($aRecord['lon']-0.01).','.($aRecord['lat']+0.01).','.($aRecord['lon']+0.01).','.($aRecord['lat']-0.01); + $sURL .= '&nearlat='.$aRecord['lat']; + $sURL .= '&nearlon='.$aRecord['lon']; break; case 'road': case 'university': case 'company': case 'department': $fMaxDist = 0.005; - $sURL .= "&viewbox=".($aRecord['lon']-0.01).",".($aRecord['lat']+0.01).",".($aRecord['lon']+0.01).",".($aRecord['lat']-0.01); - $sURL .= "&bounded=1"; - $sURL .= "&nearlat=".$aRecord['lat']; - $sURL .= "&nearlon=".$aRecord['lon']; + $sURL .= '&viewbox='.($aRecord['lon']-0.01).','.($aRecord['lat']+0.01).','.($aRecord['lon']+0.01).','.($aRecord['lat']-0.01); + $sURL .= '&bounded=1'; + $sURL .= '&nearlat='.$aRecord['lat']; + $sURL .= '&nearlon='.$aRecord['lon']; break; default: $bUnknown = true; $fMaxDist = 0.005; - $sURL .= "&viewbox=".($aRecord['lon']-0.01).",".($aRecord['lat']+0.01).",".($aRecord['lon']+0.01).",".($aRecord['lat']-0.01); + $sURL .= '&viewbox='.($aRecord['lon']-0.01).','.($aRecord['lat']+0.01).','.($aRecord['lon']+0.01).','.($aRecord['lat']-0.01); // $sURL .= "&bounded=1"; - $sURL .= "&nearlat=".$aRecord['lat']; - $sURL .= "&nearlon=".$aRecord['lon']; - echo "-- Unknown: ".$aRecord['infobox_type']."\n"; + $sURL .= '&nearlat='.$aRecord['lat']; + $sURL .= '&nearlon='.$aRecord['lon']; + echo '-- Unknown: '.$aRecord['infobox_type']."\n"; break; } $sNameURL = $sURL.'&q='.urlencode($aRecord['name']); @@ -526,14 +526,14 @@ if (isset($aCMDResult['link'])) { elseif ($iRank <= 26) $fMaxDist = 0.001; else $fMaxDist = 0.001; } - echo "-- FOUND \"".substr($aNominatRecords[$i]['DISPLAY_NAME'], 0, 50); - echo "\", ".$aNominatRecords[$i]['CLASS'].", ".$aNominatRecords[$i]['TYPE']; - echo ", ".$aNominatRecords[$i]['PLACE_RANK'].", ".$aNominatRecords[$i]['OSM_TYPE']; + echo '-- FOUND "'.substr($aNominatRecords[$i]['DISPLAY_NAME'], 0, 50); + echo '", '.$aNominatRecords[$i]['CLASS'].', '.$aNominatRecords[$i]['TYPE']; + echo ', '.$aNominatRecords[$i]['PLACE_RANK'].', '.$aNominatRecords[$i]['OSM_TYPE']; echo " (dist:$fDiff, max:$fMaxDist)\n"; if ($fDiff > $fMaxDist) { echo "-- Diff too big $fDiff (max: $fMaxDist)".$aRecord['lat'].','.$aNominatRecords[$i]['LAT'].' & '.$aRecord['lon'].','.$aNominatRecords[$i]['LON']." \n"; } else { - $sSQL = "update wikipedia_article set osm_type="; + $sSQL = 'update wikipedia_article set osm_type='; switch ($aNominatRecords[$i]['OSM_TYPE']) { case 'relation': $sSQL .= "'R'"; @@ -545,7 +545,7 @@ if (isset($aCMDResult['link'])) { $sSQL .= "'N'"; break; } - $sSQL .= ", osm_id=".$aNominatRecords[$i]['OSM_ID']." where language = '".pg_escape_string($aRecord['language'])."' and title = '".pg_escape_string($aRecord['title'])."'"; + $sSQL .= ', osm_id='.$aNominatRecords[$i]['OSM_ID']." where language = '".pg_escape_string($aRecord['language'])."' and title = '".pg_escape_string($aRecord['title'])."'"; $oDB->query($sSQL); break; } diff --git a/utils/imports.php b/utils/imports.php index fce65ab9..07bc9c45 100755 --- a/utils/imports.php +++ b/utils/imports.php @@ -7,7 +7,7 @@ ini_set('memory_limit', '800M'); $aCMDOptions = array( - "Create and setup nominatim search system", + 'Create and setup nominatim search system', array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), @@ -29,7 +29,7 @@ if (isset($aCMDResult['parse-tiger'])) { preg_match('#([0-9]{5})_(.*)#', basename($sImportFile), $aMatch); $sCountyID = $aMatch[1]; - echo "Processing ".$sCountyID."...\n"; + echo 'Processing '.$sCountyID."...\n"; $sUnzipCmd = "unzip -d $sTempDir $sImportFile"; exec($sUnzipCmd); diff --git a/utils/query.php b/utils/query.php index 85ec8737..53ce176c 100755 --- a/utils/query.php +++ b/utils/query.php @@ -9,7 +9,7 @@ ini_set('memory_limit', '800M'); $aCMDOptions = array( - "Query database from command line. Returns search result as JSON.", + 'Query database from command line. Returns search result as JSON.', array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), @@ -41,7 +41,7 @@ if ($oParams->getBool('search')) { $aSearchResults = $oGeocode->lookup(); - if (version_compare(phpversion(), "5.4.0", '<')) { + if (version_compare(phpversion(), '5.4.0', '<')) { echo json_encode($aSearchResults); } else { echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n"; diff --git a/utils/server_compare.php b/utils/server_compare.php index 70a92e9b..39016d07 100755 --- a/utils/server_compare.php +++ b/utils/server_compare.php @@ -1,7 +1,7 @@ #!/usr/bin/php -Cq connection, $sSQL)) { fail(pg_last_error($aDBInstances[$i]->connection)); @@ -459,7 +459,7 @@ if ($aCMDResult['import-tiger-data']) { foreach (glob(CONST_Tiger_Data_Path.'/*.sql') as $sFile) { echo $sFile.': '; - $hFile = fopen($sFile, "r"); + $hFile = fopen($sFile, 'r'); $sSQL = fgets($hFile, 100000); $iLines = 0; @@ -472,7 +472,7 @@ if ($aCMDResult['import-tiger-data']) { if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection)); $iLines++; if ($iLines == 1000) { - echo "."; + echo '.'; $iLines = 0; } } @@ -517,15 +517,15 @@ if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) { fail(pg_last_error($oDB->connection)); } - $sSQL = "INSERT INTO location_postcode"; - $sSQL .= " (place_id, indexed_status, country_code, postcode, geometry) "; + $sSQL = 'INSERT INTO location_postcode'; + $sSQL .= ' (place_id, indexed_status, country_code, postcode, geometry) '; $sSQL .= "SELECT nextval('seq_place'), 1, country_code,"; $sSQL .= " upper(trim (both ' ' from address->'postcode')) as pc,"; - $sSQL .= " ST_Centroid(ST_Collect(ST_Centroid(geometry)))"; - $sSQL .= " FROM placex"; + $sSQL .= ' ST_Centroid(ST_Collect(ST_Centroid(geometry)))'; + $sSQL .= ' FROM placex'; $sSQL .= " WHERE address ? 'postcode' AND address->'postcode' NOT SIMILAR TO '%(,|;)%'"; - $sSQL .= " AND geometry IS NOT null"; - $sSQL .= " GROUP BY country_code, pc"; + $sSQL .= ' AND geometry IS NOT null'; + $sSQL .= ' GROUP BY country_code, pc'; if (!pg_query($oDB->connection, $sSQL)) { fail(pg_last_error($oDB->connection)); @@ -533,36 +533,36 @@ if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) { if (CONST_Use_Extra_US_Postcodes) { // only add postcodes that are not yet available in OSM - $sSQL = "INSERT INTO location_postcode"; - $sSQL .= " (place_id, indexed_status, country_code, postcode, geometry) "; + $sSQL = 'INSERT INTO location_postcode'; + $sSQL .= ' (place_id, indexed_status, country_code, postcode, geometry) '; $sSQL .= "SELECT nextval('seq_place'), 1, 'us', postcode,"; - $sSQL .= " ST_SetSRID(ST_Point(x,y),4326)"; - $sSQL .= " FROM us_postcode WHERE postcode NOT IN"; - $sSQL .= " (SELECT postcode FROM location_postcode"; + $sSQL .= ' ST_SetSRID(ST_Point(x,y),4326)'; + $sSQL .= ' FROM us_postcode WHERE postcode NOT IN'; + $sSQL .= ' (SELECT postcode FROM location_postcode'; $sSQL .= " WHERE country_code = 'us')"; } else { - $sSQL .= "TRUNCATE TABLE us_postcode"; + $sSQL .= 'TRUNCATE TABLE us_postcode'; } if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection)); // add missing postcodes for GB (if available) - $sSQL = "INSERT INTO location_postcode"; - $sSQL .= " (place_id, indexed_status, country_code, postcode, geometry) "; + $sSQL = 'INSERT INTO location_postcode'; + $sSQL .= ' (place_id, indexed_status, country_code, postcode, geometry) '; $sSQL .= "SELECT nextval('seq_place'), 1, 'gb', postcode, geometry"; - $sSQL .= " FROM gb_postcode WHERE postcode NOT IN"; - $sSQL .= " (SELECT postcode FROM location_postcode"; + $sSQL .= ' FROM gb_postcode WHERE postcode NOT IN'; + $sSQL .= ' (SELECT postcode FROM location_postcode'; $sSQL .= " WHERE country_code = 'gb')"; if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection)); if (!$aCMDResult['all']) { $sSQL = "DELETE FROM word WHERE class='place' and type='postcode'"; - $sSQL .= "and word NOT IN (SELECT postcode FROM location_postcode)"; + $sSQL .= 'and word NOT IN (SELECT postcode FROM location_postcode)'; if (!pg_query($oDB->connection, $sSQL)) { fail(pg_last_error($oDB->connection)); } } - $sSQL = "SELECT count(getorcreate_postcode_id(v)) FROM "; - $sSQL .= "(SELECT distinct(postcode) as v FROM location_postcode) p"; + $sSQL = 'SELECT count(getorcreate_postcode_id(v)) FROM '; + $sSQL .= '(SELECT distinct(postcode) as v FROM location_postcode) p'; if (!pg_query($oDB->connection, $sSQL)) { fail(pg_last_error($oDB->connection)); @@ -623,7 +623,7 @@ if ($aCMDResult['create-country-names'] || $aCMDResult['all']) { pgsqlRunScript("select getorcreate_country(make_standard_name('uk'), 'gb')"); pgsqlRunScript("select getorcreate_country(make_standard_name('united states'), 'us')"); - pgsqlRunScript("select count(*) from (select getorcreate_country(make_standard_name(country_code), country_code) from country_name where country_code is not null) as x"); + pgsqlRunScript('select count(*) from (select getorcreate_country(make_standard_name(country_code), country_code) from country_name where country_code is not null) as x'); pgsqlRunScript("select count(*) from (select getorcreate_country(make_standard_name(name->'name'), country_code) from country_name where name ? 'name') as x"); $sSQL = 'select count(*) from (select getorcreate_country(make_standard_name(v), country_code) from (select country_code, skeys(name) as k, svals(name) as v from country_name) x where k '; @@ -653,21 +653,21 @@ if ($aCMDResult['drop']) { // tables we want to keep. everything else goes. $aKeepTables = array( - "*columns", - "import_polygon_*", - "import_status", - "place_addressline", - "location_property*", - "placex", - "search_name", - "seq_*", - "word", - "query_log", - "new_query_log", - "gb_postcode", - "spatial_ref_sys", - "country_name", - "place_classtype_*" + '*columns', + 'import_polygon_*', + 'import_status', + 'place_addressline', + 'location_property*', + 'placex', + 'search_name', + 'seq_*', + 'word', + 'query_log', + 'new_query_log', + 'gb_postcode', + 'spatial_ref_sys', + 'country_name', + 'place_classtype_*' ); $oDB =& getDB(); @@ -693,7 +693,7 @@ if ($aCMDResult['drop']) { } if (!is_null(CONST_Osm2pgsql_Flatnode_File)) { - if ($aCMDResult['verbose']) echo "deleting ".CONST_Osm2pgsql_Flatnode_File."\n"; + if ($aCMDResult['verbose']) echo 'deleting '.CONST_Osm2pgsql_Flatnode_File."\n"; unlink(CONST_Osm2pgsql_Flatnode_File); } } diff --git a/utils/specialphrases.php b/utils/specialphrases.php index 1a4a51d7..ec00cb62 100755 --- a/utils/specialphrases.php +++ b/utils/specialphrases.php @@ -8,7 +8,7 @@ ini_set('display_errors', 'stderr'); $aCMDOptions = array( - "Import and export special phrases", + 'Import and export special phrases', array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), @@ -76,30 +76,30 @@ if ($aCMDResult['wiki-import']) { } } - echo "create index idx_placex_classtype on placex (class, type);"; + echo 'create index idx_placex_classtype on placex (class, type);'; foreach ($aPairs as $aPair) { - echo "create table place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]); + echo 'create table place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]); if (CONST_Tablespace_Aux_Data) - echo " tablespace ".CONST_Tablespace_Aux_Data; - echo " as select place_id as place_id,st_centroid(geometry) as centroid from placex where "; + echo ' tablespace '.CONST_Tablespace_Aux_Data; + echo ' as select place_id as place_id,st_centroid(geometry) as centroid from placex where '; echo "class = '".pg_escape_string($aPair[0])."' and type = '".pg_escape_string($aPair[1])."'"; echo ";\n"; - echo "CREATE INDEX idx_place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])."_centroid "; - echo "ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." USING GIST (centroid)"; + echo 'CREATE INDEX idx_place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).'_centroid '; + echo 'ON place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).' USING GIST (centroid)'; if (CONST_Tablespace_Aux_Index) - echo " tablespace ".CONST_Tablespace_Aux_Index; + echo ' tablespace '.CONST_Tablespace_Aux_Index; echo ";\n"; - echo "CREATE INDEX idx_place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])."_place_id "; - echo "ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." USING btree(place_id)"; + echo 'CREATE INDEX idx_place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).'_place_id '; + echo 'ON place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).' USING btree(place_id)'; if (CONST_Tablespace_Aux_Index) - echo " tablespace ".CONST_Tablespace_Aux_Index; + echo ' tablespace '.CONST_Tablespace_Aux_Index; echo ";\n"; - echo "GRANT SELECT ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]).' TO "'.CONST_Database_Web_User."\";\n"; + echo 'GRANT SELECT ON place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).' TO "'.CONST_Database_Web_User."\";\n"; } - echo "drop index idx_placex_classtype;"; + echo 'drop index idx_placex_classtype;'; } diff --git a/utils/update.php b/utils/update.php index 3026dacb..006a4774 100755 --- a/utils/update.php +++ b/utils/update.php @@ -7,7 +7,7 @@ ini_set('memory_limit', '800M'); $aCMDOptions = array( - "Import / update / index osm data", + 'Import / update / index osm data', array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), @@ -65,7 +65,7 @@ if ($aResult['init-updates']) { if ($sBaseState === false) { echo "\nCannot find state.txt file at the configured replication URL.\n"; echo "Does the URL point to a directory containing OSM update data?\n\n"; - fail("replication URL not reachable."); + fail('replication URL not reachable.'); } $sSetup = CONST_InstallPath.'/utils/setup.php'; $iRet = -1; @@ -76,7 +76,7 @@ if ($aResult['init-updates']) { $sDatabaseDate = getDatabaseDate($oDB); if ($sDatabaseDate === false) { - fail("Cannot determine date of database."); + fail('Cannot determine date of database.'); } $sWindBack = strftime('%Y-%m-%dT%H:%M:%SZ', strtotime($sDatabaseDate) - (3*60*60)); @@ -90,9 +90,9 @@ if ($aResult['init-updates']) { pg_query($oDB->connection, 'TRUNCATE import_status'); $sSQL = "INSERT INTO import_status (lastimportdate, sequence_id, indexed) VALUES('"; - $sSQL .= $sDatabaseDate."',".$aOutput[0].", true)"; + $sSQL .= $sDatabaseDate."',".$aOutput[0].', true)'; if (!pg_query($oDB->connection, $sSQL)) { - fail("Could not enter sequence into database."); + fail('Could not enter sequence into database.'); } echo "Done. Database updates will start at sequence $aOutput[0] ($sWindBack)\n"; @@ -119,7 +119,7 @@ if (isset($aResult['import-diff']) || isset($aResult['import-file'])) { } if ($aResult['calculate-postcodes']) { - info("Update postcodes centroids"); + info('Update postcodes centroids'); $sTemplate = file_get_contents(CONST_BasePath.'/sql/update-postcodes.sql'); runSQLScript($sTemplate, true, true); } @@ -171,7 +171,7 @@ if ($aResult['deduplicate']) { $oDB =& getDB(); if (getPostgresVersion($oDB) < 9.3) { - fail("ERROR: deduplicate is only currently supported in postgresql 9.3"); + fail('ERROR: deduplicate is only currently supported in postgresql 9.3'); } $sSQL = 'select partition from country_name order by country_code'; @@ -180,7 +180,7 @@ if ($aResult['deduplicate']) { // we don't care about empty search_name_* partitions, they can't contain mentions of duplicates foreach ($aPartitions as $i => $sPartition) { - $sSQL = "select count(*) from search_name_".$sPartition; + $sSQL = 'select count(*) from search_name_'.$sPartition; $nEntries = chksql($oDB->getOne($sSQL)); if ($nEntries == 0) { unset($aPartitions[$i]); @@ -188,14 +188,14 @@ if ($aResult['deduplicate']) { } $sSQL = "select word_token,count(*) from word where substr(word_token, 1, 1) = ' '"; - $sSQL .= " and class is null and type is null and country_code is null"; - $sSQL .= " group by word_token having count(*) > 1 order by word_token"; + $sSQL .= ' and class is null and type is null and country_code is null'; + $sSQL .= ' group by word_token having count(*) > 1 order by word_token'; $aDuplicateTokens = chksql($oDB->getAll($sSQL)); foreach ($aDuplicateTokens as $aToken) { if (trim($aToken['word_token']) == '' || trim($aToken['word_token']) == '-') continue; - echo "Deduping ".$aToken['word_token']."\n"; - $sSQL = "select word_id,"; - $sSQL .= " (select count(*) from search_name where nameaddress_vector @> ARRAY[word_id]) as num"; + echo 'Deduping '.$aToken['word_token']."\n"; + $sSQL = 'select word_id,'; + $sSQL .= ' (select count(*) from search_name where nameaddress_vector @> ARRAY[word_id]) as num'; $sSQL .= " from word where word_token = '".$aToken['word_token']; $sSQL .= "' and class is null and type is null and country_code is null order by num desc"; $aTokenSet = chksql($oDB->getAll($sSQL)); @@ -204,35 +204,35 @@ if ($aResult['deduplicate']) { $iKeepID = $aKeep['word_id']; foreach ($aTokenSet as $aRemove) { - $sSQL = "update search_name set"; - $sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID."),"; - $sSQL .= " nameaddress_vector = array_replace(nameaddress_vector,".$aRemove['word_id'].",".$iKeepID.")"; - $sSQL .= " where name_vector @> ARRAY[".$aRemove['word_id']."]"; + $sSQL = 'update search_name set'; + $sSQL .= ' name_vector = array_replace(name_vector,'.$aRemove['word_id'].','.$iKeepID.'),'; + $sSQL .= ' nameaddress_vector = array_replace(nameaddress_vector,'.$aRemove['word_id'].','.$iKeepID.')'; + $sSQL .= ' where name_vector @> ARRAY['.$aRemove['word_id'].']'; chksql($oDB->query($sSQL)); - $sSQL = "update search_name set"; - $sSQL .= " nameaddress_vector = array_replace(nameaddress_vector,".$aRemove['word_id'].",".$iKeepID.")"; - $sSQL .= " where nameaddress_vector @> ARRAY[".$aRemove['word_id']."]"; + $sSQL = 'update search_name set'; + $sSQL .= ' nameaddress_vector = array_replace(nameaddress_vector,'.$aRemove['word_id'].','.$iKeepID.')'; + $sSQL .= ' where nameaddress_vector @> ARRAY['.$aRemove['word_id'].']'; chksql($oDB->query($sSQL)); - $sSQL = "update location_area_country set"; - $sSQL .= " keywords = array_replace(keywords,".$aRemove['word_id'].",".$iKeepID.")"; - $sSQL .= " where keywords @> ARRAY[".$aRemove['word_id']."]"; + $sSQL = 'update location_area_country set'; + $sSQL .= ' keywords = array_replace(keywords,'.$aRemove['word_id'].','.$iKeepID.')'; + $sSQL .= ' where keywords @> ARRAY['.$aRemove['word_id'].']'; chksql($oDB->query($sSQL)); foreach ($aPartitions as $sPartition) { - $sSQL = "update search_name_".$sPartition." set"; - $sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID.")"; - $sSQL .= " where name_vector @> ARRAY[".$aRemove['word_id']."]"; + $sSQL = 'update search_name_'.$sPartition.' set'; + $sSQL .= ' name_vector = array_replace(name_vector,'.$aRemove['word_id'].','.$iKeepID.')'; + $sSQL .= ' where name_vector @> ARRAY['.$aRemove['word_id'].']'; chksql($oDB->query($sSQL)); - $sSQL = "update location_area_country set"; - $sSQL .= " keywords = array_replace(keywords,".$aRemove['word_id'].",".$iKeepID.")"; - $sSQL .= " where keywords @> ARRAY[".$aRemove['word_id']."]"; + $sSQL = 'update location_area_country set'; + $sSQL .= ' keywords = array_replace(keywords,'.$aRemove['word_id'].','.$iKeepID.')'; + $sSQL .= ' where keywords @> ARRAY['.$aRemove['word_id'].']'; chksql($oDB->query($sSQL)); } - $sSQL = "delete from word where word_id = ".$aRemove['word_id']; + $sSQL = 'delete from word where word_id = '.$aRemove['word_id']; chksql($oDB->query($sSQL)); } } @@ -361,7 +361,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) { $oDB->query($sSQL); echo date('Y-m-d H:i:s')." Completed index step for $sBatchEnd in ".round((time()-$fCMDStartTime)/60, 2)." minutes\n"; - $sSQL = "update import_status set indexed = true"; + $sSQL = 'update import_status set indexed = true'; $oDB->query($sSQL); } diff --git a/utils/warm.php b/utils/warm.php index 68fa751c..0ac13c46 100755 --- a/utils/warm.php +++ b/utils/warm.php @@ -6,7 +6,7 @@ require_once(CONST_BasePath.'/lib/init-cmd.php'); ini_set('memory_limit', '800M'); $aCMDOptions = array( - "Tools to warm nominatim db", + 'Tools to warm nominatim db', array('help', 'h', 0, 1, 0, 0, false, 'Show Help'), array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'), array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'), @@ -31,7 +31,7 @@ if (!$aResult['search-only']) { $oPlaceLookup->setIncludeAddressDetails(true); $oPlaceLookup->setLanguagePreference(array('en')); - echo "Warm reverse: "; + echo 'Warm reverse: '; if ($bVerbose) echo "\n"; for ($i = 0; $i < 1000; $i++) { $fLat = rand(-9000, 9000) / 100; @@ -46,7 +46,7 @@ if (!$aResult['search-only']) { ); if ($bVerbose) echo $aDetails['langaddress']."\n"; } else { - echo "."; + echo '.'; } } echo "\n"; @@ -55,7 +55,7 @@ if (!$aResult['search-only']) { if (!$aResult['reverse-only']) { $oGeocode = new Nominatim\Geocode($oDB); - echo "Warm search: "; + echo 'Warm search: '; if ($bVerbose) echo "\n"; $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000'; foreach ($oDB->getCol($sSQL) as $sWord) { @@ -64,6 +64,6 @@ if (!$aResult['reverse-only']) { $oGeocode->setQuery($sWord); $aSearchResults = $oGeocode->lookup(); if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n"; - else echo "."; + else echo '.'; } } diff --git a/website/deletable.php b/website/deletable.php index 95000032..6e9178e0 100755 --- a/website/deletable.php +++ b/website/deletable.php @@ -10,11 +10,11 @@ $sOutputFormat = 'html'; $oDB =& getDB(); -$sSQL = "select placex.place_id, country_code,"; +$sSQL = 'select placex.place_id, country_code,'; $sSQL .= " name->'name' as name, i.* from placex, import_polygon_delete i"; -$sSQL .= " where placex.osm_id = i.osm_id and placex.osm_type = i.osm_type"; -$sSQL .= " and placex.class = i.class and placex.type = i.type"; -$aPolygons = chksql($oDB->getAll($sSQL), "Could not get list of deleted OSM elements."); +$sSQL .= ' where placex.osm_id = i.osm_id and placex.osm_type = i.osm_type'; +$sSQL .= ' and placex.class = i.class and placex.type = i.type'; +$aPolygons = chksql($oDB->getAll($sSQL), 'Could not get list of deleted OSM elements.'); if (CONST_Debug) { var_dump($aPolygons); @@ -73,14 +73,14 @@ table td { "; +echo ''; // var_dump($aPolygons[0]); foreach ($aPolygons[0] as $sCol => $sVal) { - echo "".$sCol.""; + echo ''.$sCol.''; } -echo ""; +echo ''; foreach ($aPolygons as $aRow) { - echo ""; + echo ''; foreach ($aRow as $sCol => $sVal) { switch ($sCol) { case 'osm_id': @@ -90,11 +90,11 @@ foreach ($aPolygons as $aRow) { echo ''.detailsLink($aRow).''; break; default: - echo "".($sVal?$sVal:' ').""; + echo ''.($sVal?$sVal:' ').''; break; } } - echo ""; + echo ''; } ?> diff --git a/website/details.php b/website/details.php index 4d7c1efb..4c4ce578 100755 --- a/website/details.php +++ b/website/details.php @@ -11,7 +11,7 @@ $oParams = new Nominatim\ParameterParser(); $sOutputFormat = 'html'; $aLangPrefOrder = $oParams->getPreferredLanguages(); -$sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $aLangPrefOrder))."]"; +$sLanguagePrefArraySQL = 'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']'; $sPlaceId = $oParams->getString('place_id'); $sOsmType = $oParams->getSet('osmtype', array('N', 'W', 'R')); @@ -30,20 +30,20 @@ if ($sOsmType && $iOsmId > 0) { // Be nice about our error messages for broken geometry if (!$sPlaceId) { - $sSQL = "SELECT "; - $sSQL .= " osm_type, "; - $sSQL .= " osm_id, "; - $sSQL .= " errormessage, "; - $sSQL .= " class, "; - $sSQL .= " type, "; + $sSQL = 'SELECT '; + $sSQL .= ' osm_type, '; + $sSQL .= ' osm_id, '; + $sSQL .= ' errormessage, '; + $sSQL .= ' class, '; + $sSQL .= ' type, '; $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname,"; - $sSQL .= " ST_AsText(prevgeometry) AS prevgeom, "; - $sSQL .= " ST_AsText(newgeometry) AS newgeom"; - $sSQL .= " FROM import_polygon_error "; + $sSQL .= ' ST_AsText(prevgeometry) AS prevgeom, '; + $sSQL .= ' ST_AsText(newgeometry) AS newgeom'; + $sSQL .= ' FROM import_polygon_error '; $sSQL .= " WHERE osm_type = '".$sOsmType."'"; - $sSQL .= " AND osm_id = ".$iOsmId; - $sSQL .= " ORDER BY updated DESC"; - $sSQL .= " LIMIT 1"; + $sSQL .= ' AND osm_id = '.$iOsmId; + $sSQL .= ' ORDER BY updated DESC'; + $sSQL .= ' LIMIT 1'; $aPointDetails = chksql($oDB->getRow($sSQL)); if (!PEAR::isError($aPointDetails) && $aPointDetails) { if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches)) { @@ -60,7 +60,7 @@ if ($sOsmType && $iOsmId > 0) { } -if (!$sPlaceId) userError("Please select a place id"); +if (!$sPlaceId) userError('Please select a place id'); $iPlaceID = (int)$sPlaceId; @@ -85,34 +85,34 @@ if (CONST_Use_Aux_Location_data) { $hLog = logStart($oDB, 'details', $_SERVER['QUERY_STRING'], $aLangPrefOrder); // Get the details for this point -$sSQL = "SELECT place_id, osm_type, osm_id, class, type, name, admin_level,"; -$sSQL .= " housenumber, postcode, country_code,"; -$sSQL .= " importance, wikipedia,"; +$sSQL = 'SELECT place_id, osm_type, osm_id, class, type, name, admin_level,'; +$sSQL .= ' housenumber, postcode, country_code,'; +$sSQL .= ' importance, wikipedia,'; $sSQL .= " to_char(indexed_date, 'YYYY-MM-DD HH24:MI') AS indexed_date,"; -$sSQL .= " parent_place_id, "; -$sSQL .= " rank_address, "; -$sSQL .= " rank_search, "; -$sSQL .= " get_searchrank_label(rank_search) AS rank_search_label,"; +$sSQL .= ' parent_place_id, '; +$sSQL .= ' rank_address, '; +$sSQL .= ' rank_search, '; +$sSQL .= ' get_searchrank_label(rank_search) AS rank_search_label,'; $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, "; $sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea, "; //$sSQL .= " ST_Area(geometry::geography) AS area, "; -$sSQL .= " ST_y(centroid) AS lat, "; -$sSQL .= " ST_x(centroid) AS lon,"; -$sSQL .= " CASE "; -$sSQL .= " WHEN importance = 0 OR importance IS NULL THEN 0.75-(rank_search::float/40) "; -$sSQL .= " ELSE importance "; -$sSQL .= " END as calculated_importance, "; -$sSQL .= " ST_AsGeoJSON(CASE "; -$sSQL .= " WHEN ST_NPoints(geometry) > 5000 THEN ST_SimplifyPreserveTopology(geometry, 0.0001) "; -$sSQL .= " ELSE geometry "; -$sSQL .= " END) as asgeojson"; -$sSQL .= " FROM placex "; +$sSQL .= ' ST_y(centroid) AS lat, '; +$sSQL .= ' ST_x(centroid) AS lon,'; +$sSQL .= ' CASE '; +$sSQL .= ' WHEN importance = 0 OR importance IS NULL THEN 0.75-(rank_search::float/40) '; +$sSQL .= ' ELSE importance '; +$sSQL .= ' END as calculated_importance, '; +$sSQL .= ' ST_AsGeoJSON(CASE '; +$sSQL .= ' WHEN ST_NPoints(geometry) > 5000 THEN ST_SimplifyPreserveTopology(geometry, 0.0001) '; +$sSQL .= ' ELSE geometry '; +$sSQL .= ' END) as asgeojson'; +$sSQL .= ' FROM placex '; $sSQL .= " WHERE place_id = $iPlaceID"; -$aPointDetails = chksql($oDB->getRow($sSQL), "Could not get details of place object."); +$aPointDetails = chksql($oDB->getRow($sSQL), 'Could not get details of place object.'); if (!$aPointDetails) { - userError("Unknown place id."); + userError('Unknown place id.'); } $aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber']; @@ -151,56 +151,56 @@ if (PEAR::isError($aPointDetails['aExtraTags'])) { // possible timeout $aAddressLines = getAddressDetails($oDB, $sLanguagePrefArraySQL, $iPlaceID, $aPointDetails['country_code'], -1, true); // Linked places -$sSQL = "SELECT placex.place_id, osm_type, osm_id, class, type, housenumber,"; -$sSQL .= " admin_level, rank_address, "; +$sSQL = 'SELECT placex.place_id, osm_type, osm_id, class, type, housenumber,'; +$sSQL .= ' admin_level, rank_address, '; $sSQL .= " ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea,"; $sSQL .= " ST_DistanceSpheroid(geometry, placegeometry, 'SPHEROID[\"WGS 84\",6378137,298.257223563, AUTHORITY[\"EPSG\",\"7030\"]]') AS distance, "; $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, "; -$sSQL .= " length(name::text) AS namelength "; -$sSQL .= " FROM "; -$sSQL .= " placex, "; -$sSQL .= " ( "; -$sSQL .= " SELECT centroid AS placegeometry "; -$sSQL .= " FROM placex "; +$sSQL .= ' length(name::text) AS namelength '; +$sSQL .= ' FROM '; +$sSQL .= ' placex, '; +$sSQL .= ' ( '; +$sSQL .= ' SELECT centroid AS placegeometry '; +$sSQL .= ' FROM placex '; $sSQL .= " WHERE place_id = $iPlaceID "; -$sSQL .= " ) AS x"; +$sSQL .= ' ) AS x'; $sSQL .= " WHERE linked_place_id = $iPlaceID"; -$sSQL .= " ORDER BY "; -$sSQL .= " rank_address ASC, "; -$sSQL .= " rank_search ASC, "; +$sSQL .= ' ORDER BY '; +$sSQL .= ' rank_address ASC, '; +$sSQL .= ' rank_search ASC, '; $sSQL .= " get_name_by_language(name, $sLanguagePrefArraySQL), "; -$sSQL .= " housenumber"; +$sSQL .= ' housenumber'; $aLinkedLines = $oDB->getAll($sSQL); if (PEAR::isError($aLinkedLines)) { // possible timeout $aLinkedLines = []; } // All places this is an imediate parent of -$sSQL = "SELECT obj.place_id, osm_type, osm_id, class, type, housenumber,"; +$sSQL = 'SELECT obj.place_id, osm_type, osm_id, class, type, housenumber,'; $sSQL .= " admin_level, rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AS isarea,"; $sSQL .= " ST_DistanceSpheroid(geometry, placegeometry, 'SPHEROID[\"WGS 84\",6378137,298.257223563, AUTHORITY[\"EPSG\",\"7030\"]]') AS distance, "; $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) AS localname, "; -$sSQL .= " length(name::text) AS namelength "; -$sSQL .= " FROM "; -$sSQL .= " ( "; -$sSQL .= " SELECT placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name "; -$sSQL .= " FROM placex "; +$sSQL .= ' length(name::text) AS namelength '; +$sSQL .= ' FROM '; +$sSQL .= ' ( '; +$sSQL .= ' SELECT placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name '; +$sSQL .= ' FROM placex '; $sSQL .= " WHERE parent_place_id = $iPlaceID "; -$sSQL .= " ORDER BY "; -$sSQL .= " rank_address ASC, "; -$sSQL .= " rank_search ASC "; -$sSQL .= " LIMIT 500 "; -$sSQL .= " ) AS obj,"; -$sSQL .= " ( "; -$sSQL .= " SELECT centroid AS placegeometry "; -$sSQL .= " FROM placex "; +$sSQL .= ' ORDER BY '; +$sSQL .= ' rank_address ASC, '; +$sSQL .= ' rank_search ASC '; +$sSQL .= ' LIMIT 500 '; +$sSQL .= ' ) AS obj,'; +$sSQL .= ' ( '; +$sSQL .= ' SELECT centroid AS placegeometry '; +$sSQL .= ' FROM placex '; $sSQL .= " WHERE place_id = $iPlaceID "; -$sSQL .= " ) AS x"; -$sSQL .= " ORDER BY "; -$sSQL .= " rank_address ASC, "; -$sSQL .= " rank_search ASC, "; -$sSQL .= " localname, "; -$sSQL .= " housenumber"; +$sSQL .= ' ) AS x'; +$sSQL .= ' ORDER BY '; +$sSQL .= ' rank_address ASC, '; +$sSQL .= ' rank_search ASC, '; +$sSQL .= ' localname, '; +$sSQL .= ' housenumber'; $aParentOfLines = $oDB->getAll($sSQL); if (PEAR::isError($aParentOfLines)) { // possible timeout $aParentOfLines = []; @@ -215,13 +215,13 @@ if ($oParams->getBool('keywords')) { $aPlaceSearchName = []; } - $sSQL = "SELECT * FROM word WHERE word_id in (".substr($aPlaceSearchName['name_vector'], 1, -1).")"; + $sSQL = 'SELECT * FROM word WHERE word_id in ('.substr($aPlaceSearchName['name_vector'], 1, -1).')'; $aPlaceSearchNameKeywords = $oDB->getAll($sSQL); if (PEAR::isError($aPlaceSearchNameKeywords)) { // possible timeout $aPlaceSearchNameKeywords = []; } - $sSQL = "SELECT * FROM word WHERE word_id in (".substr($aPlaceSearchName['nameaddress_vector'], 1, -1).")"; + $sSQL = 'SELECT * FROM word WHERE word_id in ('.substr($aPlaceSearchName['nameaddress_vector'], 1, -1).')'; $aPlaceSearchAddressKeywords = $oDB->getAll($sSQL); if (PEAR::isError($aPlaceSearchAddressKeywords)) { // possible timeout $aPlaceSearchAddressKeywords = []; diff --git a/website/hierarchy.php b/website/hierarchy.php index 131a9ca1..8f2f5237 100755 --- a/website/hierarchy.php +++ b/website/hierarchy.php @@ -12,7 +12,7 @@ $oParams = new Nominatim\ParameterParser(); $sOutputFormat = $oParams->getSet('format', array('html', 'json'), 'html'); $aLangPrefOrder = $oParams->getPreferredLanguages(); -$sLanguagePrefArraySQL = "ARRAY[".join(',', array_map("getDBQuoted", $aLangPrefOrder))."]"; +$sLanguagePrefArraySQL = 'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']'; $sPlaceId = $oParams->getString('place_id'); $sOsmType = $oParams->getSet('osmtype', array('N', 'W', 'R')); @@ -25,11 +25,11 @@ if ($sOsmType && $iOsmId > 0) { // Be nice about our error messages for broken geometry if (!$sPlaceId) { - $sSQL = "select osm_type, osm_id, errormessage, class, type,"; + $sSQL = 'select osm_type, osm_id, errormessage, class, type,'; $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname,"; - $sSQL .= " ST_AsText(prevgeometry) as prevgeom, ST_AsText(newgeometry) as newgeom"; + $sSQL .= ' ST_AsText(prevgeometry) as prevgeom, ST_AsText(newgeometry) as newgeom'; $sSQL .= " from import_polygon_error where osm_type = '".$sOsmType; - $sSQL .= "' and osm_id = ".$iOsmId." order by updated desc limit 1"; + $sSQL .= "' and osm_id = ".$iOsmId.' order by updated desc limit 1'; $aPointDetails = chksql($oDB->getRow($sSQL)); if ($aPointDetails) { if (preg_match('/\[(-?\d+\.\d+) (-?\d+\.\d+)\]/', $aPointDetails['errormessage'], $aMatches)) { @@ -42,7 +42,7 @@ if ($sOsmType && $iOsmId > 0) { } } -if (!$sPlaceId) userError("Please select a place id"); +if (!$sPlaceId) userError('Please select a place id'); $iPlaceID = (int)$sPlaceId; @@ -62,7 +62,7 @@ $oPlaceLookup->setIncludeAddressDetails(true); $aPlaceAddress = array_reverse($oPlaceLookup->getAddressDetails($iPlaceID)); -if (!sizeof($aPlaceAddress)) userError("Unknown place id."); +if (!sizeof($aPlaceAddress)) userError('Unknown place id.'); $aBreadcrums = array(); foreach ($aPlaceAddress as $i => $aPlace) { @@ -76,14 +76,14 @@ foreach ($aPlaceAddress as $i => $aPlace) { if ($sOutputFormat == 'html') { $sPlaceUrl = 'hierarchy.php?place_id='.$aPlace['place_id']; - if ($i) echo " > "; + if ($i) echo ' > '; echo ''.$aPlace['localname'].' ('.osmLink($aPlace).')'; } } if ($sOutputFormat == 'json') { - header("content-type: application/json; charset=UTF-8"); + header('content-type: application/json; charset=UTF-8'); $aDetails = array(); $aDetails['breadcrumbs'] = $aBreadcrums; javascript_renderData($aDetails); @@ -92,12 +92,12 @@ if ($sOutputFormat == 'json') { $aRelatedPlaceIDs = chksql($oDB->getCol($sSQL = "select place_id from placex where linked_place_id = $iPlaceID or place_id = $iPlaceID")); -$sSQL = "select obj.place_id, osm_type, osm_id, class, type, housenumber, admin_level,"; +$sSQL = 'select obj.place_id, osm_type, osm_id, class, type, housenumber, admin_level,'; $sSQL .= " rank_address, ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') as isarea, st_area(geometry) as area, "; $sSQL .= " get_name_by_language(name,$sLanguagePrefArraySQL) as localname, length(name::text) as namelength "; -$sSQL .= " from (select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name from placex "; -$sSQL .= " where parent_place_id in (".join(',', $aRelatedPlaceIDs).") and name is not null order by rank_address asc,rank_search asc limit 500) as obj"; -$sSQL .= " order by rank_address asc,rank_search asc,localname,class, type,housenumber"; +$sSQL .= ' from (select placex.place_id, osm_type, osm_id, class, type, housenumber, admin_level, rank_address, rank_search, geometry, name from placex '; +$sSQL .= ' where parent_place_id in ('.join(',', $aRelatedPlaceIDs).') and name is not null order by rank_address asc,rank_search asc limit 500) as obj'; +$sSQL .= ' order by rank_address asc,rank_search asc,localname,class, type,housenumber'; $aParentOfLines = chksql($oDB->getAll($sSQL)); if (sizeof($aParentOfLines)) { diff --git a/website/js/nominatim-ui.js b/website/js/nominatim-ui.js index c971d745..ccd403fa 100644 --- a/website/js/nominatim-ui.js +++ b/website/js/nominatim-ui.js @@ -17,7 +17,7 @@ function parse_and_normalize_geojson_string(raw_string){ return parsed_geojson; } -jQuery(document).on('ready', function(){ +jQuery(document).ready(function(){ if ( !$('#search-page,#reverse-page').length ){ return; } @@ -265,7 +265,7 @@ jQuery(document).on('ready', function(){ }); -jQuery(document).on('ready', function(){ +jQuery(document).ready(function(){ if ( !$('#details-page').length ){ return; } @@ -284,9 +284,6 @@ jQuery(document).on('ready', function(){ attribution: (nominatim_map_init.tile_attribution || null ) //'© OpenStreetMap contributors' }).addTo(map); - var osm2 = new L.TileLayer(nominatim_map_init.tile_url, {minZoom: 0, maxZoom: 13, attribution: (nominatim_map_init.tile_attribution || null )}); - var miniMap = new L.Control.MiniMap(osm2, {toggleDisplay: true}).addTo(map); - var layerGroup = new L.layerGroup().addTo(map); var circle = L.circleMarker([nominatim_result.lat,nominatim_result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75}); @@ -309,6 +306,8 @@ jQuery(document).on('ready', function(){ map.setView([nominatim_result.lat,nominatim_result.lon],10); } + var osm2 = new L.TileLayer(nominatim_map_init.tile_url, {minZoom: 0, maxZoom: 13, attribution: (nominatim_map_init.tile_attribution || null )}); + var miniMap = new L.Control.MiniMap(osm2, {toggleDisplay: true}).addTo(map); }); diff --git a/website/lookup.php b/website/lookup.php index 578d4c37..b9cc88f7 100755 --- a/website/lookup.php +++ b/website/lookup.php @@ -29,7 +29,7 @@ $oPlaceLookup->loadParamArray($oParams); $aOsmIds = explode(',', $oParams->getString('osm_ids', '')); if (count($aOsmIds) > CONST_Places_Max_ID_count) { - userError('Bulk User: Only ' . CONST_Places_Max_ID_count . " ids are allowed in one request."); + userError('Bulk User: Only ' . CONST_Places_Max_ID_count . ' ids are allowed in one request.'); } foreach ($aOsmIds as $sItem) { diff --git a/website/polygons.php b/website/polygons.php index 153a279d..989c8f66 100755 --- a/website/polygons.php +++ b/website/polygons.php @@ -21,13 +21,13 @@ $aPolygons = array(); while ($iTotalBroken && !sizeof($aPolygons)) { $sSQL = 'select osm_type as "type",osm_id as "id",class as "key",type as "value",name->\'name\' as "name",'; $sSQL .= 'country_code as "country",errormessage as "error message",updated'; - $sSQL .= " from import_polygon_error"; + $sSQL .= ' from import_polygon_error'; $sSQL .= " where updated > 'now'::timestamp - '".$iDays." day'::interval"; $iDays++; if ($bReduced) $sSQL .= " and errormessage like 'Area reduced%'"; if ($sClass) $sSQL .= " and class = '".pg_escape_string($sClass)."'"; - $sSQL .= " order by updated desc limit 1000"; + $sSQL .= ' order by updated desc limit 1000'; $aPolygons = chksql($oDB->getAll($sSQL)); } @@ -86,48 +86,48 @@ table td { echo "

Total number of broken polygons: $iTotalBroken

"; if (!$aPolygons) exit; -echo ""; -echo ""; +echo '
'; +echo ''; //var_dump($aPolygons[0]); foreach ($aPolygons[0] as $sCol => $sVal) { - echo ""; + echo ''; } -echo ""; -echo ""; -echo ""; +echo ''; +echo ''; +echo ''; $aSeen = array(); foreach ($aPolygons as $aRow) { if (isset($aSeen[$aRow['type'].$aRow['id']])) continue; $aSeen[$aRow['type'].$aRow['id']] = 1; - echo ""; + echo ''; foreach ($aRow as $sCol => $sVal) { switch ($sCol) { case 'error message': if (preg_match('/Self-intersection\\[([0-9.\\-]+) ([0-9.\\-]+)\\]/', $sVal, $aMatch)) { $aRow['lat'] = $aMatch[2]; $aRow['lon'] = $aMatch[1]; - echo ""; + echo ''; } else { - echo ""; + echo ''; } break; case 'id': echo ''; break; default: - echo ""; + echo ''; break; } } - echo ""; + echo ''; if (isset($aRow['lat'])) { - echo ""; + echo ''; } else { - echo ""; + echo ''; } - echo ""; + echo ''; } -echo "
".$sCol."'.$sCol.'  
  
".($sVal?$sVal:' ')."'.($sVal?$sVal:' ').'".($sVal?$sVal:' ')."'.($sVal?$sVal:' ').''.osmLink($aRow).'".($sVal?$sVal:' ')."'.($sVal?$sVal:' ').'josmjosmP2P2  
"; +echo ''; ?> diff --git a/website/reverse.php b/website/reverse.php index 41e1a725..d997088a 100755 --- a/website/reverse.php +++ b/website/reverse.php @@ -46,7 +46,7 @@ if ($sOsmType && $iOsmId > 0) { } } } elseif ($sOutputFormat != 'html') { - userError("Need coordinates or OSM object to lookup."); + userError('Need coordinates or OSM object to lookup.'); } if (isset($aPlace)) { diff --git a/website/search.php b/website/search.php index bf9695ab..9f3ae470 100755 --- a/website/search.php +++ b/website/search.php @@ -28,7 +28,7 @@ if (CONST_Search_ReversePlanForAll // Format for output $sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2'), 'html'); -$sForcedGeometry = ($sOutputFormat == 'html') ? "geojson" : null; +$sForcedGeometry = ($sOutputFormat == 'html') ? 'geojson' : null; $oGeocode->loadParamArray($oParams, $sForcedGeometry); if (CONST_Search_BatchMode && isset($_GET['batch'])) { @@ -74,8 +74,8 @@ $sQuery = $oGeocode->getQueryString(); $aMoreParams = $oGeocode->getMoreUrlParams(); if ($sOutputFormat != 'html') $aMoreParams['format'] = $sOutputFormat; -if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) { - $aMoreParams['accept-language'] = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; +if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + $aMoreParams['accept-language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } $sMoreURL = CONST_Website_BaseURL.'search.php?'.http_build_query($aMoreParams); diff --git a/website/status.php b/website/status.php index b30a9a40..124dc507 100644 --- a/website/status.php +++ b/website/status.php @@ -7,31 +7,31 @@ require_once(CONST_BasePath.'/lib/init-website.php'); function statusError($sMsg) { - header("HTTP/1.0 500 Internal Server Error"); - echo "ERROR: ".$sMsg; + header('HTTP/1.0 500 Internal Server Error'); + echo 'ERROR: '.$sMsg; exit; } $oDB =& DB::connect(CONST_Database_DSN, false); if (!$oDB || PEAR::isError($oDB)) { - statusError("No database"); + statusError('No database'); } $sStandardWord = $oDB->getOne("select make_standard_name('a')"); if (PEAR::isError($sStandardWord)) { - statusError("Module failed"); + statusError('Module failed'); } if ($sStandardWord != 'a') { - statusError("Module call failed"); + statusError('Module call failed'); } $iWordID = $oDB->getOne("select word_id,word_token, word, class, type, country_code, operator, search_name_count from word where word_token in (' a')"); if (PEAR::isError($iWordID)) { - statusError("Query failed"); + statusError('Query failed'); } if (!$iWordID) { - statusError("No value"); + statusError('No value'); } -echo "OK"; +echo 'OK'; exit; diff --git a/wikidata/parse.php b/wikidata/parse.php index d8981c6c..1bef50ec 100755 --- a/wikidata/parse.php +++ b/wikidata/parse.php @@ -1,14 +1,14 @@ #!/usr/bin/php -Cq hour.txt'); - $hPrevTotals = @fopen("totals.txt", "r"); - $hDayTotals = @fopen("hour.txt", "r"); - $hNewTotals = @fopen("newtotals.txt", "w"); + $hPrevTotals = @fopen('totals.txt', 'r'); + $hDayTotals = @fopen('hour.txt', 'r'); + $hNewTotals = @fopen('newtotals.txt', 'w'); $sPrevKey = $sDayKey = true; $sPrevLine = true; @@ -64,8 +64,8 @@ for ($iTimestamp = mktime(0, 0, 0, 5, 1, 2013); $iTimestamp < mktime(0, 0, 0, 6, @fclose($hDayTotals); @fclose($hNewTotals); - @unlink("totals.txt"); - rename("newtotals.txt", "totals.txt"); + @unlink('totals.txt'); + rename('newtotals.txt', 'totals.txt'); } }