From 553b1d03d711d80c9b5ffe2e1ffc68518f59a592 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 27 Apr 2009 19:16:38 +0000 Subject: [PATCH] Fix HEAD link issues with RssFeed with exporting. Refactor the module so that getting the feed url will return the static URL when exporting. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/AssetAspect/RssFeed.pm | 103 +++++++++++++++++++++--------- t/AssetAspect/RssFeed.t | 2 + 3 files changed, 75 insertions(+), 31 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index a4b6cdb0a..cd01c3f86 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -7,6 +7,7 @@ - fixed #10047: SQLReport Debug doesn't catch when bind variables are incorrect - fixed #10260: WebGUI::Asset::Wobject::Gallery.pm default search date misfunction - fixed #10238: Edit Calendar Event not working when proxy cache disabled + - Fixed a bug in the RssFeed aspect that would cause the wrong HEAD links to be made for the feeds when exporting. 7.7.4 - rfe: Extend DateTime for Week-Nrs (#9151) diff --git a/lib/WebGUI/AssetAspect/RssFeed.pm b/lib/WebGUI/AssetAspect/RssFeed.pm index 718f38e58..b1caab66f 100644 --- a/lib/WebGUI/AssetAspect/RssFeed.pm +++ b/lib/WebGUI/AssetAspect/RssFeed.pm @@ -220,7 +220,7 @@ sub exportAssetCollateral { $reportSession->output->print('
'); } - foreach my $ext (qw( rss atom )) { + foreach my $ext (qw( rss atom rdf )) { my $dest = Path::Class::File->new($filedir, $filenameBase . '.' . $ext); # tell the user which asset we're exporting. @@ -313,95 +313,136 @@ sub getRssFeedItems { #------------------------------------------------------------------- +=head2 _getFeedUrl ($extension) + +Generic method for returning the URL for a type of feed. If the special scratch variable +isExporting is true, the static url (url based vs asset function based) will be returned +instead. + +=head3 $extension + +The kind of feed that is requested. Valid extensions are "rss", "atom" or "rdf". + +=cut + +sub _getFeedUrl { + my $self = shift; + my $extension = shift; + if ( $self->session->scratch->get('isExporting') ) { + return $self->_getStaticFeedUrl($extension); + } + return $self->getUrl("func=view\u$extension"); +} + +#------------------------------------------------------------------- + +=head2 _getStaticFeedUrl ($extension) + +Generic method for returning the static URL for a type of feed. + +=head3 $extension + +The kind of feed that is requested. Valid extensions are "rss", "atom" or "rdf". + +=cut + +sub _getStaticFeedUrl { + my $self = shift; + my $extension = shift; + my $url = $self->get("url") . '.' . $extension; + $url = $self->session->url->gateway($url); + if ($self->get("encryptPage")) { + $url = $self->session->url->getSiteURL . $url; + $url =~ s/^http:/https:/; + } + return $url; +} + +#------------------------------------------------------------------- + =head2 getAtomFeedUrl () -Returns $self->getUrl('func=viewAtom'). +Returns the URL for this asset's feed in Atom format. If the special scratch variable +isExporting is true, the static url (url based vs asset function based) will be returned +instead. + =cut sub getAtomFeedUrl { - shift->getUrl("func=viewAtom"); + my $self = shift; + return $self->_getFeedUrl('atom'); } #------------------------------------------------------------------- =head2 getRdfFeedUrl () -Returns $self->getUrl('func=viewRdf'). +Returns the URL for this asset's feed in RDF format. If the special scratch variable +isExporting is true, the static url (url based vs asset function based) will be returned +instead. + =cut sub getRdfFeedUrl { - shift->getUrl("func=viewRdf"); + my $self = shift; + return $self->_getFeedUrl('rdf'); } #------------------------------------------------------------------- =head2 getRssFeedUrl () -Returns $self->getUrl('func=viewRss'). +Returns the URL for this asset's feed in RSS 2.0 format. If the special scratch variable +isExporting is true, the static url (url based vs asset function based) will be returned +instead. + =cut sub getRssFeedUrl { - shift->getUrl("func=viewRss"); + my $self = shift; + return $self->_getFeedUrl('rss'); } #------------------------------------------------------------------- =head2 getStaticAtomFeedUrl () -Returns the current asset's URL with .atom concatenated onto it. +Returns the URL to use when exporting for this asset's feed in Atom format. =cut sub getStaticAtomFeedUrl { my $self = shift; - my $url = $self->get("url") . '.atom'; - $url = $self->session->url->gateway($url); - if ($self->get("encryptPage")) { - $url = $self->session->url->getSiteURL . $url; - $url =~ s/^http:/https:/; - } - return $url; + return $self->_getStaticFeedUrl('atom'); } #------------------------------------------------------------------- =head2 getStaticRdfFeedUrl () -Returns the current asset's URL with .rdf concatenated onto it. +Returns the URL to use when exporting for this asset's feed in RDF format. =cut sub getStaticRdfFeedUrl { my $self = shift; - my $url = $self->get("url") . '.rdf'; - $url = $self->session->url->gateway($url); - if ($self->get("encryptPage")) { - $url = $self->session->url->getSiteURL . $url; - $url =~ s/^http:/https:/; - } - return $url; + return $self->_getStaticFeedUrl('rdf'); } #------------------------------------------------------------------- =head2 getStaticRssFeedUrl () -Returns the current asset's URL with .rss concatenated onto it. +Returns the URL to use when exporting for this asset's feed in RSS 2.0 format. =cut sub getStaticRssFeedUrl { my $self = shift; - my $url = $self->get("url") . '.rss'; - $url = $self->session->url->gateway($url); - if ($self->get("encryptPage")) { - $url = $self->session->url->getSiteURL . $url; - $url =~ s/^http:/https:/; - } - return $url; + return $self->_getStaticFeedUrl('rss'); } #------------------------------------------------------------------- diff --git a/t/AssetAspect/RssFeed.t b/t/AssetAspect/RssFeed.t index d0c004b4b..d7b1dd14b 100644 --- a/t/AssetAspect/RssFeed.t +++ b/t/AssetAspect/RssFeed.t @@ -157,6 +157,7 @@ cmp_bag( [qw/ shawshank.rss shawshank shawshank.atom + shawshank.rdf /], 'exportAssetCollateral: feed files exported, index.html file' ); @@ -172,6 +173,7 @@ cmp_bag( [qw/ shawshank.html.rss shawshank.html.atom + shawshank.html.rdf /], 'exportAssetCollateral: feed files exported, shawshank.html file' );