Browse Source

Switch places.php over to GIS API, remove external placedb connection

Skylar Ittner 2 years ago
parent
commit
84413765f7
2 changed files with 13 additions and 55 deletions
  1. 13
    48
      places.php
  2. 0
    7
      settings.template.php

+ 13
- 48
places.php View File

@@ -9,21 +9,6 @@ require 'required.php';
9 9
 
10 10
 //ini_set('memory_limit','32M');
11 11
 
12
-$placebase;
13
-try {
14
-    $placebase = new medoo([
15
-        'database_type' => PDB_TYPE,
16
-        'database_name' => PDB_NAME,
17
-        'server' => PDB_SERVER,
18
-        'username' => PDB_USER,
19
-        'password' => PDB_PASS,
20
-        'charset' => PDB_CHARSET
21
-    ]);
22
-} catch (Exception $ex) {
23
-    header('HTTP/1.1 500 Internal Server Error');
24
-    sendError('Location database error.  Try again later.', true);
25
-}
26
-
27 12
 use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
28 13
 
29 14
 if (is_empty($VARS['lat'])) {
@@ -50,31 +35,11 @@ if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) {
50 35
     $radius = floatval($VARS['radius']);
51 36
 }
52 37
 
53
-$userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']);
54
-$searchbounds = $userlocation->boundingCoordinates($radius, 'miles');
55 38
 if ($VARS['debug']) {
56 39
     echo "got to the place data query ";
57 40
 }
58
-if (is_empty($VARS['names'])) {
59
-    $places = $placebase->select('places', '*', ['AND' => [
60
-            'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
61
-            'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
62
-            'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
63
-            'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
64
-        "LIMIT" => 200
65
-    ]);
66
-} else {
67
-    $places = $placebase->select('places', '*', ['AND' => [
68
-            'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
69
-            'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
70
-            'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
71
-            'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(),
72
-            'name[!]' => ''],
73
-        "LIMIT" => 200
74
-    ]);
75
-}
76
-
77 41
 
42
+$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'];
78 43
 
79 44
 $data['status'] = 'OK';
80 45
 $data['places'] = $places;
@@ -86,30 +51,30 @@ if ($VARS['debug']) {
86 51
     echo "got to the game data loop ";
87 52
 }
88 53
 foreach ($places as $place) {
89
-    if (!$database->has('locations', ['osmid' => $place['osmid']])) {
90
-        $database->insert('locations', ['osmid' => $place['osmid'], 'teamid' => 0]);
54
+    $osmid = $place['properties']['osm_id'];
55
+    $name = $place['properties']['name'];
56
+    $plong = $place['geometry']['coordinates'][0];
57
+    $plat = $place['geometry']['coordinates'][1];
58
+    if (!$database->has('locations', ['osmid' => $osmid])) {
59
+        $database->insert('locations', ['osmid' => $osmid, 'teamid' => 0]);
91 60
     }
92
-    $gameinfo = $database->select('locations', ['locationid', 'teamid', 'currentlife', 'maxlife'], ['osmid' => $place['osmid']])[0];
61
+    $gameinfo = $database->select('locations', ['locationid', 'teamid', 'currentlife', 'maxlife'], ['osmid' => $osmid])[0];
93 62
     // Reset owner info for dead places
94 63
     if ($gameinfo['currentlife'] <= 0) {
95 64
         $database->update('locations', ['teamid' => 0, 'owneruuid' => null], ['locationid' => $gameinfo['locationid']]);
96
-        $gameinfo = $database->select('locations', ['locationid', 'teamid', 'currentlife', 'maxlife'], ['osmid' => $place['osmid']])[0];
65
+        $gameinfo = $database->select('locations', ['locationid', 'teamid', 'currentlife', 'maxlife'], ['osmid' => $osmid])[0];
97 66
     }
98 67
     $geo['features'][] = array("type" => "Feature",
99 68
         "geometry" => [
100 69
             "type" => "Point",
101 70
             "coordinates" => [
102
-                floatval($place['longitude']),
103
-                floatval($place['latitude'])
71
+                floatval($plong),
72
+                floatval($plat)
104 73
             ]
105 74
         ],
106 75
         "properties" => [
107
-            "osm_id" => intval($place['osmid']),
108
-            "name" => ($place['name'] == '' ? null : $place['name']),
109
-            "name:en" => ($place['name'] == '' ? null : $place['name']),
110
-            "amenity" => ($place['amenity'] == '' ? null : $place['amenity']),
111
-            "historic" => ($place['historic'] == '' ? null : $place['historic']),
112
-            "tourism" => ($place['tourism'] == '' ? null : $place['tourism']),
76
+            "osm_id" => intval($osmid),
77
+            "name" => $name,
113 78
             "gameinfo" => $gameinfo//['teamid' => $gameinfo['teamid'], 'owneruuid' => $gameinfo['owneruuid']]
114 79
         ]
115 80
     );

+ 0
- 7
settings.template.php View File

@@ -10,13 +10,6 @@ define("DB_USER", "");
10 10
 define("DB_PASS", "");
11 11
 define("DB_CHARSET", "latin1");
12 12
 
13
-define("PDB_TYPE", "mysql");
14
-define("PDB_NAME", "");
15
-define("PDB_SERVER", "");
16
-define("PDB_USER", "");
17
-define("PDB_PASS", "");
18
-define("PDB_CHARSET", "latin1");
19
-
20 13
 define("MIN_CLIENT_VERSION", "1.6.0");
21 14
 
22 15
 define("GEOCACHE_KEY", "");

Loading…
Cancel
Save