]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/GeonamesPlugin.php
Remove more contractions
[quix0rs-gnu-social.git] / plugins / GeonamesPlugin.php
index 745cd4126f80463a347c327a77694550b56292e4..8059d49d78ed568d5f034ad18b5cd2480bd20bf8 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];
 
@@ -87,12 +87,12 @@ class GeonamesPlugin extends Plugin
                 $location->location_id      = $n->geonameId;
                 $location->location_ns      = self::NAMESPACE;
 
-                // handled, don't continue processing!
+                // handled, do not continue processing!
                 return false;
             }
         }
 
-        // Continue processing; we don't have the answer
+        // Continue processing; we do not have the answer
         return true;
     }
 
@@ -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) {
 
@@ -217,7 +217,7 @@ class GeonamesPlugin extends Plugin
             }
         }
 
-        // For some reason we don't know, so pass.
+        // For some reason we do not know, so pass.
 
         return true;
     }
@@ -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 do not process further.
+        return false;
+    }
 }