$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
$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.'\')';
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 : '');
// 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) {
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);
$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;
}
$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);
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;
}
}
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();
($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');
}
}
}
if ($this->sAddressRankListSql) {
$sSQL .= ' OR placex.rank_address in '.$this->sAddressRankListSql;
}
- $sSQL .= " ) ";
+ $sSQL .= ' ) ';
if ($this->sAllowedTypesSQLList) {
$sSQL .= 'AND placex.class in '.$this->sAllowedTypesSQLList;
}
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";
$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, ';
$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;
}
$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, ';
$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;
}
$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, ';
$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;
$aPlaces = chksql(
$this->oDB->getAll(join(' UNION ', $aSubSelects)),
- "Could not lookup place"
+ 'Could not lookup place'
);
$aClassType = getClassTypes();
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) {
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.'
);
}
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']);
$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);
$sSQL .= " WHERE place_id = $iPlaceID";
$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);
}
$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";
}
$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'])) {
}
if (CONST_Debug) {
- echo "<br><b>Place IDs:</b> ";
+ echo '<br><b>Place IDs:</b> ';
var_dump(array_keys($aResults));
}
}
$aResults = $aNewResults;
if (CONST_Debug) {
- echo "<br><b>Place IDs after postcode filtering:</b> ";
+ echo '<br><b>Place IDs after postcode filtering:</b> ';
var_dump(array_keys($aResults));
}
}
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);
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));
}
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;
}
}
$aDBResults = chksql(
$oDB->getAll($sSQL),
- "Could not get places for search terms."
+ 'Could not get places for search terms.'
);
foreach ($aDBResults as $aResult) {
$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";
$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";
$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);
$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));
}
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)";
}
$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) {
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';
$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";
return $aWordIDs[$k];
};
- echo "<tr>";
+ echo '<tr>';
echo "<td>$this->iSearchRank</td>";
- echo "<td>".join(', ', array_map($kf, $this->aName))."</td>";
- echo "<td>".join(', ', array_map($kf, $this->aNameNonSearch))."</td>";
- echo "<td>".join(', ', array_map($kf, $this->aAddress))."</td>";
- echo "<td>".join(', ', array_map($kf, $this->aAddressNonSearch))."</td>";
- echo "<td>".$this->sCountryCode."</td>";
- echo "<td>".Operator::toString($this->iOperator)."</td>";
- echo "<td>".$this->sClass."</td>";
- echo "<td>".$this->sType."</td>";
- echo "<td>".$this->sPostcode."</td>";
- echo "<td>".$this->sHouseNumber."</td>";
-
- echo "</tr>";
+ echo '<td>'.join(', ', array_map($kf, $this->aName)).'</td>';
+ echo '<td>'.join(', ', array_map($kf, $this->aNameNonSearch)).'</td>';
+ echo '<td>'.join(', ', array_map($kf, $this->aAddress)).'</td>';
+ echo '<td>'.join(', ', array_map($kf, $this->aAddressNonSearch)).'</td>';
+ echo '<td>'.$this->sCountryCode.'</td>';
+ echo '<td>'.Operator::toString($this->iOperator).'</td>';
+ echo '<td>'.$this->sClass.'</td>';
+ echo '<td>'.$this->sType.'</td>';
+ echo '<td>'.$this->sPostcode.'</td>';
+ echo '<td>'.$this->sHouseNumber.'</td>';
+
+ echo '</tr>';
}
}
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)) {
// 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'");
*/
-function chksql($oSql, $sMsg = "Database request failed")
+function chksql($oSql, $sMsg = 'Database request failed')
{
if (!PEAR::isError($oSql)) return $oSql;
if (CONST_Debug) {
var_dump($oSql);
} else {
- echo "<pre>\n".$oSql->getUserInfo()."</pre>";
+ echo "<pre>\n".$oSql->getUserInfo().'</pre>';
}
- echo "</pre></p></body></html>";
+ echo '</pre></p></body></html>';
exit;
}
{
header('HTTP/1.0 500 Internal Server Error');
header('Content-type: text/html; charset=utf-8');
- echo "<html><body><h1>Internal Server Error</h1>";
+ echo '<html><body><h1>Internal Server Error</h1>';
echo '<p>Nominatim has encountered an internal error while processing your request. This is most likely because of a bug in the software.</p>';
- echo "<p><b>Details:</b> ".$sError,"</p>";
+ echo '<p><b>Details:</b> '.$sError,'</p>';
echo '<p>Feel free to file an issue on <a href="https://github.com/openstreetmap/Nominatim/issues">Github</a>. ';
echo 'Please include the error message above and the URL you used.</p>';
if (CONST_Debug) {
- echo "<hr><h2>Debugging Information</h2><br>";
+ echo '<hr><h2>Debugging Information</h2><br>';
if ($sSQL) {
- echo "<h3>SQL query</h3><code>".$sSQL."</code>";
+ echo '<h3>SQL query</h3><code>'.$sSQL.'</code>';
}
if ($vDumpVar) {
- echo "<h3>Result</h3> <code>";
+ echo '<h3>Result</h3> <code>';
var_dump($vDumpVar);
- echo "</code>";
+ echo '</code>';
}
}
echo "\n</body></html>\n";
{
header('HTTP/1.0 400 Bad Request');
header('Content-type: text/html; charset=utf-8');
- echo "<html><body><h1>Bad Request</h1>";
+ echo '<html><body><h1>Bad Request</h1>';
echo '<p>Nominatim has encountered an error with your request.</p>';
- echo "<p><b>Details:</b> ".$sError."</p>";
+ echo '<p><b>Details:</b> '.$sError.'</p>';
echo '<p>If you feel this error is incorrect feel file an issue on <a href="https://github.com/openstreetmap/Nominatim/issues">Github</a>. ';
echo 'Please include the error message above and the URL you used.</p>';
echo "\n</body></html>\n";
*/
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;
// 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) {
$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');
}
}
}
- echo "<table border=\"1\">";
- echo "<tr><th>rank</th><th>Name Tokens</th><th>Name Not</th>";
- echo "<th>Address Tokens</th><th>Address Not</th><th>country</th><th>operator</th>";
- echo "<th>class</th><th>type</th><th>postcode</th><th>housenumber</th></tr>";
+ echo '<table border="1">';
+ echo '<tr><th>rank</th><th>Name Tokens</th><th>Name Not</th>';
+ echo '<th>Address Tokens</th><th>Address Not</th><th>country</th><th>operator</th>';
+ echo '<th>class</th><th>type</th><th>postcode</th><th>housenumber</th></tr>';
foreach ($aData as $iRank => $aRankedSet) {
foreach ($aRankedSet as $aRow) {
$aRow->dumpAsHtmlTableRow($aWordsIDs);
}
}
- echo "</table>";
+ echo '</table>';
}
{
$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;
$hLog = array(
date('Y-m-d H:i:s', $aStartTime[0]).'.'.$aStartTime[1],
- $_SERVER["REMOTE_ADDR"],
+ $_SERVER['REMOTE_ADDR'],
$_SERVER['QUERY_STRING'],
$sOutQuery,
$sType,
$this->assertEquals(
array(
- 'label' => "Country",
+ 'label' => 'Country',
'frequency' => 0,
- 'icon' => "poi_boundary_administrative",
+ 'icon' => 'poi_boundary_administrative',
'defzoom' => 6,
'defdiameter' => 15,
'importance' => 3
$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'),
$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",
$aDetails['totalBlocks'],
(int)$aDetails['currentBucketSize'],
$aDetails['currentlyBlocked']?'Y':'N',
- date("r", $aDetails['lastBlockTimestamp']),
+ date('r', $aDetails['lastBlockTimestamp']),
$aDetails['isSleeping']?'Y':'N'
);
}
$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'),
$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'),
$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'])) {
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']));
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;
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':
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']);
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'";
$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;
}
$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'),
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);
$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'),
$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";
#!/usr/bin/php -Cq
<?php
-$sFile = "sample.log.txt"; // Apache log file
+$sFile = 'sample.log.txt'; // Apache log file
$sHost1 = 'http://mq-open-search-lm02.ihost.aol.com:8000/nominatim/v1';
$sHost2 = 'http://mq-open-search-lm03.ihost.aol.com:8000/nominatim/v1';
$aToDo = array(251, 293, 328, 399.1, 455.1, 479, 496, 499, 574, 609, 702, 790, 846, 865, 878, 894, 902, 961, 980);
-$hFile = @fopen($sFile, "r");
+$hFile = @fopen($sFile, 'r');
if (!$hFile) {
echo "Unable to open file: $sFile\n";
exit;
$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'),
array('create-tables', '', 0, 1, 0, 0, 'bool', 'Create main tables'),
array('create-partition-tables', '', 0, 1, 0, 0, 'bool', 'Create required partition tables'),
array('create-partition-functions', '', 0, 1, 0, 0, 'bool', 'Create required partition triggers'),
- array('no-partitions', '', 0, 1, 0, 0, 'bool', "Do not partition search indices (speeds up import of single country extracts)"),
+ array('no-partitions', '', 0, 1, 0, 0, 'bool', 'Do not partition search indices (speeds up import of single country extracts)'),
array('import-wikipedia-articles', '', 0, 1, 0, 0, 'bool', 'Import wikipedia article dump'),
array('load-data', '', 0, 1, 0, 0, 'bool', 'Copy data to live tables from import table'),
array('disable-token-precalc', '', 0, 1, 0, 0, 'bool', 'Disable name precalculation (EXPERT)'),
if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
if ($aCMDResult['create-db'] || $aCMDResult['all']) {
- info("Create DB");
+ info('Create DB');
$bDidSomething = true;
$oDB = DB::connect(CONST_Database_DSN, false);
if (!PEAR::isError($oDB)) {
}
if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
- info("Setup DB");
+ info('Setup DB');
$bDidSomething = true;
$oDB =& getDB();
echo 'Postgres version found: '.$fPostgresVersion."\n";
if ($fPostgresVersion < 9.1) {
- fail("Minimum supported version of Postgresql is 9.1.");
+ fail('Minimum supported version of Postgresql is 9.1.');
}
pgsqlRunScript('CREATE EXTENSION IF NOT EXISTS hstore');
}
if (!file_exists(CONST_ExtraDataPath.'/country_osm_grid.sql.gz')) {
- echo "Error: you need to download the country_osm_grid first:";
+ echo 'Error: you need to download the country_osm_grid first:';
echo "\n wget -O ".CONST_ExtraDataPath."/country_osm_grid.sql.gz http://www.nominatim.org/data/country_grid.sql.gz\n";
exit(1);
}
info('Create Functions');
$bDidSomething = true;
if (!file_exists(CONST_InstallPath.'/module/nominatim.so')) {
- fail("nominatim module not built");
+ fail('nominatim module not built');
}
create_sql_functions($aCMDResult);
}
$sSQL = "INSERT INTO placex ($sColumns) SELECT $sColumns FROM place WHERE osm_id % $iLoadThreads = $i";
$sSQL .= " and not (class='place' and type='houses' and osm_type='W'";
$sSQL .= " and ST_GeometryType(geometry) = 'ST_LineString')";
- $sSQL .= " and ST_IsValid(geometry)";
+ $sSQL .= ' and ST_IsValid(geometry)';
if ($aCMDResult['verbose']) echo "$sSQL\n";
if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) {
fail(pg_last_error($aDBInstances[$i]->connection));
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;
if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection));
$iLines++;
if ($iLines == 1000) {
- echo ".";
+ echo '.';
$iLines = 0;
}
}
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));
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));
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 ';
// 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();
}
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);
}
}
$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'),
}
}
- 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;';
}
$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'),
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;
$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));
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";
}
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);
}
$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';
// 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]);
}
$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));
$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));
}
}
$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);
}
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'),
$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;
);
if ($bVerbose) echo $aDetails['langaddress']."\n";
} else {
- echo ".";
+ echo '.';
}
}
echo "\n";
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) {
$oGeocode->setQuery($sWord);
$aSearchResults = $oGeocode->lookup();
if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n";
- else echo ".";
+ else echo '.';
}
}
$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);
<?php
if (!$aPolygons) exit;
-echo "<tr>";
+echo '<tr>';
// var_dump($aPolygons[0]);
foreach ($aPolygons[0] as $sCol => $sVal) {
- echo "<th>".$sCol."</th>";
+ echo '<th>'.$sCol.'</th>';
}
-echo "</tr>";
+echo '</tr>';
foreach ($aPolygons as $aRow) {
- echo "<tr>";
+ echo '<tr>';
foreach ($aRow as $sCol => $sVal) {
switch ($sCol) {
case 'osm_id':
echo '<td>'.detailsLink($aRow).'</td>';
break;
default:
- echo "<td>".($sVal?$sVal:' ')."</td>";
+ echo '<td>'.($sVal?$sVal:' ').'</td>';
break;
}
}
- echo "</tr>";
+ echo '</tr>';
}
?>
$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'));
// 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)) {
}
-if (!$sPlaceId) userError("Please select a place id");
+if (!$sPlaceId) userError('Please select a place id');
$iPlaceID = (int)$sPlaceId;
$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'];
$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 = [];
$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 = [];
$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'));
// 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)) {
}
}
-if (!$sPlaceId) userError("Please select a place id");
+if (!$sPlaceId) userError('Please select a place id');
$iPlaceID = (int)$sPlaceId;
$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) {
if ($sOutputFormat == 'html') {
$sPlaceUrl = 'hierarchy.php?place_id='.$aPlace['place_id'];
- if ($i) echo " > ";
+ if ($i) echo ' > ';
echo '<a href="'.$sPlaceUrl.'">'.$aPlace['localname'].'</a> ('.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);
$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)) {
$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) {
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));
}
echo "<p>Total number of broken polygons: $iTotalBroken</p>";
if (!$aPolygons) exit;
-echo "<table>";
-echo "<tr>";
+echo '<table>';
+echo '<tr>';
//var_dump($aPolygons[0]);
foreach ($aPolygons[0] as $sCol => $sVal) {
- echo "<th>".$sCol."</th>";
+ echo '<th>'.$sCol.'</th>';
}
-echo "<th> </th>";
-echo "<th> </th>";
-echo "</tr>";
+echo '<th> </th>';
+echo '<th> </th>';
+echo '</tr>';
$aSeen = array();
foreach ($aPolygons as $aRow) {
if (isset($aSeen[$aRow['type'].$aRow['id']])) continue;
$aSeen[$aRow['type'].$aRow['id']] = 1;
- echo "<tr>";
+ echo '<tr>';
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 "<td><a href=\"http://www.openstreetmap.org/?lat=".$aMatch[2]."&lon=".$aMatch[1]."&zoom=18&layers=M&".$sOSMType."=".$aRow['id']."\">".($sVal?$sVal:' ')."</a></td>";
+ echo '<td><a href="http://www.openstreetmap.org/?lat='.$aMatch[2].'&lon='.$aMatch[1].'&zoom=18&layers=M&'.$sOSMType.'='.$aRow['id'].'">'.($sVal?$sVal:' ').'</a></td>';
} else {
- echo "<td>".($sVal?$sVal:' ')."</td>";
+ echo '<td>'.($sVal?$sVal:' ').'</td>';
}
break;
case 'id':
echo '<td>'.osmLink($aRow).'</td>';
break;
default:
- echo "<td>".($sVal?$sVal:' ')."</td>";
+ echo '<td>'.($sVal?$sVal:' ').'</td>';
break;
}
}
- echo "<td><a href=\"http://localhost:8111/import?url=http://www.openstreetmap.org/api/0.6/".$sOSMType.'/'.$aRow['id']."/full\" target=\"josm\">josm</a></td>";
+ echo '<td><a href="http://localhost:8111/import?url=http://www.openstreetmap.org/api/0.6/'.$sOSMType.'/'.$aRow['id'].'/full" target="josm">josm</a></td>';
if (isset($aRow['lat'])) {
- echo "<td><a href=\"http://open.mapquestapi.com/dataedit/index_flash.html?lat=".$aRow['lat']."&lon=".$aRow['lon']."&zoom=18\" target=\"potlatch2\">P2</a></td>";
+ echo '<td><a href="http://open.mapquestapi.com/dataedit/index_flash.html?lat='.$aRow['lat'].'&lon='.$aRow['lon'].'&zoom=18" target="potlatch2">P2</a></td>';
} else {
- echo "<td> </td>";
+ echo '<td> </td>';
}
- echo "</tr>";
+ echo '</tr>';
}
-echo "</table>";
+echo '</table>';
?>
</body>
}
}
} elseif ($sOutputFormat != 'html') {
- userError("Need coordinates or OSM object to lookup.");
+ userError('Need coordinates or OSM object to lookup.');
}
if (isset($aPlace)) {
// 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'])) {
$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);
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;
#!/usr/bin/php -Cq
<?php
-$hFile = @fopen("wikidatawiki-20130623-pages-articles.xml", "r");
+$hFile = @fopen('wikidatawiki-20130623-pages-articles.xml', 'r');
-$hFileEntity = fopen("entity.csv", "w");
-$hFileEntityLabel = fopen("entity_label.csv", "w");
-$hFileEntityDescription = fopen("entity_description.csv", "w");
-$hFileEntityAlias = fopen("entity_alias.csv", "w");
-$hFileEntityLink = fopen("entity_link.csv", "w");
-$hFileEntityProperty = fopen("entity_property.csv", "w");
+$hFileEntity = fopen('entity.csv', 'w');
+$hFileEntityLabel = fopen('entity_label.csv', 'w');
+$hFileEntityDescription = fopen('entity_description.csv', 'w');
+$hFileEntityAlias = fopen('entity_alias.csv', 'w');
+$hFileEntityLink = fopen('entity_link.csv', 'w');
+$hFileEntityProperty = fopen('entity_property.csv', 'w');
$iCount = 0;
$sText = html_entity_decode(substr($sLine, 33, -8), ENT_COMPAT, 'UTF-8');
$aArticle = json_decode($sText, true);
- if (array_diff(array_keys($aArticle), array("label", "description", "aliases", "links", "entity", "claims", "datatype")) != array()) {
+ if (array_diff(array_keys($aArticle), array('label', 'description', 'aliases', 'links', 'entity', 'claims', 'datatype')) != array()) {
// DEBUG
var_dump($sTitle);
var_dump(array_keys($aArticle));
continue;
}
- echo ".";
+ echo '.';
fputcsv($hFileEntity, array($iID, $sTitle, $iPID, $iQID, @$aArticle['datatype']));
$iPID,
null,
null,
- "SRID=4326;POINT(".((float) $aClaim['m'][3]['longitude'])." ".((float)$aClaim['m'][3]['latitude']).")", null
+ 'SRID=4326;POINT('.((float) $aClaim['m'][3]['longitude']).' '.((float)$aClaim['m'][3]['latitude']).')', null
)
);
/* echo "insert into entity_property values (nextval('seq_entity_property'),";
<?php
for ($iTimestamp = mktime(0, 0, 0, 5, 1, 2013); $iTimestamp < mktime(0, 0, 0, 6, 15, 2013); $iTimestamp += 24*60*60) {
- $sYear = date("Y", $iTimestamp);
- $sMonth = date("Y-m", $iTimestamp);
- $sDay = date("Ymd", $iTimestamp);
+ $sYear = date('Y', $iTimestamp);
+ $sMonth = date('Y-m', $iTimestamp);
+ $sDay = date('Ymd', $iTimestamp);
for ($iHour = 0; $iHour < 24; $iHour++) {
- $sFilename = sprintf("pagecounts-".$sDay."-%02d0000", $iHour);
+ $sFilename = sprintf('pagecounts-'.$sDay.'-%02d0000', $iHour);
echo $sFilename."\n";
if (!file_exists($sFilename.'.gz')) {
exec('wget http://dumps.wikimedia.org/other/pagecounts-raw/'.$sYear.'/'.$sMonth.'/'.$sFilename.'.gz');
exec('gzip -dc '.$sFilename.'.gz'.' | grep -e "^[a-z]\{2\} [^ :]\+ [0-9]\+" > 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;
@fclose($hDayTotals);
@fclose($hNewTotals);
- @unlink("totals.txt");
- rename("newtotals.txt", "totals.txt");
+ @unlink('totals.txt');
+ rename('newtotals.txt', 'totals.txt');
}
}