RssFeed fixes and cleanups

This commit is contained in:
Graham Knop 2009-04-02 16:24:44 +00:00
parent c1ac5b9761
commit ca4a9add6d
4 changed files with 57 additions and 52 deletions

View file

@ -246,11 +246,11 @@ sub getTemplateVariables {
my ($self, $feed) = @_; my ($self, $feed) = @_;
my @items = $feed->get_item; my @items = $feed->get_item;
my %var; 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_description} = WebGUI::HTML::filter(scalar($feed->description), 'javascript');
$var{channel_date} = WebGUI::HTML::filter(scalar($feed->get_pubDate_epoch), '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_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; my @image = $feed->image;
$var{channel_image_url} = WebGUI::HTML::filter($image[0], 'javascript'); $var{channel_image_url} = WebGUI::HTML::filter($image[0], 'javascript');
$var{channel_image_title} = WebGUI::HTML::filter($image[1], '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'); $var{channel_image_height} = WebGUI::HTML::filter($image[5], 'javascript');
foreach my $object (@items) { foreach my $object (@items) {
my %item; my %item;
$item{title} = WebGUI::HTML::filter($object->title, 'javascript'); $item{title} = WebGUI::HTML::filter(scalar $object->title, 'javascript');
$item{date} = WebGUI::HTML::filter($object->get_pubDate_epoch, 'javascript'); $item{date} = WebGUI::HTML::filter(scalar $object->get_pubDate_epoch, 'javascript');
$item{category} = WebGUI::HTML::filter($object->category, 'javascript'); $item{category} = WebGUI::HTML::filter(scalar $object->category, 'javascript');
$item{author} = WebGUI::HTML::filter($object->author, 'javascript'); $item{author} = WebGUI::HTML::filter(scalar $object->author, 'javascript');
$item{guid} = WebGUI::HTML::filter($object->guid, 'javascript'); $item{guid} = WebGUI::HTML::filter(scalar $object->guid, 'javascript');
$item{link} = WebGUI::HTML::filter($object->link, 'javascript'); $item{link} = WebGUI::HTML::filter(scalar $object->link, 'javascript');
$item{description} = WebGUI::HTML::filter(scalar($object->description), 'javascript'); $item{description} = WebGUI::HTML::filter(scalar($object->description), 'javascript');
$item{descriptionFirst100words} = $item{description}; $item{descriptionFirst100words} = $item{description};
$item{descriptionFirst100words} =~ s/(((\S+)\s+){100}).*/$1/s; $item{descriptionFirst100words} =~ s/(((\S+)\s+){100}).*/$1/s;

View file

@ -141,7 +141,7 @@ particular asset.
=head3 params =head3 params
A hashref with the quiet, userId, depth, and indexFileName parameters from A hashref with the quiet, userId, depth, and indexFileName parameters from
L<exportAsHtml>. L<WebGUI::Asset/exportAsHtml>.
=cut =cut
@ -151,6 +151,9 @@ sub exportAssetCollateral {
my $self = shift; my $self = shift;
my $basepath = shift; my $basepath = shift;
my $args = shift; my $args = shift;
my $reportSession = shift;
my $reporti18n = WebGUI::International->new($self->session, 'Asset');
my $basename = $basepath->basename; my $basename = $basepath->basename;
my $filedir; my $filedir;
@ -172,58 +175,59 @@ sub exportAssetCollateral {
$filenameBase = $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 )) { foreach my $ext (qw( rss atom )) {
my $dest = Path::Class::File->new($filedir, $filenameBase . '.' . $ext); my $dest = Path::Class::File->new($filedir, $filenameBase . '.' . $ext);
# tell the user which asset we're exporting. # tell the user which asset we're exporting.
unless ($args->{quiet}) { if ( $reportSession && !$args->{quiet} ) {
my $message = sprintf $self->{ '_masteri18n' }->get('exporting page'), $dest->absolute->stringify; my $message = sprintf $reporti18n->get('exporting page'), $dest->absolute->stringify;
$self->{ '_masterSession' }->output->print('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$message); $reportSession->output->print(
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $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... # open another session as the user doing the exporting...
my $tempSession = WebGUI::Session->open($self->session->config->getWebguiRoot,$self->session->config->getFilename); my $selfdupe = WebGUI::Asset->newByDynamicClass( $exportSession, $self->getId );
$tempSession->user( { userId => $self->session->user->userId } );
my $selfdupe = WebGUI::Asset->newByDynamicClass( $tempSession, $self->getId );
# next, get the contents, open the file, and write the contents to the file. # next, get the contents, open the file, and write the contents to the file.
my $fh = eval { $dest->open('>:utf8') }; my $fh = eval { $dest->open('>:utf8') };
if($@) { if($@) {
WebGUI::Error->throw(error => "can't open " . $dest->absolute->stringify . " for writing: $!"); WebGUI::Error->throw(error => "can't open " . $dest->absolute->stringify . " for writing: $!");
$exportSession->close;
} }
my $previousHandle = $selfdupe->session->{_handle}; $exportSession->asset($selfdupe);
my $previousDefaultAsset = $selfdupe->session->asset; $exportSession->output->setHandle($fh);
$selfdupe->session->asset($selfdupe);
$selfdupe->session->output->setHandle($fh);
my $contents; my $contents;
if ($ext eq 'rss') { if ($ext eq 'rss') {
$contents = $selfdupe->www_viewRss; $contents = $selfdupe->www_viewRss;
} else { }
else {
$contents = $selfdupe->www_viewAtom; $contents = $selfdupe->www_viewAtom;
} # add more for more extensions. } # add more for more extensions.
# chunked content is already printed, no need to print it again # chunked content is already printed, no need to print it again
unless($contents eq 'chunked') { unless($contents eq 'chunked') {
$tempSession->output->print($contents); $exportSession->output->print($contents);
} }
$tempSession->output->setHandle($previousHandle); $exportSession->close;
# properly close the temp session
$tempSession->var->end;
$tempSession->close;
# tell the user we did this asset collateral correctly # tell the user we did this asset collateral correctly
unless( $args->{quiet} ) { if ( $reportSession && !$args->{quiet} ) {
$self->{ '_masterSession' }->output->print($self->{ '_masteri18n' }->get('done')); $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 () =head2 getAtomFeedUrl ()
Returns $self->getUrl(func=viewAtom). Returns $self->getUrl('func=viewAtom').
=cut =cut
@ -259,7 +263,7 @@ sub getAtomFeedUrl {
=head2 getRssFeedUrl () =head2 getRssFeedUrl ()
Returns $self->getUrl(func=viewRss). Returns $self->getUrl('func=viewRss').
=cut =cut

View file

@ -331,14 +331,9 @@ sub exportAsHtml {
return ($returnCode, $message); 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 # next, tell the asset that we're exporting, so that it can export any
# of its collateral or other extra data. # of its collateral or other extra data.
eval { $asset->exportAssetCollateral($asset->exportGetUrlAsPath, $args) }; eval { $asset->exportAssetCollateral($asset->exportGetUrlAsPath, $args, $session) };
if($@) { if($@) {
$returnCode = 0; $returnCode = 0;
$message = $@; $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 Plug in point for complicated assets (like the CS, the Calendar) to manage
exporting their collateral data like other views, children threads and posts, 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 A hashref with the quiet, userId, depth, and indexFileName parameters from
L</exportAsHtml>. L</exportAsHtml>.
=head3 session
The session doing the full export. Can be used to report status messages.
=cut =cut
sub exportAssetCollateral { sub exportAssetCollateral {

View file

@ -89,7 +89,9 @@ $post = $collab->addChild($props,
}); });
my $rssitems = $collab->getRssFeedItems(); 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: { TODO: {
local $TODO = "Tests to make later"; local $TODO = "Tests to make later";