From 10dc9078f5816eeb9c9dcc7394a29ac8c147d8f7 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 19 Nov 2009 16:42:04 +0000 Subject: Added lat and lon coordinates to notice location --- lib/noticelist.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/noticelist.php b/lib/noticelist.php index 3bad2cf7c..5877827ff 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -397,16 +397,21 @@ class NoticeListItem extends Widget return; } + $lat = $this->notice->lat; + $lon = $this->notice->lon; + $latlon = (!empty($lat) && !empty($lon)) ? $lat.';'.$lon : ''; + $url = $location->getUrl(); - // TODO: Output @title lat and lon on element @class geo - // e.g., class="geo" title="45.5088375;-73.587809" $this->out->elementStart('span', array('class' => 'location')); $this->out->text(_('at')); if (empty($url)) { - $this->out->element('span', array('class' => 'geo'), $name); + $this->out->element('span', array('class' => 'geo', + 'title' => $latlon), + $name); } else { $this->out->element('a', array('class' => 'geo', + 'title' => $latlon, 'href' => $url), $name); } -- cgit v1.2.3-54-g00ecf From 4463768baed036b487d473a60b30f0c314ee1673 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 19 Nov 2009 12:00:25 -0500 Subject: tobyink's location RDF patch --- actions/foaf.php | 26 ++++++++++++++++++++++---- lib/location.php | 24 ++++++++++++++++++++++++ lib/rssaction.php | 12 ++++++++++++ plugins/GeonamesPlugin.php | 24 ++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/actions/foaf.php b/actions/foaf.php index 356393304..e9f67b7f2 100644 --- a/actions/foaf.php +++ b/actions/foaf.php @@ -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'); } diff --git a/lib/location.php b/lib/location.php index bbfc15a36..191550d6d 100644 --- a/lib/location.php +++ b/lib/location.php @@ -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; + } } diff --git a/lib/rssaction.php b/lib/rssaction.php index faf6bec7d..cd4c8b51c 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -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/')); diff --git a/plugins/GeonamesPlugin.php b/plugins/GeonamesPlugin.php index 1d7381a80..59232c1c5 100644 --- a/plugins/GeonamesPlugin.php +++ b/plugins/GeonamesPlugin.php @@ -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; + } } -- cgit v1.2.3-54-g00ecf From ee22b2ccf9819cefba54ef38c6a57829c7d3fa73 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 19 Nov 2009 12:16:15 -0500 Subject: tobyink's RDF compatibility patch --- lib/rssaction.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/rssaction.php b/lib/rssaction.php index cd4c8b51c..3b303f73e 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -270,14 +270,7 @@ class Rss10Action extends Action foreach($attachments as $attachment){ $enclosure=$attachment->getEnclosure(); if ($enclosure) { - // DO NOT move xmlns declaration to root element. Making it - // the default namespace here improves compatibility with - // real-world feed readers. - $attribs = array( - 'rdf:resource' => $enclosure->url, - 'url' => $enclosure->url, - 'xmlns' => 'http://purl.oclc.org/net/rss_2.0/enc#' - ); + $attribs = array('rdf:resource' => $enclosure->url); if ($enclosure->title) { $attribs['dc:title'] = $enclosure->title; } @@ -285,12 +278,12 @@ class Rss10Action extends Action $attribs['dc:date'] = common_date_w3dtf($enclosure->modified); } if ($enclosure->size) { - $attribs['length'] = $enclosure->size; + $attribs['enc:length'] = $enclosure->size; } if ($enclosure->mimetype) { - $attribs['type'] = $enclosure->mimetype; + $attribs['enc:type'] = $enclosure->mimetype; } - $this->element('enclosure', $attribs); + $this->element('enc:enclosure', $attribs); } $this->element('sioc:links_to', array('rdf:resource'=>$attachment->url)); } @@ -358,6 +351,8 @@ class Rss10Action extends Action 'http://commontag.org/ns#', 'xmlns:foaf' => 'http://xmlns.com/foaf/0.1/', + 'xmlns:enc' => + 'http://purl.oclc.org/net/rss_2.0/enc#', 'xmlns:sioc' => 'http://rdfs.org/sioc/ns#', 'xmlns:sioct' => -- cgit v1.2.3-54-g00ecf