Switch places.php over to GIS API, remove external placedb connection
This commit is contained in:
parent
ea7e60d329
commit
84413765f7
61
places.php
61
places.php
@ -9,21 +9,6 @@ require 'required.php';
|
|||||||
|
|
||||||
//ini_set('memory_limit','32M');
|
//ini_set('memory_limit','32M');
|
||||||
|
|
||||||
$placebase;
|
|
||||||
try {
|
|
||||||
$placebase = new medoo([
|
|
||||||
'database_type' => PDB_TYPE,
|
|
||||||
'database_name' => PDB_NAME,
|
|
||||||
'server' => PDB_SERVER,
|
|
||||||
'username' => PDB_USER,
|
|
||||||
'password' => PDB_PASS,
|
|
||||||
'charset' => PDB_CHARSET
|
|
||||||
]);
|
|
||||||
} catch (Exception $ex) {
|
|
||||||
header('HTTP/1.1 500 Internal Server Error');
|
|
||||||
sendError('Location database error. Try again later.', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
|
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
|
||||||
|
|
||||||
if (is_empty($VARS['lat'])) {
|
if (is_empty($VARS['lat'])) {
|
||||||
@ -50,31 +35,11 @@ if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) {
|
|||||||
$radius = floatval($VARS['radius']);
|
$radius = floatval($VARS['radius']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']);
|
|
||||||
$searchbounds = $userlocation->boundingCoordinates($radius, 'miles');
|
|
||||||
if ($VARS['debug']) {
|
if ($VARS['debug']) {
|
||||||
echo "got to the place data query ";
|
echo "got to the place data query ";
|
||||||
}
|
}
|
||||||
if (is_empty($VARS['names'])) {
|
|
||||||
$places = $placebase->select('places', '*', ['AND' => [
|
|
||||||
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
|
||||||
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
|
||||||
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
|
||||||
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
|
|
||||||
"LIMIT" => 200
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$places = $placebase->select('places', '*', ['AND' => [
|
|
||||||
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
|
||||||
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
|
||||||
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
|
||||||
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(),
|
|
||||||
'name[!]' => ''],
|
|
||||||
"LIMIT" => 200
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
$places = json_decode(file_get_contents("http://gis.terranquest.net/places.php?key=" . GIS_API_KEY . "&lat=" . $VARS['lat'] . "&long=" . $VARS['long'] . "&radius=" . $radius), TRUE)['features'];
|
||||||
|
|
||||||
$data['status'] = 'OK';
|
$data['status'] = 'OK';
|
||||||
$data['places'] = $places;
|
$data['places'] = $places;
|
||||||
@ -86,30 +51,30 @@ if ($VARS['debug']) {
|
|||||||
echo "got to the game data loop ";
|
echo "got to the game data loop ";
|
||||||
}
|
}
|
||||||
foreach ($places as $place) {
|
foreach ($places as $place) {
|
||||||
if (!$database->has('locations', ['osmid' => $place['osmid']])) {
|
$osmid = $place['properties']['osm_id'];
|
||||||
$database->insert('locations', ['osmid' => $place['osmid'], 'teamid' => 0]);
|
$name = $place['properties']['name'];
|
||||||
|
$plong = $place['geometry']['coordinates'][0];
|
||||||
|
$plat = $place['geometry']['coordinates'][1];
|
||||||
|
if (!$database->has('locations', ['osmid' => $osmid])) {
|
||||||
|
$database->insert('locations', ['osmid' => $osmid, 'teamid' => 0]);
|
||||||
}
|
}
|
||||||
$gameinfo = $database->select('locations', ['locationid', 'teamid', 'currentlife', 'maxlife'], ['osmid' => $place['osmid']])[0];
|
$gameinfo = $database->select('locations', ['locationid', 'teamid', 'currentlife', 'maxlife'], ['osmid' => $osmid])[0];
|
||||||
// Reset owner info for dead places
|
// Reset owner info for dead places
|
||||||
if ($gameinfo['currentlife'] <= 0) {
|
if ($gameinfo['currentlife'] <= 0) {
|
||||||
$database->update('locations', ['teamid' => 0, 'owneruuid' => null], ['locationid' => $gameinfo['locationid']]);
|
$database->update('locations', ['teamid' => 0, 'owneruuid' => null], ['locationid' => $gameinfo['locationid']]);
|
||||||
$gameinfo = $database->select('locations', ['locationid', 'teamid', 'currentlife', 'maxlife'], ['osmid' => $place['osmid']])[0];
|
$gameinfo = $database->select('locations', ['locationid', 'teamid', 'currentlife', 'maxlife'], ['osmid' => $osmid])[0];
|
||||||
}
|
}
|
||||||
$geo['features'][] = array("type" => "Feature",
|
$geo['features'][] = array("type" => "Feature",
|
||||||
"geometry" => [
|
"geometry" => [
|
||||||
"type" => "Point",
|
"type" => "Point",
|
||||||
"coordinates" => [
|
"coordinates" => [
|
||||||
floatval($place['longitude']),
|
floatval($plong),
|
||||||
floatval($place['latitude'])
|
floatval($plat)
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"properties" => [
|
"properties" => [
|
||||||
"osm_id" => intval($place['osmid']),
|
"osm_id" => intval($osmid),
|
||||||
"name" => ($place['name'] == '' ? null : $place['name']),
|
"name" => $name,
|
||||||
"name:en" => ($place['name'] == '' ? null : $place['name']),
|
|
||||||
"amenity" => ($place['amenity'] == '' ? null : $place['amenity']),
|
|
||||||
"historic" => ($place['historic'] == '' ? null : $place['historic']),
|
|
||||||
"tourism" => ($place['tourism'] == '' ? null : $place['tourism']),
|
|
||||||
"gameinfo" => $gameinfo//['teamid' => $gameinfo['teamid'], 'owneruuid' => $gameinfo['owneruuid']]
|
"gameinfo" => $gameinfo//['teamid' => $gameinfo['teamid'], 'owneruuid' => $gameinfo['owneruuid']]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -10,13 +10,6 @@ define("DB_USER", "");
|
|||||||
define("DB_PASS", "");
|
define("DB_PASS", "");
|
||||||
define("DB_CHARSET", "latin1");
|
define("DB_CHARSET", "latin1");
|
||||||
|
|
||||||
define("PDB_TYPE", "mysql");
|
|
||||||
define("PDB_NAME", "");
|
|
||||||
define("PDB_SERVER", "");
|
|
||||||
define("PDB_USER", "");
|
|
||||||
define("PDB_PASS", "");
|
|
||||||
define("PDB_CHARSET", "latin1");
|
|
||||||
|
|
||||||
define("MIN_CLIENT_VERSION", "1.6.0");
|
define("MIN_CLIENT_VERSION", "1.6.0");
|
||||||
|
|
||||||
define("GEOCACHE_KEY", "");
|
define("GEOCACHE_KEY", "");
|
||||||
|
Reference in New Issue
Block a user