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

Revision 680 (checked in by miyagawa, 14 years ago)
  • Now subscription and update share $feed object, which is experimental.
  • Planet uses $context->subcription to get members rather than from feeds. Fixes #198
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     );
40
41     $self->_write_index(
42         $context,
43         $self->templatize($context, $feed),
44         $self->conf->{dir} . '/index.html',
45     );
46    
47     $self->_apply_skin(
48         $context,
49         $self->conf->{skin},
50         $self->conf->{dir},
51     );
52 }
53
54
55 sub templatize {
56     my($self, $context, $feed) = @_;
57     my $tt   = $context->template();
58     my $skin = $self->conf->{skin} || 'default';
59
60     $tt->process("$skin/template/index.tt", {
61         %{ $self->conf->{template} },
62         feed  => $feed,
63         members => [ $context->subscription->feeds ],
64     }, \my $out) or $context->error($tt->error);
65     $out;
66 }
67
68 sub _sanitize_entries {
69     my ($self, $context, $feed, $tidy, $scrubber) = @_;
70    
71     foreach my $entry ($feed->entries) {
72 #        $entry->{body} = $tidy->clean($entry->{body});
73         $entry->{body} = $scrubber->scrub($entry->{body});
74     }
75 }
76
77 sub _write_index {
78     my ($self, $context, $index, $file) = @_;
79
80     open my $out, ">:utf8", $file or $context->error("$file: $!");
81     print $out $index;
82     close $out;
83 }
84
85 sub _apply_skin {
86     my ($self, $context, $skin_name, $output_dir) = @_;
87    
88     $context->log(debug => "Assets Directory: " . $self->assets_dir);
89    
90     rcopy(
91         File::Spec->catfile($self->assets_dir, $skin_name, 'static'),
92         $output_dir,
93     ) or $context->error("rcopy: $!");
94 }
95
96 1;
97
Note: See TracBrowser for help on using the browser.