]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/GeonamesPlugin.php
Some more XRDS fixes. With this and the previous commit, remote subs seem to work...
[quix0rs-gnu-social.git] / plugins / GeonamesPlugin.php
index 745cd4126f80463a347c327a77694550b56292e4..e18957c36d9dd561cca16fee49fd8d45a1250cf9 100644 (file)
@@ -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;
+    }
 }