X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/91513466877df4329567f2cc73b6719999394258..295a08394f1f962459d26db06624ff5d17bc3008:/IkiWiki/Plugin/aggregate.pm

diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index 5a9eb433d..59185e97f 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -8,7 +8,6 @@ use IkiWiki 3.00;
 use HTML::Parser;
 use HTML::Tagset;
 use HTML::Entities;
-use URI;
 use open qw{:utf8 :std};
 
 my %feeds;
@@ -210,6 +209,8 @@ sub needsbuild (@) {
 			markunseen($feed->{sourcepage});
 		}
 	}
+
+	return $needsbuild;
 }
 
 sub preprocess (@) {
@@ -298,7 +299,7 @@ sub loadstate () {
 	return if $state_loaded;
 	$state_loaded=1;
 	if (-e "$config{wikistatedir}/aggregate") {
-		open(IN, "$config{wikistatedir}/aggregate") ||
+		open(IN, "<", "$config{wikistatedir}/aggregate") ||
 			die "$config{wikistatedir}/aggregate: $!";
 		while (<IN>) {
 			$_=IkiWiki::possibly_foolish_untaint($_);
@@ -335,7 +336,7 @@ sub savestate () {
 	garbage_collect();
 	my $newfile="$config{wikistatedir}/aggregate.new";
 	my $cleanup = sub { unlink($newfile) };
-	open (OUT, ">$newfile") || error("open $newfile: $!", $cleanup);
+	open (OUT, ">", $newfile) || error("open $newfile: $!", $cleanup);
 	foreach my $data (values %feeds, values %guids) {
 		my @line;
 		foreach my $field (keys %$data) {
@@ -356,6 +357,20 @@ sub savestate () {
 	close OUT || error("save $newfile: $!", $cleanup);
 	rename($newfile, "$config{wikistatedir}/aggregate") ||
 		error("rename $newfile: $!", $cleanup);
+
+	my $timestamp=undef;
+	foreach my $feed (keys %feeds) {
+		my $t=$feeds{$feed}->{lastupdate}+$feeds{$feed}->{updateinterval};
+		if (! defined $timestamp || $timestamp > $t) {
+			$timestamp=$t;
+		}
+	}
+	$newfile=~s/\.new$/time/;
+	open (OUT, ">", $newfile) || error("open $newfile: $!", $cleanup);
+	if (defined $timestamp) {
+		print OUT $timestamp."\n";
+	}
+	close OUT || error("save $newfile: $!", $cleanup);
 }
 
 sub garbage_collect () {
@@ -628,7 +643,14 @@ sub add_page (@) {
 	$guid->{md5}=$digest;
 
 	# Create the page.
-	my $template=template($feed->{template}, blind_cache => 1);
+	my $template;
+	eval {
+		$template=template($feed->{template}, blind_cache => 1);
+	};
+	if ($@) {
+		print STDERR gettext("failed to process template:")." $@";
+		return;
+	}
 	$template->param(title => $params{title})
 		if defined $params{title} && length($params{title});
 	$template->param(content => wikiescape(htmlabs($params{content},
@@ -637,7 +659,7 @@ sub add_page (@) {
 	$template->param(url => $feed->{url});
 	$template->param(copyright => $params{copyright})
 		if defined $params{copyright} && length $params{copyright};
-	$template->param(permalink => urlabs($params{link}, $feed->{feedurl}))
+	$template->param(permalink => IkiWiki::urlabs($params{link}, $feed->{feedurl}))
 		if defined $params{link};
 	if (ref $feed->{tags}) {
 		$template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
@@ -665,13 +687,6 @@ sub wikiescape ($) {
 	return encode_entities(shift, '\[\]');
 }
 
-sub urlabs ($$) {
-	my $url=shift;
-	my $urlbase=shift;
-
-	URI->new_abs($url, $urlbase)->as_string;
-}
-
 sub htmlabs ($$) {
 	# Convert links in html from relative to absolute.
 	# Note that this is a heuristic, which is not specified by the rss
@@ -697,7 +712,7 @@ sub htmlabs ($$) {
 				next unless $v_offset; # 0 v_offset means no value
 				my $v = substr($text, $v_offset, $v_len);
 				$v =~ s/^([\'\"])(.*)\1$/$2/;
-				my $new_v=urlabs($v, $urlbase);
+				my $new_v=IkiWiki::urlabs($v, $urlbase);
 				$new_v =~ s/\"/&quot;/g; # since we quote with ""
 				substr($text, $v_offset, $v_len) = qq("$new_v");
 			}