root/trunk/plagger/lib/Plagger/Plugin/Publish/Planet.pm

Revision 683 (checked in by miyagawa, 14 years ago)
  • Plagger::Util::decode_content now takes $content or $res
  • Try xml encoding header first, before HTML meta tag to guess charsets
  • Subscription::XOXO to handle multibyte title okay
  • Unhandled feed is removed from Subscription
  • use Plagger::UserAgent? in Util.pm
  • Planer: Unuse Scrubber for now
  • Aggregator::Xango to handle auto-discovered feed mapping as well
Line 
1 package Plagger::Plugin::Publish::Planet;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use File::Copy::Recursive qw[rcopy];
6 use File::Spec;
7 #use HTML::Tidy;
8 use HTML::Scrubber;
9
10 our $VERSION = '0.01';
11
12 sub register {
13     my($self, $context) = @_;
14     $context->register_hook(
15         $self,
16         'publish.feed' => \&add_feed,
17     );
18 }
19
20 sub add_feed {
21     my($self, $context, $args) = @_;
22     my $feed = $args->{feed};
23     if ($feed->id ne 'smartfeed:all') {
24         $context->error("Publish::Planet requires SmartFeed::All to run.");
25     }
26
27     $self->_sanitize_entries(
28         $context,
29         $feed,
30 #        HTML::Tidy->new,
31         undef,
32 #        HTML::Scrubber->new(
33 #            rules => [
34 #                style => 0,
35 #                script => 0,
36 #            ],
37 #            default => [ 1, { '*' => 1, style => 0 } ],
38 #        ),
39         undef,
40     );
41
42     $self->_write_index(
43         $context,
44         $self->templatize($context, $feed),
45         $self->conf->{dir} . '/index.html',
46     );
47    
48     $self->_apply_skin(
49         $context,
50         $self->conf->{skin},
51         $self->conf->{dir},
52     );
53 }
54
55
56 sub templatize {
57     my($self, $context, $feed) = @_;
58     my $tt   = $context->template();
59     my $skin = $self->conf->{skin} || 'default';
60
61     $tt->process("$skin/template/index.tt", {
62         %{ $self->conf->{template} },
63         feed  => $feed,
64         members => [ $context->subscription->feeds ],
65     }, \my $out) or $context->error($tt->error);
66     $out;
67 }
68
69 sub _sanitize_entries {
70     my ($self, $context, $feed, $tidy, $scrubber) = @_;
71    
72     foreach my $entry ($feed->entries) {
73 #        $entry->{body} = $tidy->clean($entry->{body});
74         $entry->{body} = $scrubber->scrub($entry->{body}) if $scrubber;
75     }
76 }
77
78 sub _write_index {
79     my ($self, $context, $index, $file) = @_;
80
81     open my $out, ">:utf8", $file or $context->error("$file: $!");
82     print $out $index;
83     close $out;
84 }
85
86 sub _apply_skin {
87     my ($self, $context, $skin_name, $output_dir) = @_;
88    
89     $context->log(debug => "Assets Directory: " . $self->assets_dir);
90    
91     rcopy(
92         File::Spec->catfile($self->assets_dir, $skin_name, 'static'),
93         $output_dir,
94     ) or $context->error("rcopy: $!");
95 }
96
97 1;
98
Note: See TracBrowser for help on using the browser.