From a3623b784b8c463dbedbfca02a715eb380c74fe1 Mon Sep 17 00:00:00 2001 From: dbs Date: Sun, 29 Jun 2008 07:07:00 +0000 Subject: [PATCH] Address a few RSS and Atom feed validation problems: * Make OPAC URLs absolute (needs refinement to respect locale/skin) * Push datetime creation down to the feed and item level * Atom: * Merge summary fields into a single element * RSS2: * Generate a channel/description field * Merge item/description fields into a single element * Use RFC-822 dates (adds DateTime::Format::Mail as a prerequisite) * Set guid isPermaLink attribute false as we're using tag: URIs * Place alternate link elements in the xhtml namespace * Generate a link element with no attributes git-svn-id: svn://svn.open-ils.org/ILS/trunk@9950 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/Makefile.install | 1 + Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm | 16 +++-- .../src/perlmods/OpenILS/WWW/SuperCat/Feed.pm | 67 +++++++++++++++---- Open-ILS/xsl/MARC21slim2ATOM.xsl | 17 +++-- Open-ILS/xsl/MARC21slim2RSS2.xsl | 12 ++-- 5 files changed, 83 insertions(+), 30 deletions(-) diff --git a/Open-ILS/src/extras/Makefile.install b/Open-ILS/src/extras/Makefile.install index 26dd7e6c88..980f7e0747 100644 --- a/Open-ILS/src/extras/Makefile.install +++ b/Open-ILS/src/extras/Makefile.install @@ -101,6 +101,7 @@ DEBS = \ libclass-dbi-abstractsearch-perl\ libtemplate-perl\ libtext-aspell-perl\ + libdatetime-format-mail-perl\ libdatetime-timezone-perl\ libdatetime-perl\ libunix-syslog-perl\ diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm index a348336bc5..f3bf99d040 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm @@ -412,7 +412,7 @@ sub unapi { $feed->root($root); $feed->creator($host); - $feed->update_ts(gmtime_ISO8601()); + $feed->update_ts(); $feed->link( unapi => $base) if ($flesh_feed); print "Content-type: ". $feed->type ."; charset=utf-8\n\n"; @@ -656,7 +656,9 @@ sub supercat { $feed->root($root); $feed->creator($host); - $feed->update_ts(gmtime_ISO8601()); + + $feed->update_ts(); + $feed->link( unapi => $base) if ($flesh_feed); print "Content-type: ". $feed->type ."; charset=utf-8\n\n"; @@ -745,7 +747,7 @@ sub bookbag_feed { $feed->title("Items in Book Bag [".$bucket->name."]"); $feed->creator($host); - $feed->update_ts(gmtime_ISO8601()); + $feed->update_ts(); $feed->link(alternate => $base . "/rss2-full/$id" => 'application/rss+xml'); $feed->link(atom => $base . "/atom-full/$id" => 'application/atom+xml'); @@ -754,7 +756,7 @@ sub bookbag_feed { $feed->link( OPAC => - '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' . + $host . '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' . join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ), 'text/html' ); @@ -814,7 +816,7 @@ sub changes_feed { } $feed->creator($host); - $feed->update_ts(gmtime_ISO8601()); + $feed->update_ts(); $feed->link(alternate => $base . "/rss2-full/$rtype/$axis/$limit/$date" => 'application/rss+xml'); $feed->link(atom => $base . "/atom-full/$rtype/$axis/$limit/$date" => 'application/atom+xml'); @@ -823,7 +825,7 @@ sub changes_feed { $feed->link( OPAC => - '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' . + $host . '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' . join('&', map { 'rl=' . $_} @$list ), 'text/html' ); @@ -1069,7 +1071,7 @@ sub opensearch_feed { $feed->title("Search results for [$terms] at ".$org_unit->[0]->name); $feed->creator($host); - $feed->update_ts(gmtime_ISO8601()); + $feed->update_ts(); $feed->_create_node( $feed->{item_xpath}, diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm index ba9d3cc848..bce56dd350 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm @@ -6,6 +6,9 @@ use XML::LibXML; use XML::LibXSLT; use OpenSRF::Utils::SettingsClient; use CGI; +use DateTime; +use DateTime::Format::Mail; + sub exists { my $class = shift; @@ -225,6 +228,7 @@ sub creator {}; package OpenILS::WWW::SuperCat::Feed::atom; use base 'OpenILS::WWW::SuperCat::Feed'; +use OpenSRF::Utils qw/:datetime/; sub new { my $class = shift; @@ -244,7 +248,8 @@ sub title { sub update_ts { my $self = shift; - my $text = shift; + # ATOM demands RFC-3339 compliant datetime formats + my $text = shift || gmtime_ISO8601(); $self->_create_node($self->{item_xpath},'http://www.w3.org/2005/Atom','updated', $text); } @@ -317,11 +322,15 @@ sub title { my $self = shift; my $text = shift; $self->_create_node('/rss/channel',undef,'title', $text); + # RSS2 demands a /channel/description element; just dupe title until we give + # users the ability to provide a description for their bookbags + $self->_create_node('/rss/channel',undef,'description', $text); } sub update_ts { my $self = shift; - my $text = shift; + # RSS2 demands RFC-822 compliant datetime formats + my $text = shift || DateTime::Format::Mail->format_datetime(DateTime->now()); $self->_create_node($self->{item_xpath},undef,'lastBuildDate', $text); } @@ -337,17 +346,27 @@ sub link { my $id = shift; my $mime = shift || "application/x-$type+xml"; - $type = 'self' if ($type eq 'rss2'); - - $self->_create_node( - $self->{item_xpath}, - undef, - 'link', - $id, - { rel => $type, - type => $mime, - } - ); + if ($type eq 'rss2' or $type eq 'alternate') { + # Just link to ourself using standard RSS2 link element + $self->_create_node( + $self->{item_xpath}, + undef, + 'link', + $id, + undef + ); + } else { + # Alternate link: use XHTML link element + $self->_create_node( + $self->{item_xpath}, + 'http://www.w3.org/1999/xhtml', + 'xhtml:link', + $id, + { rel => $type, + type => $mime, + } + ); + } } sub id { @@ -372,11 +391,33 @@ sub new { sub update_ts { my $self = shift; + # RSS2 demands RFC-822 compliant datetime formats my $text = shift; + if (!$text) { + # No date passed in, default to now + $text = DateTime::Format::Mail->format_datetime(DateTime->now()); + } elsif ($text =~ m/^\s*(\d{4})\.?\s*$/o) { + # Publication date is just a year, convert accordingly + my $year = DateTime->new(year=>$1); + $text = DateTime::Format::Mail->format_datetime($year); + } $self->_create_node($self->{item_xpath},undef,'pubDate', $text); } +sub id { + my $self = shift; + my $id = shift; + $self->_create_node( + $self->{item_xpath}, + undef, + 'guid', + $id, + { + isPermaLink=>"false" + } + ); +} #---------------------------------------------------------- diff --git a/Open-ILS/xsl/MARC21slim2ATOM.xsl b/Open-ILS/xsl/MARC21slim2ATOM.xsl index e706763b41..dd0c7e1497 100644 --- a/Open-ILS/xsl/MARC21slim2ATOM.xsl +++ b/Open-ILS/xsl/MARC21slim2ATOM.xsl @@ -24,6 +24,7 @@ + @@ -77,17 +78,23 @@ + - - - - - + + + + + + diff --git a/Open-ILS/xsl/MARC21slim2RSS2.xsl b/Open-ILS/xsl/MARC21slim2RSS2.xsl index 8461557f5a..bb8f852a00 100644 --- a/Open-ILS/xsl/MARC21slim2RSS2.xsl +++ b/Open-ILS/xsl/MARC21slim2RSS2.xsl @@ -78,6 +78,7 @@ + @@ -94,11 +95,12 @@ - - - - - + + + + + + -- 2.43.2