]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
tobyink's location RDF patch
authorCraig Andrews <candrews@integralblue.com>
Thu, 19 Nov 2009 17:00:25 +0000 (12:00 -0500)
committerCraig Andrews <candrews@integralblue.com>
Thu, 19 Nov 2009 17:00:25 +0000 (12:00 -0500)
actions/foaf.php
lib/location.php
lib/rssaction.php
plugins/GeonamesPlugin.php

index 356393304ed5abbc0a243bcd68e8974d395aa05b..e9f67b7f2bd0208e248bff5d30a8857a9e4d5113 100644 (file)
@@ -108,11 +108,29 @@ class FoafAction extends Action
         if ($this->profile->bio) {
             $this->element('bio:olb', null, $this->profile->bio);
         }
-        // XXX: more structured location data
-        if ($this->profile->location) {
+        
+        $location = $this->profile->getLocation();
+        if ($location) {
+            $attr = array();
+            if ($location->getRdfURL()) {
+                $attr['rdf:about'] = $location->getRdfURL();
+            }
+            $location_name = $location->getName();
+            
             $this->elementStart('based_near');
-            $this->elementStart('geo:SpatialThing');
-            $this->element('name', null, $this->profile->location);
+            $this->elementStart('geo:SpatialThing', $attr);
+            if ($location_name) {
+                $this->element('name', null, $location_name);
+            }
+            if ($location->lat) {
+                $this->element('geo:lat', null, $location->lat);
+            }
+            if ($location->lon) {
+                $this->element('geo:long', null, $location->lat);
+            }
+            if ($location->getURL()) {
+                $this->element('page', array('rdf:resource'=>$location->getURL()));
+            }
             $this->elementEnd('geo:SpatialThing');
             $this->elementEnd('based_near');
         }
index bbfc15a36d3929e817df561a05a59683593961b3..191550d6d6ca53e213f4a13f3b6b8bd2fc763a65 100644 (file)
@@ -52,6 +52,7 @@ class Location
     public  $location_id;
     public  $location_ns;
     private $_url;
+    private $_rdfurl;
 
     var $names = array();
 
@@ -185,4 +186,27 @@ class Location
 
         return $url;
     }
+
+    /**
+     * Get an URL for this location, suitable for embedding in RDF
+     *
+     * @return string URL for this location or NULL
+     */
+
+    function getRdfURL()
+    {
+        // Keep one cached
+
+        if (is_string($this->_rdfurl)) {
+            return $this->_rdfurl;
+        }
+
+        $url = null;
+
+        Event::handle('LocationRdfUrl', array($this, &$url));
+
+        $this->_rdfurl = $url;
+
+        return $url;
+    }
 }
index faf6bec7dec4618d8ebc4888c4e55353f8aff99a..cd4c8b51c4810894ffaa3f675c3a94ca66b20fef 100644 (file)
@@ -244,6 +244,16 @@ class Rss10Action extends Action
         $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
         $this->element('foaf:maker', array('rdf:resource' => $creator_uri));
         $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri.'#acct'));
+        $location = $notice->getLocation();
+        if ($location && isset($location->lat) && isset($location->lon)) {
+            $location_uri = $location->getRdfURL();
+            $attrs = array('geo:lat' => $location->lat,
+                'geo:long' => $location->lon);
+            if (strlen($location_uri)) {
+                $attrs['rdf:resource'] = $location_uri;
+            }
+            $this->element('statusnet:origin', $attrs);
+        }
         $this->element('statusnet:postIcon', array('rdf:resource' => $profile->avatarUrl()));
         $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
         if ($notice->reply_to) {
@@ -354,6 +364,8 @@ class Rss10Action extends Action
                                               'http://rdfs.org/sioc/types#',
                                               'xmlns:rdfs' =>
                                               'http://www.w3.org/2000/01/rdf-schema#',
+                                              'xmlns:geo' =>
+                                              'http://www.w3.org/2003/01/geo/wgs84_pos#',
                                               'xmlns:statusnet' =>
                                               'http://status.net/ont/',
                                               'xmlns' => 'http://purl.org/rss/1.0/'));
index 1d7381a802d9b5c5182ae5138731a8ac03819a1c..59232c1c55b376667109a5f249bac358ef710fa0 100644 (file)
@@ -302,4 +302,28 @@ class GeonamesPlugin extends Plugin
         // it's been filled, so don't process further.
         return false;
     }
+
+    /**
+     * Machine-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 onLocationRdfUrl($location, &$url)
+    {
+        if ($location->location_ns != self::LOCATION_NS) {
+            // It's not one of our IDs... keep processing
+            return true;
+        }
+
+        $url = 'http://sw.geonames.org/' . $location->location_id . '/';
+
+        // it's been filled, so don't process further.
+        return false;
+    }
 }