diff --git a/api/actions/nearby.php b/api/actions/nearby.php new file mode 100644 index 0000000..4ac7ed7 --- /dev/null +++ b/api/actions/nearby.php @@ -0,0 +1,74 @@ +boundingCoordinates($radius, "miles"); + +// (NPR voice): The following horrible workaround is brought to you by: +// Medoo bugs #797, #828, member stations, and viewers like you +ob_end_flush(); +ob_start(); +$people = $database->debug()->select("accounts", [ + "publicid", + "name", + "username", + "verified", + "latitude", + "longitude" + ], [ + "AND" => [ + 'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(), + 'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(), + 'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(), + 'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(), + "lastgpsfix[>]" => date("Y-m-d H:i:s", strtotime("-1 hour")), + "type" => 2 + ], + "LIMIT" => 20 + ] +); +$people = $database->query(ob_get_contents())->fetchAll(); +ob_end_clean(); +// No more really bad code allowed past this point + + +$nearby = []; + +foreach ($people as $person) { + $nearby[] = [ + "name" => (empty($person["name"]) ? $person["username"] : $person["name"]), + "username" => $person["username"], + "verified" => $person["verified"] == 1, + "publicid" => $person["publicid"], + "latitude" => $person["latitude"] * 1.0, + "longitude" => $person["longitude"] * 1.0 + ]; +} + +exitWithJson([ + "status" => "OK", + "radius" => $radius, + "bounds" => [ + 0 => [ + "latitude" => $searchbounds[0]->getLatitudeInDegrees(), + "longitude" => $searchbounds[0]->getLongitudeInDegrees() + ], + 1 => [ + "latitude" => $searchbounds[1]->getLatitudeInDegrees(), + "longitude" => $searchbounds[1]->getLongitudeInDegrees() + ], + ], + "nearby" => $nearby +]); diff --git a/api/apisettings.php b/api/apisettings.php index 2cc1a1f..b45a87d 100644 --- a/api/apisettings.php +++ b/api/apisettings.php @@ -65,5 +65,14 @@ $APIS = [ "key" => $keyregex, "id (optional)" => "/[0-9a-z]+/" ] - ] + ], + "getnearby" => [ + "load" => "nearby.php", + "vars" => [ + "key" => $keyregex, + "latitude" => "/-?[0-9]{2}\.[0-9]+/", + "longitude" => "/-?[0-9]{2,3}\.[0-9]+/", + "radius (optional)" => "/[0-9]*\.?[0-9]+/" + ] + ], ]; diff --git a/composer.json b/composer.json index fb37c32..c81c0af 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "type": "project", "require": { "catfan/medoo": "^1.5", - "guzzlehttp/guzzle": "^6.2" + "guzzlehttp/guzzle": "^6.2", + "anthonymartin/geo-location": "^1.0" }, "license": "MPL-2.0", "authors": [ diff --git a/composer.lock b/composer.lock index 07b730a..16e2713 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,53 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "e4e700119f47d2f68b0ed82abaf8c5c6", + "content-hash": "a4330dce069db4d0d962b670496ca8ef", "packages": [ + { + "name": "anthonymartin/geo-location", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/anthonymartin/GeoLocation.php.git", + "reference": "50bf026f069296dfae11aa195d987854b2e75855" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/anthonymartin/GeoLocation.php/zipball/50bf026f069296dfae11aa195d987854b2e75855", + "reference": "50bf026f069296dfae11aa195d987854b2e75855", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "class", + "autoload": { + "psr-0": { + "AnthonyMartin": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "CC 3.0" + ], + "authors": [ + { + "name": "Anthony Martin", + "email": "anthony@replaycreative.com", + "homepage": "http://replaycreative.com", + "role": "Developer" + } + ], + "description": "Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php", + "homepage": "https://github.com/anthonymartin/GeoLocation.php", + "keywords": [ + "bounding coordinates", + "distances", + "geocoding", + "geolocation" + ], + "time": "2016-09-17T18:05:14+00:00" + }, { "name": "catfan/medoo", "version": "v1.6.1", diff --git a/database.mwb b/database.mwb index d081387..9b44091 100644 Binary files a/database.mwb and b/database.mwb differ