syndicated content sorted by pubDate where possible
This commit is contained in:
parent
1a3165e6ee
commit
5aa7db7d58
1 changed files with 22 additions and 17 deletions
|
|
@ -334,7 +334,7 @@ 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');
|
my $cache = WebGUI::Cache->new($session,'url:' . $url, 'RSS');
|
||||||
my $rss_serial = $cache->get;
|
my $rss_serial = $cache->get;
|
||||||
my $rss = {};
|
my $rss = {};
|
||||||
if ($rss_serial) {
|
if ($rss_serial) {
|
||||||
|
|
@ -422,22 +422,28 @@ sub _get_rss_data {
|
||||||
# whole database to keep the thing from growing too large
|
# whole database to keep the thing from growing too large
|
||||||
|
|
||||||
sub _assign_rss_dates {
|
sub _assign_rss_dates {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my ($items) = @_;
|
my ($items) = @_;
|
||||||
|
|
||||||
for my $item (@{$items}) {
|
for my $item (@{$items}) {
|
||||||
my $key = 'dates:' . ($item->{guid} || $item->{title} ||
|
my $key = 'dates:' . ($item->{guid} || $item->{title} ||
|
||||||
$item->{description} || $item->{link});
|
$item->{description} || $item->{link});
|
||||||
my $cache = WebGUI::Cache->new($session,$key, 'RSS');
|
my $cache = WebGUI::Cache->new($session,$key, 'RSS');
|
||||||
if (my $date = $cache->get()) {
|
if (my $date = $cache->get()) {
|
||||||
$item->{date} = $date;
|
$item->{date} = $date;
|
||||||
} else {
|
|
||||||
$item->{date} =$session->datetime->time();
|
|
||||||
$cache->set($item->{date}, '1 year');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@{$items} = sort { $b->{date} <=> $a->{date} } @{$items};
|
else {
|
||||||
}
|
if (my $pubDate = $session->datetime->mailToEpoch($item->{pubDate})) {
|
||||||
|
$item->{date} = $pubDate;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$item->{date} = $session->datetime->time() - (60 * 60 * 24 * 365); # handicap the undated
|
||||||
|
}
|
||||||
|
$cache->set($item->{date}, '1 year');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@{$items} = sort { $b->{date} <=> $a->{date} } @{$items};
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
# $items is the hashref to put items into.
|
# $items is the hashref to put items into.
|
||||||
|
|
@ -489,6 +495,7 @@ sub _create_interleaved_items {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@$items = sort { $b->{date} <=> $a->{date} } @$items;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -559,14 +566,12 @@ sub _get_items {
|
||||||
@rss_feeds = @{$cached->[1]};
|
@rss_feeds = @{$cached->[1]};
|
||||||
} else {
|
} else {
|
||||||
$items = [];
|
$items = [];
|
||||||
|
|
||||||
for my $url (@{$urls}) {
|
for my $url (@{$urls}) {
|
||||||
my $rss_info=_get_rss_data($self->session,$url);
|
my $rss_info=_get_rss_data($self->session,$url);
|
||||||
push(@rss_feeds, $rss_info) if(defined $rss_info);
|
push(@rss_feeds, $rss_info) if(defined $rss_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
# deal with the fact that we may never get valid data
|
# deal with the fact that we may never get valid data
|
||||||
|
|
||||||
if (scalar(@rss_feeds) < 1) {
|
if (scalar(@rss_feeds) < 1) {
|
||||||
return ({}, []);
|
return ({}, []);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue