root/trunk/plagger/lib/Plagger/Plugin/Subscription/XOXO.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::Subscription::XOXO;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use HTML::TreeBuilder;
6 use Plagger::Util;
7 use URI;
8
9 sub register {
10     my($self, $context) = @_;
11
12     $context->register_hook(
13         $self,
14         'subscription.load' => \&load,
15     );
16 }
17
18 sub load {
19     my($self, $context) = @_;
20     my $uri = URI->new($self->conf->{url})
21         or $context->error("config 'url' is missing");
22
23     $self->load_xoxo($context, $uri);
24 }
25
26 sub load_xoxo {
27     my($self, $context, $uri) = @_;
28
29     my $xhtml = Plagger::Util::load_uri($uri, $self);
30     my $tree = HTML::TreeBuilder->new;
31     $tree->parse($xhtml);
32     $tree->eof;
33
34     $self->find_xoxo($tree);
35 }
36
37 sub find_xoxo {
38     my($self, $tree) = @_;
39
40     for my $child ($tree->content_list) {
41         next unless ref $child;
42         if ($child->tag eq 'ul' || $child->tag eq 'ol') {
43             my $class = $child->attr('class') || '';
44             if ($class eq 'xoxo' || $class eq 'subscriptionlist') {
45                 $self->find_list($child);
46             }
47         } else {
48             $self->find_xoxo($child);
49         }
50     }
51 }
52
53 sub find_list {
54     my($self, $tree) = @_;
55
56     for my $child ($tree->content_list) {
57         next unless ref $child;
58         if ($child->tag eq 'a') {
59             my $href  = $child->attr('href') or next;
60             my $title = $child->attr('title') || $child->as_text;
61
62             my $feed = Plagger::Feed->new;
63             $feed->url($href);
64             $feed->title($title);
65
66             Plagger->context->subscription->add($feed);
67         } else {
68             $self->find_list($child);
69         }
70     }
71 }
72
73 1;
74
75 __END__
76
77 =head1 NAME
78
79 Plagger::Plugin::Subscription::XOXO - Subscription list with XOXO microformats
80
81 =head1 SYNOPSIS
82
83   - module: Subscription::XOXO
84     config:
85       url: http://example.com/mySubscriptions.xhtml
86
87 =head1 DESCRIPTION
88
89 This plugin creates Subscription by fetching remote XOXO file by HTTP
90 or locally (with C<file://> URI). The parser is implemented in really
91 a dumb way and only supports extracting URL (I<href>) and title from A
92 links inside XOXO C<ul> or C<ol> tags.
93
94 =head1 AUTHOR
95
96 Tatsuhiko Miyagawa
97
98 =head1 SEE ALSO
99
100 L<Plagger>, L<http://microformats.org/wiki/xoxo>
101
102 =cut
Note: See TracBrowser for help on using the browser.