X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FGeonamesPlugin.php;h=e18957c36d9dd561cca16fee49fd8d45a1250cf9;hb=707efadbd4b44435741ad9b2b972a77f4069e689;hp=745cd4126f80463a347c327a77694550b56292e4;hpb=61ccf450de29a0433cd35415c6f2a3c7bbcbb91b;p=quix0rs-gnu-social.git diff --git a/plugins/GeonamesPlugin.php b/plugins/GeonamesPlugin.php index 745cd4126f..e18957c36d 100644 --- a/plugins/GeonamesPlugin.php +++ b/plugins/GeonamesPlugin.php @@ -74,8 +74,8 @@ class GeonamesPlugin extends Plugin $result = $client->get('http://ws.geonames.org/search?'.$str); - if ($result->code == "200") { - $rj = json_decode($result->body); + if ($result->isOk()) { + $rj = json_decode($result->getBody()); if (count($rj->geonames) > 0) { $n = $rj->geonames[0]; @@ -121,9 +121,9 @@ class GeonamesPlugin extends Plugin $result = $client->get('http://ws.geonames.org/hierarchyJSON?'.$str); - if ($result->code == "200") { + if ($result->isOk()) { - $rj = json_decode($result->body); + $rj = json_decode($result->getBody()); if (count($rj->geonames) > 0) { @@ -182,9 +182,9 @@ class GeonamesPlugin extends Plugin $result = $client->get('http://ws.geonames.org/findNearbyPlaceNameJSON?'.$str); - if ($result->code == "200") { + if ($result->isOk()) { - $rj = json_decode($result->body); + $rj = json_decode($result->getBody()); if (count($rj->geonames) > 0) { @@ -249,9 +249,9 @@ class GeonamesPlugin extends Plugin $result = $client->get('http://ws.geonames.org/hierarchyJSON?'.$str); - if ($result->code == "200") { + if ($result->isOk()) { - $rj = json_decode($result->body); + $rj = json_decode($result->getBody()); if (count($rj->geonames) > 0) { @@ -278,4 +278,28 @@ class GeonamesPlugin extends Plugin return true; } + + /** + * Human-readable name for a location + * + * Given a location, we try to retrieve a geonames.org URL. + * + * @param Location $location Location to get the url for + * @param string &$url Place to put the url + * + * @return boolean whether to continue + */ + + function onLocationUrl($location, &$url) + { + if ($location->location_ns != self::NAMESPACE) { + // It's not one of our IDs... keep processing + return true; + } + + $url = 'http://www.geonames.org/' . $location->location_id; + + // it's been filled, so don't process further. + return false; + } }