Updates to SyndicatedContent to allow for content republishing and MIME-types to Snippets.
This commit is contained in:
parent
6a49e2036b
commit
5917f21991
5 changed files with 153 additions and 7 deletions
|
|
@ -18,6 +18,7 @@ use strict;
|
|||
use WebGUI::Asset;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::HTTP;
|
||||
use WebGUI::Session;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset);
|
||||
|
|
@ -29,7 +30,7 @@ Package WebGUI::Asset::Snippet
|
|||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides a mechanism to publish arbitrary code snippets to WebGUI for reuse in other pages. Can be used for things like HTML segments, javascript, and cascading style sheets.
|
||||
Provides a mechanism to publish arbitrary code snippets to WebGUI for reuse in other pages. Can be used for things like HTML segments, javascript, and cascading style sheets. You can also specify the MIME type of the snippet, allowing you to serve XML, CSS and other text files directly from the WebGUI asset system and have browsers recognize them correctly.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
|
|
@ -70,7 +71,12 @@ sub definition {
|
|||
processAsTemplate=>{
|
||||
fieldType=>'yesNo',
|
||||
defaultValue=>0
|
||||
},
|
||||
mimeType=>{
|
||||
fieldType=>'text',
|
||||
defaultValue=>'text/html'
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
|
|
@ -89,6 +95,10 @@ Returns the TabForm object that will be used in generating the edit page for thi
|
|||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm();
|
||||
my %mimeTypes;
|
||||
foreach ('text/html','text/css','text/javascript','text/plain','text/xml','application/xml') {
|
||||
$mimeTypes{$_}=$_;
|
||||
}
|
||||
$tabform->getTab("properties")->codearea(
|
||||
-name=>"snippet",
|
||||
-label=>WebGUI::International::get('snippet', 'Asset_Snippet'),
|
||||
|
|
@ -99,6 +109,13 @@ sub getEditForm {
|
|||
-label=>WebGUI::International::get('process as template', 'Asset_Snippet'),
|
||||
-value=>$self->getValue("processAsTemplate")
|
||||
);
|
||||
$tabform->getTab("properties")->combo(
|
||||
-name=>"mimeType",
|
||||
-label=>WebGUI::International::get('mimeType', 'Asset_Snippet'),
|
||||
-value=>[$self->getValue('mimeType')],
|
||||
-options=>\%mimeTypes
|
||||
);
|
||||
|
||||
return $tabform;
|
||||
}
|
||||
|
||||
|
|
@ -180,6 +197,8 @@ A web accessible version of the view method.
|
|||
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
my $mimeType=$self->getValue('mimeType');
|
||||
WebGUI::HTTP::setMimeType($mimeType || 'text/html');
|
||||
return $self->view(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,11 @@ use WebGUI::Privilege;
|
|||
use WebGUI::Session;
|
||||
use WebGUI::Asset::Wobject;
|
||||
use XML::RSSLite;
|
||||
use XML::RSS::Creator;
|
||||
use LWP::UserAgent;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::HTTP;
|
||||
use POSIX qw/floor/;
|
||||
my $hasEncode=1;
|
||||
eval " use Encode qw(from_to); "; $hasEncode=0 if $@;
|
||||
|
|
@ -523,14 +526,18 @@ Returns the rendered output of the wobject.
|
|||
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my $rssFlavor = shift;
|
||||
$self->logView() if ($session{setting}{passiveProfilingEnabled});
|
||||
|
||||
my $maxHeadlines = $self->get("maxHeadlines") || 1000000;
|
||||
my @urls = split(/\s+/,$self->get("rssUrl"));
|
||||
|
||||
#We came into this subroutine as
|
||||
my $rssObject=($rssFlavor) ? XML::RSS::Creator->new(version=>$rssFlavor) : undef;
|
||||
|
||||
my %var;
|
||||
|
||||
my($item_loop,$rss_feeds)=$self->_get_items(\@urls, $maxHeadlines);
|
||||
my($item_loop,$rss_feeds)=$self->_get_items(\@urls, $maxHeadlines,$rssObject);
|
||||
if(@$rss_feeds > 1){
|
||||
#If there is more than one (valid) feed in this wobject, put in the wobject description info.
|
||||
$var{'channel.title'} = $self->get("title");
|
||||
|
|
@ -541,11 +548,56 @@ sub view {
|
|||
$var{"channel.link"} = $rss_feeds->[0]->{channel}->{link};
|
||||
$var{"channel.description"} = $rss_feeds->[0]->{channel}->{description};
|
||||
}
|
||||
$self->_createRSSURLs(\%var);
|
||||
$var{item_loop} = $item_loop;
|
||||
|
||||
if ($rssObject) {
|
||||
$self->_constructRSS($rssObject,\%var);
|
||||
my $rss=$rssObject->as_string;
|
||||
WebGUI::HTTP::setMimeType('text/xml');
|
||||
|
||||
#Looks like a kludge, but what this does is put in the proper
|
||||
#XSLT stylesheet so the RSS doesn't look like total ass.
|
||||
my $siteURL=WebGUI::URL::getSiteURL().WebGUI::URL::gateway();
|
||||
$rss=~s|<\?xml version="1\.0" encoding="UTF\-8"\?>|<\?xml version="1\.0" encoding="UTF\-8"\?>\n<?xml\-stylesheet type="text/xsl" href="${siteURL}xslt/rss$rssFlavor.xsl"\?>\n|;
|
||||
return $rss;
|
||||
|
||||
} else {
|
||||
return $self->processTemplate(\%var,$self->get("templateId"));
|
||||
}
|
||||
|
||||
return $self->processTemplate(\%var,$self->get("templateId"));
|
||||
}
|
||||
|
||||
sub _constructRSS{
|
||||
my($self,$rssObject,$var)=@_;
|
||||
#They've chosen to emit this as an RSS feed, in one of the four flavors we support.
|
||||
$rssObject->channel(
|
||||
title=>$var->{'channel.title'} || $self->get('title'),
|
||||
link=>WebGUI::URL::page('',1),
|
||||
description=>$var->{'channel.description'} || ''
|
||||
);
|
||||
foreach my $item (@{$var->{item_loop}}) {
|
||||
# I know this seems kludgy, but because XML::RSSLite parses
|
||||
# feeds loosely, sometimes it returns a data structure when it shouldn't.
|
||||
# So we're only pushing in attributes when they AREN'T a reference to
|
||||
# a data structure.
|
||||
my %attributes;
|
||||
foreach my $attribute(keys %$item){
|
||||
$attributes{$attribute}=$item->{$attribute} if (! ref($item->{$attribute}));
|
||||
}
|
||||
$rssObject->add_item(%attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub _createRSSURLs{
|
||||
my $self=shift;
|
||||
my $var=shift;
|
||||
foreach({ver=>'1.0',param=>'10'},{ver=>'0.9',param=>'090'},{ver=>'0.91',param=>'091'},{ver=>'2.0',param=>'20'}){
|
||||
$var->{'rss.url.'.$_->{ver}}=$self->getUrl('func=viewRSS'.$_->{param});
|
||||
}
|
||||
$var->{'rss.url'}=$self->getUrl('func=viewRSS20');
|
||||
}
|
||||
|
||||
=head2 www_edit()
|
||||
|
||||
|
|
@ -560,6 +612,51 @@ sub www_edit {
|
|||
return $self->getAdminConsole->render($self->getEditForm->print,WebGUI::International::get("4","Asset_SyndicatedContent"));
|
||||
}
|
||||
|
||||
=head2 www_viewRSS090()
|
||||
|
||||
Emit an RSS 0.9 feed.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_viewRSS090{
|
||||
my $self=shift;
|
||||
return $self->view('0.9');
|
||||
}
|
||||
|
||||
=head2 www_viewRSS091()
|
||||
|
||||
Emit an RSS 0.91 feed.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_viewRSS091{
|
||||
my $self=shift;
|
||||
return $self->view('0.91');
|
||||
}
|
||||
|
||||
=head2 www_viewRSS10()
|
||||
|
||||
Emit an RSS 1.0 feed.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_viewRSS10{
|
||||
my $self=shift;
|
||||
return $self->view('1.0');
|
||||
}
|
||||
|
||||
|
||||
=head2 www_viewRSS20()
|
||||
|
||||
Emit an RSS 2.0 feed.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_viewRSS20{
|
||||
my $self=shift;
|
||||
return $self->view('2.0');
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue