fixed: Syndicated Content doesn't always decode text properly

fixed: Syndicated Content caches improperly
This commit is contained in:
Graham Knop 2008-07-08 16:55:23 +00:00
parent 67c0338e47
commit 823c0af44f
2 changed files with 25 additions and 38 deletions

View file

@ -2,6 +2,8 @@
- Created a migration from 7.4.40 directly to 7.5.16. - Created a migration from 7.4.40 directly to 7.5.16.
- fixed: More permissive DSN checking to allow use of SQLite (thanks pathma) - fixed: More permissive DSN checking to allow use of SQLite (thanks pathma)
- fixed: Project manager modal dialog doesn't work in some instances. - fixed: Project manager modal dialog doesn't work in some instances.
- fixed: Syndicated Content doesn't always decode text properly
- fixed: Syndicated Content caches improperly
7.5.15 7.5.15
- fixed: Colorpicker window would not open (Martin Kamerbeek / Oqapi) - fixed: Colorpicker window would not open (Martin Kamerbeek / Oqapi)

View file

@ -10,13 +10,10 @@ package WebGUI::Asset::Wobject::SyndicatedContent;
# http://www.plainblack.com info@plainblack.com # http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------- #-------------------------------------------------------------------
use HTML::Entities;
use strict; use strict;
use Storable; use HTML::Entities;
use Tie::CPHash;
use Tie::IxHash; use Tie::IxHash;
use WebGUI::Cache; use WebGUI::Cache;
use WebGUI::HTMLForm;
use WebGUI::HTML; use WebGUI::HTML;
use WebGUI::International; use WebGUI::International;
use WebGUI::Asset::Wobject; use WebGUI::Asset::Wobject;
@ -24,9 +21,7 @@ use WebGUI::Macro;
use XML::RSSLite; use XML::RSSLite;
use XML::RSS::Creator; use XML::RSS::Creator;
use LWP::UserAgent; use LWP::UserAgent;
use POSIX qw/floor/; use Encode;
my $hasEncode=1;
eval ' use Encode qw(from_to); '; $hasEncode=0 if $@;
our @ISA = qw(WebGUI::Asset::Wobject); our @ISA = qw(WebGUI::Asset::Wobject);
@ -331,14 +326,14 @@ sub _normalize_items {
sub _get_rss_data { sub _get_rss_data {
my $session = shift; my $session = shift;
my $url = shift; my $url = shift;
my $cache = WebGUI::Cache->new($session,'url:' . $url, 'RSS'); # format of cache was changed, differentiate
my $rss_serial = $cache->get; my $cache = WebGUI::Cache->new($session,'url2:' . $url, 'RSS');
my $rss = {}; my $rss = $cache->get;
if ($rss_serial) { if ($rss) {
$rss = Storable::thaw($rss_serial); if ($rss->{error}) {
} return undef;
if ($rss->{error}) { }
return undef; return $rss;
} }
else { else {
my $ua = LWP::UserAgent->new(timeout => 5); my $ua = LWP::UserAgent->new(timeout => 5);
@ -347,10 +342,10 @@ sub _get_rss_data {
if (!$response->is_success()) { if (!$response->is_success()) {
$session->errorHandler->warn("Error retrieving url '$url': " . $session->errorHandler->warn("Error retrieving url '$url': " .
$response->status_line()); $response->status_line());
$cache->set(Storable::nfreeze({'error' => 1, 'error_status' => $response->status_line}), 3600); $cache->set({'error' => 1, 'error_status' => $response->status_line}, 3600);
return undef; return undef;
} }
my $xml = $response->content(); my $xml = $response->decoded_content;
# Approximate with current time if we don't have a Last-Modified # Approximate with current time if we don't have a Last-Modified
# header coming from the RSS source. # header coming from the RSS source.
@ -360,17 +355,10 @@ sub _get_rss_data {
# XML::RSSLite does not handle <![CDATA[ ]]> so: # XML::RSSLite does not handle <![CDATA[ ]]> so:
$xml =~ s/<!\[CDATA\[(.*?)\]\]>/$1/sg; $xml =~ s/<!\[CDATA\[(.*?)\]\]>/$1/sg;
# Convert encoding if needed / Perl 5.8.0 or up required. # Convert encoding if needed
if ($] >= 5.008 && $hasEncode) { $xml =~ /<\?xml.*?encoding=['"](\S+)['"]/i;
$xml =~ /<\?xml.*?encoding=['"](\S+)['"]/i; my $xmlEncoding = $1 || 'utf8';
my $xmlEncoding = $1 || 'utf8'; $xml = Encode::decode($xmlEncoding, $xml);
my $encoding = 'utf8';
if (lc($xmlEncoding) ne lc($encoding)) {
eval { from_to($xml, $xmlEncoding, $encoding) };
$session->errorHandler->warn($@) if ($@);
}
}
my $rss_lite = {}; my $rss_lite = {};
eval { eval {
@ -390,6 +378,7 @@ sub _get_rss_data {
# structure. # structure.
$rss_lite = {channel => $rss_lite}; $rss_lite = {channel => $rss_lite};
$rss = {};
if (!($rss->{channel} = if (!($rss->{channel} =
_find_record($rss_lite, qr/^channel$/))) { _find_record($rss_lite, qr/^channel$/))) {
$session->errorHandler->warn("unable to find channel info for url $url"); $session->errorHandler->warn("unable to find channel info for url $url");
@ -412,7 +401,7 @@ sub _get_rss_data {
$rss->{last_modified} = $last_modified; $rss->{last_modified} = $last_modified;
#Default to an hour timeout #Default to an hour timeout
$cache->set(Storable::nfreeze($rss), 3600); $cache->set($rss, 3600);
} }
return $rss; return $rss;
@ -548,14 +537,10 @@ sub _get_items {
my $hasTermsRegex=_make_regex($self->getValue('hasTerms')); my $hasTermsRegex=_make_regex($self->getValue('hasTerms'));
# Cache format changes: # Format of cache has changed several times
# - aggregate: $items my $key=join(':', 'aggregate3', $displayMode,$hasTermsRegex,$maxHeadlines,$self->getRssUrl);
# - aggregate2 (2006-08-26): [$items, \@rss_feeds] my $cache = WebGUI::Cache->new($self->session,$key, 'RSS');
my $cached = $cache->get;
my $key=join(':',('aggregate2', $displayMode,$hasTermsRegex,$maxHeadlines,$self->getRssUrl));
my $cache = WebGUI::Cache->new($self->session,$key, 'RSS');
my $cached = Storable::thaw($cache->get());
my ($items, @rss_feeds); my ($items, @rss_feeds);
if ($cached) { if ($cached) {
@ -584,7 +569,7 @@ sub _get_items {
#@{$items} = sort { $b->{date} <=> $a->{date} } @{$items}; #@{$items} = sort { $b->{date} <=> $a->{date} } @{$items};
$cache->set(Storable::freeze([$items, \@rss_feeds]), 3600); $cache->set([$items, \@rss_feeds], 3600);
} }
#So return the item loop and the first RSS feed, because #So return the item loop and the first RSS feed, because