RssFeed fixes and cleanups
This commit is contained in:
parent
c1ac5b9761
commit
ca4a9add6d
4 changed files with 57 additions and 52 deletions
|
|
@ -246,11 +246,11 @@ sub getTemplateVariables {
|
|||
my ($self, $feed) = @_;
|
||||
my @items = $feed->get_item;
|
||||
my %var;
|
||||
$var{channel_title} = WebGUI::HTML::filter($feed->title, 'javascript');
|
||||
$var{channel_title} = WebGUI::HTML::filter(scalar $feed->title, 'javascript');
|
||||
$var{channel_description} = WebGUI::HTML::filter(scalar($feed->description), 'javascript');
|
||||
$var{channel_date} = WebGUI::HTML::filter(scalar($feed->get_pubDate_epoch), 'javascript');
|
||||
$var{channel_copyright} = WebGUI::HTML::filter(scalar($feed->copyright), 'javascript');
|
||||
$var{channel_link} = WebGUI::HTML::filter($feed->link, 'javascript');
|
||||
$var{channel_link} = WebGUI::HTML::filter(scalar $feed->link, 'javascript');
|
||||
my @image = $feed->image;
|
||||
$var{channel_image_url} = WebGUI::HTML::filter($image[0], 'javascript');
|
||||
$var{channel_image_title} = WebGUI::HTML::filter($image[1], 'javascript');
|
||||
|
|
@ -260,12 +260,12 @@ sub getTemplateVariables {
|
|||
$var{channel_image_height} = WebGUI::HTML::filter($image[5], 'javascript');
|
||||
foreach my $object (@items) {
|
||||
my %item;
|
||||
$item{title} = WebGUI::HTML::filter($object->title, 'javascript');
|
||||
$item{date} = WebGUI::HTML::filter($object->get_pubDate_epoch, 'javascript');
|
||||
$item{category} = WebGUI::HTML::filter($object->category, 'javascript');
|
||||
$item{author} = WebGUI::HTML::filter($object->author, 'javascript');
|
||||
$item{guid} = WebGUI::HTML::filter($object->guid, 'javascript');
|
||||
$item{link} = WebGUI::HTML::filter($object->link, 'javascript');
|
||||
$item{title} = WebGUI::HTML::filter(scalar $object->title, 'javascript');
|
||||
$item{date} = WebGUI::HTML::filter(scalar $object->get_pubDate_epoch, 'javascript');
|
||||
$item{category} = WebGUI::HTML::filter(scalar $object->category, 'javascript');
|
||||
$item{author} = WebGUI::HTML::filter(scalar $object->author, 'javascript');
|
||||
$item{guid} = WebGUI::HTML::filter(scalar $object->guid, 'javascript');
|
||||
$item{link} = WebGUI::HTML::filter(scalar $object->link, 'javascript');
|
||||
$item{description} = WebGUI::HTML::filter(scalar($object->description), 'javascript');
|
||||
$item{descriptionFirst100words} = $item{description};
|
||||
$item{descriptionFirst100words} =~ s/(((\S+)\s+){100}).*/$1/s;
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ particular asset.
|
|||
=head3 params
|
||||
|
||||
A hashref with the quiet, userId, depth, and indexFileName parameters from
|
||||
L<exportAsHtml>.
|
||||
L<WebGUI::Asset/exportAsHtml>.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -151,11 +151,14 @@ sub exportAssetCollateral {
|
|||
my $self = shift;
|
||||
my $basepath = shift;
|
||||
my $args = shift;
|
||||
|
||||
my $reportSession = shift;
|
||||
|
||||
my $reporti18n = WebGUI::International->new($self->session, 'Asset');
|
||||
|
||||
my $basename = $basepath->basename;
|
||||
my $filedir;
|
||||
my $filenameBase;
|
||||
|
||||
|
||||
# We want our .rss and .atom files to "appear" at the same level as the asset.
|
||||
if ($basename eq 'index.html') {
|
||||
# Get the 2nd ancestor, since the asset url had no dot in it (and it therefore
|
||||
|
|
@ -171,59 +174,60 @@ sub exportAssetCollateral {
|
|||
# just use the basename.
|
||||
$filenameBase = $basename;
|
||||
}
|
||||
|
||||
$self->{ '_masterSession' }->output->print('<br />') unless ($args->{quiet});
|
||||
|
||||
|
||||
if ( $reportSession && !$args->{quiet} ) {
|
||||
$reportSession->output->print('<br />');
|
||||
}
|
||||
|
||||
foreach my $ext (qw( rss atom )) {
|
||||
my $dest = Path::Class::File->new($filedir, $filenameBase . '.' . $ext);
|
||||
|
||||
|
||||
# tell the user which asset we're exporting.
|
||||
unless ($args->{quiet}) {
|
||||
my $message = sprintf $self->{ '_masteri18n' }->get('exporting page'), $dest->absolute->stringify;
|
||||
$self->{ '_masterSession' }->output->print(' '.$message);
|
||||
if ( $reportSession && !$args->{quiet} ) {
|
||||
my $message = sprintf $reporti18n->get('exporting page'), $dest->absolute->stringify;
|
||||
$reportSession->output->print(
|
||||
' ' . $message . '<br />');
|
||||
}
|
||||
|
||||
my $exportSession = WebGUI::Session->open(
|
||||
$self->session->config->getWebguiRoot,
|
||||
$self->session->config->getFilename,
|
||||
undef,
|
||||
undef,
|
||||
$self->session->getId,
|
||||
);
|
||||
|
||||
# open another session as the user doing the exporting...
|
||||
my $tempSession = WebGUI::Session->open($self->session->config->getWebguiRoot,$self->session->config->getFilename);
|
||||
$tempSession->user( { userId => $self->session->user->userId } );
|
||||
|
||||
my $selfdupe = WebGUI::Asset->newByDynamicClass( $tempSession, $self->getId );
|
||||
|
||||
|
||||
my $selfdupe = WebGUI::Asset->newByDynamicClass( $exportSession, $self->getId );
|
||||
|
||||
# next, get the contents, open the file, and write the contents to the file.
|
||||
my $fh = eval { $dest->open('>:utf8') };
|
||||
if($@) {
|
||||
WebGUI::Error->throw(error => "can't open " . $dest->absolute->stringify . " for writing: $!");
|
||||
$exportSession->close;
|
||||
}
|
||||
my $previousHandle = $selfdupe->session->{_handle};
|
||||
my $previousDefaultAsset = $selfdupe->session->asset;
|
||||
$selfdupe->session->asset($selfdupe);
|
||||
$selfdupe->session->output->setHandle($fh);
|
||||
$exportSession->asset($selfdupe);
|
||||
$exportSession->output->setHandle($fh);
|
||||
my $contents;
|
||||
if ($ext eq 'rss') {
|
||||
$contents = $selfdupe->www_viewRss;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$contents = $selfdupe->www_viewAtom;
|
||||
} # add more for more extensions.
|
||||
|
||||
# chunked content is already printed, no need to print it again
|
||||
unless($contents eq 'chunked') {
|
||||
$tempSession->output->print($contents);
|
||||
$exportSession->output->print($contents);
|
||||
}
|
||||
|
||||
$tempSession->output->setHandle($previousHandle);
|
||||
|
||||
# properly close the temp session
|
||||
$tempSession->var->end;
|
||||
$tempSession->close;
|
||||
|
||||
$exportSession->close;
|
||||
|
||||
# tell the user we did this asset collateral correctly
|
||||
unless( $args->{quiet} ) {
|
||||
$self->{ '_masterSession' }->output->print($self->{ '_masteri18n' }->get('done'));
|
||||
if ( $reportSession && !$args->{quiet} ) {
|
||||
$reportSession->output->print($reporti18n->get('done'));
|
||||
}
|
||||
|
||||
}
|
||||
return $self->next::method($basepath, $args);
|
||||
return $self->next::method($basepath, $args, $reportSession);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -247,7 +251,7 @@ sub getRssFeedItems {
|
|||
|
||||
=head2 getAtomFeedUrl ()
|
||||
|
||||
Returns $self->getUrl(“func=viewAtom”).
|
||||
Returns $self->getUrl('func=viewAtom').
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -259,7 +263,7 @@ sub getAtomFeedUrl {
|
|||
|
||||
=head2 getRssFeedUrl ()
|
||||
|
||||
Returns $self->getUrl(“func=viewRss”).
|
||||
Returns $self->getUrl('func=viewRss').
|
||||
|
||||
=cut
|
||||
|
||||
|
|
|
|||
|
|
@ -330,15 +330,10 @@ sub exportAsHtml {
|
|||
$exportSession->close;
|
||||
return ($returnCode, $message);
|
||||
}
|
||||
|
||||
# Stash the current session and i18n into the asset so that exportAssetCollateral can
|
||||
# also write informative messages to the output terminal. :)
|
||||
$asset->{ '_masterSession' } = $self->session;
|
||||
$asset->{ '_masteri18n' } = $i18n;
|
||||
|
||||
|
||||
# next, tell the asset that we're exporting, so that it can export any
|
||||
# of its collateral or other extra data.
|
||||
eval { $asset->exportAssetCollateral($asset->exportGetUrlAsPath, $args) };
|
||||
eval { $asset->exportAssetCollateral($asset->exportGetUrlAsPath, $args, $session) };
|
||||
if($@) {
|
||||
$returnCode = 0;
|
||||
$message = $@;
|
||||
|
|
@ -392,7 +387,7 @@ sub exportAsHtml {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 exportAssetCollateral ( basePath, params )
|
||||
=head2 exportAssetCollateral ( basePath, params, [ session ] )
|
||||
|
||||
Plug in point for complicated assets (like the CS, the Calendar) to manage
|
||||
exporting their collateral data like other views, children threads and posts,
|
||||
|
|
@ -413,6 +408,10 @@ particular asset.
|
|||
A hashref with the quiet, userId, depth, and indexFileName parameters from
|
||||
L</exportAsHtml>.
|
||||
|
||||
=head3 session
|
||||
|
||||
The session doing the full export. Can be used to report status messages.
|
||||
|
||||
=cut
|
||||
|
||||
sub exportAssetCollateral {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,9 @@ $post = $collab->addChild($props,
|
|||
});
|
||||
|
||||
my $rssitems = $collab->getRssFeedItems();
|
||||
is(scalar@{ $rssitems }, 2, 'rssitems set to number of posts added');
|
||||
is(scalar @{ $rssitems }, 2, 'rssitems set to number of posts added');
|
||||
|
||||
is($collab->get('itemsPerFeed'), 25, 'itemsPerFeed is set to the default');
|
||||
|
||||
TODO: {
|
||||
local $TODO = "Tests to make later";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue