Skip to content

Commit

Permalink
Item14058: added support for non-unicode engines
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Apr 26, 2016
1 parent 9af5625 commit 873f427
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
4 changes: 2 additions & 2 deletions data/System/FeedPlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1461663841" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1461667167" format="1.1" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

Expand Down Expand Up @@ -104,7 +104,7 @@ In addition the =header=, =format=, =separator= and =footer= format strings may
---++ Change History

%TABLE{columnwidths="7em" tablewidth="100%"}%
| 24 Apr 2016 | fixed docu; fixed discover mode |
| 24 Apr 2016 | fixed docu; fixed discover mode; added support for non-unicode Foswiki engines |
| 18 Mar 2016 | be more robust on feeds not publishing proper dates |
| 16 Mar 2016 | initial release |

Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/FeedPlugin.pm
Expand Up @@ -20,7 +20,7 @@ use warnings;

use Foswiki::Func ();

our $VERSION = '1.03';
our $VERSION = '1.04';
our $RELEASE = '26 Apr 2016';
our $SHORTDESCRIPTION = 'Syndication feed parser';
our $NO_PREFS_IN_TOPIC = 1;
Expand Down
45 changes: 26 additions & 19 deletions lib/Foswiki/Plugins/FeedPlugin/Core.pm
Expand Up @@ -22,6 +22,7 @@ use Foswiki::Func ();
use Foswiki::Time ();
use XML::Feed();
use URI ();
use Encode ();
use Cache::FileCache ();
use Digest::MD5 ();
use Error qw(:try);
Expand Down Expand Up @@ -258,27 +259,27 @@ sub FEED {
next if $skip && $index <= $skip;
my $line = $format;

my $category = join(", ", $entry->category()) || '';
my $tags = join(", ", $entry->tags()) || '';
my $content = "<noautolink>".$entry->content->body()."</noautolink>";
my $summary = $entry->summary->body();
my $category = _encode(join(", ", $entry->category()) || '');
my $tags = _encode(join(", ", $entry->tags()) || '');
my $content = "<noautolink>"._encode($entry->content->body())."</noautolink>";
my $summary = _encode($entry->summary->body());
my $issued = $entry->issued;
$issued = $issued->epoch if defined $issued;
my $modified = $entry->modified;
$modified = $modified->epoch if defined $modified;

$line =~ s/\$author/$entry->author/g;
$line =~ s/\$base/$entry->base/ge;
$line =~ s/\$author/_encode($entry->author)/ge;
$line =~ s/\$base/_encode($entry->base)/ge;
$line =~ s/\$category/$category/g;
$line =~ s/\$content/$content/g;
$line =~ s/\$id/$entry->id/ge;
$line =~ s/\$id/_encode($entry->id)/ge;
$line =~ s/\$index/$index/g;
$line =~ s/\$issued(?:\((.*?)\))?/defined($issued)?Foswiki::Time::formatTime($issued, $1 || '$day $month $year'):""/ge;
$line =~ s/\$link/$entry->link/ge;
$line =~ s/\$link/_encode($entry->link)/ge;
$line =~ s/\$modified(?:\((.*?)\))?/defined($modified)?Foswiki::Time::formatTime($modified, $1 || '$day $month $year'):""/ge;
$line =~ s/\$summary/$summary/g;
$line =~ s/\$tags/$tags/g;
$line =~ s/\$title/$entry->title/ge;
$line =~ s/\$title/_encode($entry->title)/ge;

$line =~ s/%(\w)/%<nop>$1/g;
push @result, $line;
Expand All @@ -287,19 +288,25 @@ sub FEED {

my $result = $header.join($separator, @result).$footer;

$result =~ s/\$feed_author/$feed->author/ge;
$result =~ s/\$feed_base/$feed->base/ge;
$result =~ s/\$feed_copyright/$feed->copyright/ge;
$result =~ s/\$feed_format/$feed->format/ge;
$result =~ s/\$feed_generator/$feed->generator/ge;
$result =~ s/\$feed_language/$feed->language/ge;
$result =~ s/\$feed_link/$feed->link/ge;
$result =~ s/\$feed_modified/$feed->modified/ge;
$result =~ s/\$feed_author/_encode($feed->author)/ge;
$result =~ s/\$feed_base/_encode($feed->base)/ge;
$result =~ s/\$feed_copyright/_encode($feed->copyright)/ge;
$result =~ s/\$feed_format/_encode($feed->format)/ge;
$result =~ s/\$feed_generator/_encode($feed->generator)/ge;
$result =~ s/\$feed_language/_encode($feed->language)/ge;
$result =~ s/\$feed_link/_encode($feed->link)/ge;
$result =~ s/\$feed_modified/_encode($feed->modified)/ge;
$result =~ s/\$feed_modified(?:\((.*?)\))?/Foswiki::Time::formatTime($feed->modified->epoch, $1 || '$day $month $year')/ge;
$result =~ s/\$feed_tagline/$feed->tagline/ge;
$result =~ s/\$feed_title/$feed->title/ge;
$result =~ s/\$feed_tagline/_encode($feed->tagline)/ge;
$result =~ s/\$feed_title/_encode($feed->title)/ge;

return Foswiki::Func::decodeFormatTokens($result);
}

sub _encode {
my $string = shift;
$string = Encode::encode($Foswiki::cfg{Site}{CharSet}, $string) unless $Foswiki::UNICODE;
return $string;
}

1;

0 comments on commit 873f427

Please sign in to comment.