line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Orze::Drivers::RSS; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1057
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1029
|
use Encode; |
|
1
|
|
|
|
|
27117
|
|
|
1
|
|
|
|
|
125
|
|
7
|
1
|
|
|
1
|
|
489
|
use XML::RSS; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use XML::Twig; |
9
|
|
|
|
|
|
|
use DateTime; |
10
|
|
|
|
|
|
|
use HTML::Entities; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use base "Orze::Drivers"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Orze::Drivers::RSS - Create a RSS feed |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Create a RSS feed by parsing a piece of html code. Each title will |
21
|
|
|
|
|
|
|
be the title of an entry of the feed, the text until the next will |
22
|
|
|
|
|
|
|
become the cotent of the entry. The id attribute of the title prefixed |
23
|
|
|
|
|
|
|
by a base url will become the permalink of the entry. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Such a design is intended to allow to share content between the feed and |
26
|
|
|
|
|
|
|
a webpage. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
It uses the following variables: |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=over |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=item feedtitle |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
The title of the feed |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item description |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The description of the feed |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item content |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The content. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item url |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
The base url for the links |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item webmaster |
49
|
|
|
|
|
|
|
=item language |
50
|
|
|
|
|
|
|
=item update |
51
|
|
|
|
|
|
|
=item content |
52
|
|
|
|
|
|
|
=item copyright |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
See L for more information on the variables. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=back |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 EXAMPLE |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Feed title |
62
|
|
|
|
|
|
|
Feed description |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
name="url">http://gnagna.foo |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
index.html looks like: |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Foo Bar |
71
|
|
|
|
|
|
|
Some text |
72
|
|
|
|
|
|
|
Hello world |
73
|
|
|
|
|
|
|
Some other text |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SEE ALSO |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Lookt at L. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 METHODS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 process |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Do the real processing |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub process { |
88
|
|
|
|
|
|
|
my ($self) = @_; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $page = $self->{page}; |
91
|
|
|
|
|
|
|
my $variables = $self->{variables}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# $variables->{root} = $self->root(); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $name = $page->att('name'); |
96
|
|
|
|
|
|
|
# $variables->{page} = $name; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $extension = $page->att('extension'); |
99
|
|
|
|
|
|
|
# $variables->{extension} = $extension; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $feedtitle = $variables->{feedtitle}; |
102
|
|
|
|
|
|
|
$feedtitle = decode('UTF-8', $feedtitle); |
103
|
|
|
|
|
|
|
my $description = $variables->{description}; |
104
|
|
|
|
|
|
|
$description = decode('UTF-8', $description); |
105
|
|
|
|
|
|
|
my $url = $variables->{url}; |
106
|
|
|
|
|
|
|
my $webmaster = $variables->{webmaster}; |
107
|
|
|
|
|
|
|
my $language = $variables->{language}; |
108
|
|
|
|
|
|
|
my $update = $variables->{update}; |
109
|
|
|
|
|
|
|
my $content = $variables->{content}; |
110
|
|
|
|
|
|
|
my $copyright = $variables->{copyright}; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $xml = XML::Twig->new( |
113
|
|
|
|
|
|
|
keep_encoding => 1 |
114
|
|
|
|
|
|
|
) |
115
|
|
|
|
|
|
|
->parse("" . $content . ""); |
116
|
|
|
|
|
|
|
my $root= $xml->root; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $cached = $self->cache($name, $extension); |
119
|
|
|
|
|
|
|
my @items = (); |
120
|
|
|
|
|
|
|
my $dt = DateTime->now(); |
121
|
|
|
|
|
|
|
my $date = $dt->strftime("%a, %d %b %Y %H:%M:%S %z"); |
122
|
|
|
|
|
|
|
my $pubDate = $date; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
if (-r $cached) { |
125
|
|
|
|
|
|
|
my $oldrss = new XML::RSS (version => '2.0'); |
126
|
|
|
|
|
|
|
$oldrss->parsefile($cached); |
127
|
|
|
|
|
|
|
@items = @{$oldrss->{'items'}}; |
128
|
|
|
|
|
|
|
$pubDate = $oldrss->{pubDate}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
my $rss = new XML::RSS (version => '2.0'); |
131
|
|
|
|
|
|
|
$rss->channel(title => $feedtitle, |
132
|
|
|
|
|
|
|
link => $url, |
133
|
|
|
|
|
|
|
language => $language, |
134
|
|
|
|
|
|
|
description => $description, |
135
|
|
|
|
|
|
|
copyright => $copyright, |
136
|
|
|
|
|
|
|
pubDate => $pubDate, |
137
|
|
|
|
|
|
|
lastBuildDate => $date, |
138
|
|
|
|
|
|
|
managingEditor => $webmaster, |
139
|
|
|
|
|
|
|
webMaster => $webmaster, |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my @h1= $root->children('h1'); |
143
|
|
|
|
|
|
|
foreach my $h1 (@h1) { |
144
|
|
|
|
|
|
|
my $title = $h1->text; |
145
|
|
|
|
|
|
|
my $guid = decode("UTF-8", $h1->att('id')); |
146
|
|
|
|
|
|
|
my $link = $url . "#" . $guid; |
147
|
|
|
|
|
|
|
my $date; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
my @grep = grep {$_->{link} eq $link} @items; |
150
|
|
|
|
|
|
|
if (@grep) { |
151
|
|
|
|
|
|
|
$date = $grep[0]->{pubDate}; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
else { |
154
|
|
|
|
|
|
|
my $dt = DateTime->now(); |
155
|
|
|
|
|
|
|
$date = $dt->strftime("%a, %d %b %Y %H:%M:%S %z"); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
my $description; |
158
|
|
|
|
|
|
|
my @lines; |
159
|
|
|
|
|
|
|
my $next = $h1->next_sibling(); |
160
|
|
|
|
|
|
|
while (defined($next) && $next->tag ne "h1") { |
161
|
|
|
|
|
|
|
push @lines, $next->sprint; |
162
|
|
|
|
|
|
|
$next = $next->next_sibling(); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
$description = join("", @lines); |
165
|
|
|
|
|
|
|
$description = decode('UTF-8', $description); |
166
|
|
|
|
|
|
|
$description = decode_entities($description); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
$title = decode('UTF-8', $title); |
169
|
|
|
|
|
|
|
$title = decode_entities($title); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$rss->add_item( |
172
|
|
|
|
|
|
|
title => $title, |
173
|
|
|
|
|
|
|
link => $link, |
174
|
|
|
|
|
|
|
description => $description, |
175
|
|
|
|
|
|
|
pubDate => $date, |
176
|
|
|
|
|
|
|
); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
$rss->save($cached); |
179
|
|
|
|
|
|
|
$rss->save($self->output($name, $extension)); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |