diff --git a/docs/gotcha.txt b/docs/gotcha.txt index eb49bed9c..34b78d75a 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -64,6 +64,10 @@ save you many hours of grief. file. The international messages are now automatically cached if caching is available. + * After upgrading please remove the SyndicatedContent.pm file from + sbin/Hourly as it is no longer required, and will cause + problems if it is not removed. + 5.1.0 -------------------------------------------------------------------- diff --git a/docs/upgrades/upgrade_5.1.2-5.2.0.sql b/docs/upgrades/upgrade_5.1.2-5.2.0.sql index c228e369f..b3420c513 100644 --- a/docs/upgrades/upgrade_5.1.2-5.2.0.sql +++ b/docs/upgrades/upgrade_5.1.2-5.2.0.sql @@ -3103,8 +3103,12 @@ delete from international where languageId=1 and namespace='WebGUI' and internat insert into international (internationalId,languageId,namespace,message,lastUpdated) values (896,1,'WebGUI','Page Cache Timeout (Visitors)', 1047342926); delete from international where languageId=1 and namespace='WebGUI' and internationalId=895; insert into international (internationalId,languageId,namespace,message,lastUpdated) values (895,1,'WebGUI','Page Cache Timeout', 1047342910); - - +delete from international where namespace='SyndicatedContent' and internationalId=5; +delete from international where namespace='SyndicatedContent' and internationalId=6; +alter table SyndicatedContent drop column content; +alter table SyndicatedContent drop column lastFetched; +alter table SyndicatedContent add column templateId int not null default 1; +INSERT INTO template VALUES (1,'Default Syndicated Content','\r\n

\r\n
\r\n\r\n\r\n

\r\n\r\n\r\n

\r\n\r\n \" target=\"_blank\"> \r\n\r\n \r\n\r\n

\r\n\r\n\r\n

\r\n\r\n\r\n\r\n\r\n

  • \r\n \r\n \" target=\"_blank\"> \r\n \r\n \r\n \r\n \r\n - \r\n \r\n
    \r\n\r\n','SyndicatedContent'); diff --git a/lib/WebGUI/Wobject/SyndicatedContent.pm b/lib/WebGUI/Wobject/SyndicatedContent.pm index d09ea525e..dc854e1cf 100644 --- a/lib/WebGUI/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Wobject/SyndicatedContent.pm @@ -12,6 +12,7 @@ package WebGUI::Wobject::SyndicatedContent; use strict; use Tie::CPHash; +use WebGUI::Cache; use WebGUI::DateTime; use WebGUI::HTMLForm; use WebGUI::Icon; @@ -20,6 +21,7 @@ use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Wobject; +use XML::RSSLite; our @ISA = qw(WebGUI::Wobject); @@ -37,12 +39,9 @@ sub new { -properties=>$property, -extendedProperties=>{ rssUrl=>{}, - content=>{ - defaultValue=>'Not yet fetched!' - }, - lastFetched=>{ - defaultValue=>time() - } + templateId=>{ + defaultValue=>1 + } } ); bless $self, $class; @@ -56,27 +55,22 @@ sub uiLevel { #------------------------------------------------------------------- sub www_edit { - my $f = WebGUI::HTMLForm->new; - $f->url( + my $properties = WebGUI::HTMLForm->new; + my $layout = WebGUI::HTMLForm->new; + $properties->url( -name=>"rssUrl", -label=>WebGUI::International::get(1,$_[0]->get("namespace")), -value=>$_[0]->getValue("rssUrl") ); - if ($_[0]->get("wobjectId") ne "new") { - $f->readOnly( - -value=>WebGUI::DateTime::epochToHuman($_[0]->getValue("lastFetched"),"%z %Z"), - -label=>WebGUI::International::get(5,$_[0]->get("namespace")) - ); - $f->readOnly( - -value=>$_[0]->getValue("content"), - -label=>WebGUI::International::get(6,$_[0]->get("namespace")) - ); - } else { - $f->hidden("content",$_[0]->getValue("content")); - $f->hidden("lastFetched",$_[0]->getValue("lastFetched")); - } + $layout->template( + -name=>"templateId", + -value=>$_[0]->getValue("templateId"), + -namespace=>$_[0]->get("namespace"), + -afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId") + ); return $_[0]->SUPER::www_edit( - -properties=>$f->printRowsOnly, + -properties=>$properties->printRowsOnly, + -layout=>$layout->printRowsOnly, -headingId=>4, -helpId=>1 ); @@ -85,11 +79,30 @@ sub www_edit { #------------------------------------------------------------------- sub www_view { - my ($output); - $output = $_[0]->displayTitle; - $output .= $_[0]->description; - $output .= $_[0]->get("content"); - return $output; + my %rss; + my $cache = WebGUI::Cache->new($_[0]->get("rssUrl"),"URL"); + my $rssFile = $cache->get; + unless (defined $rssFile) { + $rssFile = $cache->setByHTTP($_[0]->get("rssUrl"),3600); + } + eval{parseXML(\%rss, \$rssFile)}; + if ($@) { + WebGUI::ErrorHandler::warn($_[0]->get("rssUrl")." ".$@); + } + my %var; + $var{"channel.title"} = $rss{title}; + $var{"channel.link"} = $rss{link}; + $var{"channel.description"} = $rss{description}; + my @items; + foreach my $item (@{$rss{items}}) { + push (@items,{ + link=>$item->{link}, + title=>$item->{title}, + description=>$item->{description} + }); + } + $var{item_loop} = \@items; + return $_[0]->processTemplate($_[0]->get("templateId"),\%var); } diff --git a/sbin/Hourly/SyndicatedContent.pm b/sbin/Hourly/SyndicatedContent.pm deleted file mode 100644 index 80f44f87c..000000000 --- a/sbin/Hourly/SyndicatedContent.pm +++ /dev/null @@ -1,73 +0,0 @@ -package Hourly::SyndicatedContent; - -#------------------------------------------------------------------- -# WebGUI is Copyright 2001-2002 Plain Black LLC. -#------------------------------------------------------------------- -# Please read the legal notices (docs/legal.txt) and the license -# (docs/license.txt) that came with this distribution before using -# this software. -#------------------------------------------------------------------- -# http://www.plainblack.com info@plainblack.com -#------------------------------------------------------------------- - -use HTTP::Request; -use LWP::UserAgent; -use strict; -use WebGUI::Session; -use WebGUI::SQL; -use XML::RSSLite; - -#------------------------------------------------------------------- -sub getRSS { - my ($userAgent, $request, $response, $content, %result); - $userAgent = new LWP::UserAgent; - $request = new HTTP::Request (GET => $_[0]); - $response = $userAgent->request($request); - $content = $response->content; - eval{parseXML(\%result, \$content)} or print $@; - return %result; -} - -#------------------------------------------------------------------- -sub generateHTML { - my (%rss, $html, $item); - %rss = @_; - $html = $rss{title}; - $html = ''.$html.'' if ($rss{link}); - $html = '

    '.$html.'

    '; - $html .= $rss{description}.'

    ' if ($rss{description}); - foreach $item (@{$rss{items}}) { - $html .= '

  • '; - if ($item->{link}) { - $html .= ''.$item->{title}.''; - } else { - $html .= $item->{title}; - } - $html .= ' - '.$item->{description} if ($item->{description}); - $html .= '
    '; - } - return ($html); -} - -#------------------------------------------------------------------- -sub process { - my ($sth, @data, %rss, $html); - $sth = WebGUI::SQL->read("select wobject.wobjectId, SyndicatedContent.rssURL, SyndicatedContent.content - from wobject,SyndicatedContent where wobject.wobjectId=SyndicatedContent.wobjectId and wobject.pageId<>3"); - while (@data = $sth->array) { - %rss = getRSS($data[1]); - $html = generateHTML(%rss); - if ($html ne "") { - WebGUI::SQL->write("update SyndicatedContent set content=".quote($html).", lastFetched=".time()." where wobjectId=$data[0]"); - } elsif (substr($data[2],6) ne "Unable" && substr($data[2],7) ne "Not yet") { - # then just leave the existing content in place - } else { - WebGUI::SQL->write("update SyndicatedContent set content='Unable to fetch content. Perhaps the RSS is improperly formated.', - lastFetched=".time()." where wobjectId=$data[0]"); - } - } - $sth->finish; -} - -1; -