X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=gavinc%2Frss20;h=8419ef151998d6c5e842db826edbe46821b1668c;hb=caaf09e3ed3f4f9ddba8b709d47f90c2578db8a5;hp=9ce4d0d8c9d27cb714e99b47fc20da7f111fa005;hpb=318ee8989d5ec0becee0a5bc6f1d5c8f04a9b2a1;p=matthijs%2Fupstream%2Fblosxom-plugins.git diff --git a/gavinc/rss20 b/gavinc/rss20 index 9ce4d0d..8419ef1 100644 --- a/gavinc/rss20 +++ b/gavinc/rss20 @@ -1,6 +1,6 @@ # Blosxom Plugin: rss20 # Author(s): Gavin Carr -# Version: 0.001001 +# Version: 0.001002 # Requires: storydate, lastmodified2 # Suggests: absolute # Follows: storydate, lastmodified2 @@ -50,38 +50,82 @@ $generator_url = "http://blosxom.sourceforge.net/?v=$blosxom::version"; $error_email ||= $author_email; +# Escape <, >, and & to hex-encoded entities for max compatibility in text elements +# See http://www.rssboard.org/rss-profile#data-types-characterdata +my %escape_text = ( + '<' => '<', + '>' => '>', + '&' => '&', +); +my $escape_text_re = join '|' => keys %escape_text; + +# Escape <, >, and & to standard html-encoded entities for in html elements +my %escape_html = ( + '<' => '<', + '>' => '>', + '&' => '&', +); +my $escape_html_re = join '|' => keys %escape_html; + sub start { _load_templates(); +} - 1; +sub story { + my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; + + # Ignore flavours other than ours + return unless $blosxom::flavour eq $flavour; + + # Don't double-encode if someone else has already done it + return unless $blosxom::encode_xml_entities; + + # Encode and reset encode_xml_entities flag + $$title_ref = _escape_text( $$title_ref ); + $$body_ref = _escape_html( $$body_ref ); + $blosxom::encode_xml_entities = 0; } # --- Private subroutines +sub _escape_text { + my ($text) = @_; + $text =~ s/($escape_text_re)/$escape_text{$1}/g; + return $text; +} + +sub _escape_html { + my ($html) = @_; + $html =~ s/($escape_html_re)/$escape_html{$1}/g; + return $html; +} + sub _load_templates { - $blosxom::template{$flavour}{'content_type'} = 'text/xml'; + $blosxom::template{$flavour}{'content_type'} = 'text/xml; charset=$blog_encoding'; $blosxom::template{$flavour}{'date'} = "\n"; - $blosxom::template{$flavour}{'head'} = <<'HEAD'; - + $blosxom::template{$flavour}{'head'} = < - $blog_title - $url - $blog_description - $lastmodified2::latest_iso8601 + $blosxom::blog_title + $blosxom::url + $blosxom::blog_description + \$lastmodified2::latest_iso8601 $blosxom::blog_language mailto:$rss20::author_email $rss20::copyright + hourly 1 2000-01-01T12:00+00:00 @@ -103,6 +147,8 @@ STORY FOOT + + 1; }