-
Notifications
You must be signed in to change notification settings - Fork 3
/
atomfeed-v20050301
236 lines (166 loc) · 7.28 KB
/
atomfeed-v20050301
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Blosxom Plugin: atomfeed
# Author(s): Rael Dornfest <[email protected]>
# Version: 2005-03-01
# Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
# Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
package atomfeed;
# --- Configurable variables -----
# Who would you like your feed to credit as the default author of each entry?
# Leave blank and the atomfeed plugin will attempt to use the whoami and
# fauxami plugins
$default_author = '';
# What domain should Blosxom use in ID tags?
# Leave blank if you don't understand or for Blosxom to use the domain in $url.
$id_domain = '';
# --- Plug-in package variables -----
$author = '';
$T = 'T';
$colon = ':';
$zerozero = '00';
# URL where an atom.css might reside
$css_url = "$blosxom::url/atom.css";
# Try to glean the domain from $url
$id_domain or ($id_domain) = $blosxom::url =~ m#http://(?:www\.)?([^\/]+)#;
# Glean year for feed id
$feed_yr = (gmtime(time))[5] + 1900;
$utc_date = '';
$feed_utc_date = '';
use vars qw/$feed_utc_date/;
# --------------------------------
sub start {
# Check for the existence of already-loaded flavour templates or theme
$blosxom::template{'atom'}{'head'} and return 1;
# Otherwise, load on-board templates
_load_templates();
eval {use XML::Parser; $parser = new XML::Parser;};
%escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"');
$escape_re = join '|' => keys %escape;
1;
}
sub story {
my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
my @utc = gmtime($blosxom::files{"$blosxom::datadir$path/$filename.$blosxom::file_extension"});
$utc_date = sprintf("%4d-%02d-%02dT%02d:%02d:00Z",
$utc[5]+1900, $utc[4]+1, $utc[3], $utc[2], $utc[1]);
$utc_yr = $utc[5]+1900;
# Date/time of most recently-modified story becomes date/time of the feed.
$feed_utc_date = $utc_date if $utc_date > $feed_utc_date;
# Set authorship if available, falling back to $atomfeed::author
$author = $whoami::fullname || $fauxami::name || $default_author || '';
if (eval {$parser->parse("<div>$$body_ref</div>")}) {
$type = 'application/xhtml+xml';
$mode = 'xml';
$body = "<div xmlns=\"http://www.w3.org/1999/xhtml\">$$body_ref</div>";
} else {
$type = 'text/html';
$mode = 'escaped';
if (index($$body_ref,']]>')<0) {
$body = "<![CDATA[$$body_ref]]>";
} else {
($body = $$body_ref) =~ s/($escape_re)/$escape{$1}/g;
}
}
1;
}
sub _load_templates {
$blosxom::template{'atom'}{'content_type'} = 'application/atom+xml';
$blosxom::template{'atom'}{'date'} = "\n";
$blosxom::template{'atom'}{'head'} =<<'HEAD';
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="$atomfeed::css_url" type="text/css"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
<title type="text/plain">$blosxom::blog_title</title>
<tagline type="text/plain">$blosxom::blog_description</tagline>
<link rel="alternate" type="text/html" href="$blosxom::url" />
<id>tag$atomfeed::colon$atomfeed::id_domain,$atomfeed::feed_yr$atomfeed::colon/$blosxom::path_info</id>
<generator url="http://www.blosxom.com/" version="$blosxom::version">Blosxom</generator>
HEAD
$blosxom::template{'atom'}{'story'} =<<'STORY';
<entry>
<id>tag$atomfeed::colon$atomfeed::id_domain,$atomfeed::utc_yr$atomfeed::colon$path/$fn</id>
<link rel="alternate" type="text/html" href="$blosxom::url$blosxom::path/$blosxom::fn.$blosxom::default_flavour" />
<title type="text/plain">$blosxom::title</title>
<dc:subject>$blosxom::path</dc:subject>
<issued>$atomfeed::utc_date</issued>
<modified>$atomfeed::utc_date</modified>
<author>
<name>$atomfeed::author</name>
</author>
<content type="$atomfeed::type" xml:base="$blosxom::url" xml:lang="$blosxom::blog_language" xml:space="preserve" mode="$atomfeed::mode">
$atomfeed::body
</content>
</entry>
STORY
$blosxom::template{'atom'}{'foot'} =<<'FOOT';
<modified>$atomfeed::feed_utc_date</modified>
</feed>
FOOT
1;
}
1;
__END__
=head1 NAME
Blosxom Plug-in: atomfeed
=head1 SYNOPSIS
Provides an Atom feed of your weblog.
The plugin has all you need right on-board, including the appropriate flavour
template components and a couple-three configuration directives.
Point your browser/Atom feed reader at http://yoururl/index.atom.
=head1 VERSION
2003-12-11
=head1 AUTHOR
Rael Dornfest <[email protected]>, http://www.raelity.org/
Sam Ruby <[email protected]>, http://www.intertwingly.net/
- contributed the XML::Parser magic
Frank Hecker <[email protected]>, http://www.hecker.org/
- contributed patches for Atom 0.3 compliance, UTC date/time fix
=head1 INSTALLATION
Drop atomfeed into your plugins directory.
=head1 CONFIGURATION
Drop atomfeed into your plugins directory.
All other configuration is optional.
$default_author is where you specify who you'd like to credit as the default
author of each entry. I say "default" since if you leave it blank it'll
attempt to use the value provided by the whoami or fauxami plugins if you
happen to have them installed.
e.g. $default_author = 'Rael Dornfest';
Atom associates unique ID tags with the feed itself and individual entries.
By default it'll attempt to glean your domain from the specified or calculated
value of $blosxom::url. But you can override this by setting $id_domain in
the configuration section above.
e.g. $id_domain = "raelity.org";
Just be sure it's a domain name sans any http://, slashes, extra path bits,
or what-have-you.
=head1 OTHER PLUGINS
The atomfeed plugin assumes you're not running any fancy interpolation plugin
(e.g. interpolate_fancy) which changes the way variables are specified in a
template (e.g. <$foo /> rather than $foo).
If you are running interpolate_fancy or the like--I am--use the config plugin
and a config.atom file in your blosxom $datadir consisting of:
$blosxom::plugins{"interpolate_fancy"} = 0;
Where "interpolate_fancy" is the name of the interpolation plugin you're
turning off _just for the atom feed_.
=head1 SEE ALSO
Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
=head1 BUGS
Address bug reports and comments to the Blosxom mailing list
[http://www.yahoogroups.com/group/blosxom].
=head1 LICENSE
Blosxom and this Blosxom Plug-in
Copyright 2003, Rael Dornfest
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.