]> git.deb.at Git - pkg/blosxom.git/blob - blosxom.cgi
Add plugin_dir and plugin_list test cases.
[pkg/blosxom.git] / blosxom.cgi
1 #!/usr/bin/perl
2
3 # Blosxom
4 # Author: Rael Dornfest <rael@oreilly.com>
5 # Version: 2.0.2
6 # Home/Docs/Licensing: http://blosxom.sourceforge.net/
7 # Development/Downloads: http://sourceforge.net/projects/blosxom
8
9 package blosxom;
10
11 # --- Configurable variables -----
12
13 # What's this blog's title?
14 $blog_title = "My Weblog";
15
16 # What's this blog's description (for outgoing RSS feed)?
17 $blog_description = "Yet another Blosxom weblog.";
18
19 # What's this blog's primary language (for outgoing RSS feed)?
20 $blog_language = "en";
21
22 # What's this blog's text encoding ?
23 $blog_encoding = "UTF-8";
24
25 # Where are this blog's entries kept?
26 $datadir = "/Library/WebServer/Documents/blosxom";
27
28 # What's my preferred base URL for this blog (leave blank for automatic)?
29 $url = "";
30
31 # Should I stick only to the datadir for items or travel down the
32 # directory hierarchy looking for items?  If so, to what depth?
33 # 0 = infinite depth (aka grab everything), 1 = datadir only, n = n levels down
34 $depth = 0;
35
36 # How many entries should I show on the home page?
37 $num_entries = 40;
38
39 # What file extension signifies a blosxom entry?
40 $file_extension = "txt";
41
42 # What is the default flavour?
43 $default_flavour = "html";
44
45 # Should I show entries from the future (i.e. dated after now)?
46 $show_future_entries = 0;
47
48 # --- Plugins (Optional) -----
49
50 # File listing plugins blosxom should load
51 # (if empty blosxom will load all plugins in $plugin_dir and $plugin_path directories)
52 $plugin_list = "";
53
54 # Where are my plugins kept?
55 $plugin_dir = "";
56
57 # Where should my plugins keep their state information?
58 $plugin_state_dir = "$plugin_dir/state";
59
60 # Additional plugins location
61 # List of directories, separated by ';' on windows, ':' everywhere else
62 $plugin_path = "";
63
64 # --- Static Rendering -----
65
66 # Where are this blog's static files to be created?
67 $static_dir = "/Library/WebServer/Documents/blog";
68
69 # What's my administrative password (you must set this for static rendering)?
70 $static_password = "";
71
72 # What flavours should I generate statically?
73 @static_flavours = qw/html rss/;
74
75 # Should I statically generate individual entries?
76 # 0 = no, 1 = yes
77 $static_entries = 0;
78
79 # --------------------------------
80
81 use vars
82     qw! $version $blog_title $blog_description $blog_language $blog_encoding $datadir $url %template $template $depth $num_entries $file_extension $default_flavour $static_or_dynamic $config_dir $plugin_list $plugin_path $plugin_dir $plugin_state_dir @plugins %plugins $static_dir $static_password @static_flavours $static_entries $path_info $path_info_yr $path_info_mo $path_info_da $path_info_mo_num $flavour $static_or_dynamic %month2num @num2month $interpolate $entries $output $header $show_future_entries %files %indexes %others !;
83
84 use strict;
85 use FileHandle;
86 use File::Find;
87 use File::stat;
88 use Time::Local;
89 use CGI qw/:standard :netscape/;
90
91 $version = "2.0.2";
92
93 # Load configuration from $ENV{BLOSXOM_CONFIG_DIR}/blosxom.conf, if it exists
94 my $blosxom_config;
95 if ( $ENV{BLOSXOM_CONFIG_FILE} && -r $ENV{BLOSXOM_CONFIG_FILE} ) {
96     $blosxom_config = $ENV{BLOSXOM_CONFIG_FILE};
97     ( $config_dir = $blosxom_config ) =~ s! / [^/]* $ !!x;
98 }
99 else {
100     for my $blosxom_config_dir ( $ENV{BLOSXOM_CONFIG_DIR}, '/etc/blosxom',
101         '/etc' )
102     {
103         if ( -r "$blosxom_config_dir/blosxom.conf" ) {
104             $config_dir     = $blosxom_config_dir;
105             $blosxom_config = "$blosxom_config_dir/blosxom.conf";
106             last;
107         }
108     }
109 }
110
111 # Load $blosxom_config
112 if ($blosxom_config) {
113     if ( -r $blosxom_config ) {
114         eval { require $blosxom_config }
115             or warn "Error reading blosxom config file '$blosxom_config'"
116             . ( $@ ? ": $@" : '' );
117     }
118     else {
119         warn "Cannot find or read blosxom config file '$blosxom_config'";
120     }
121 }
122
123 my $fh = new FileHandle;
124
125 %month2num = (
126     nil => '00',
127     Jan => '01',
128     Feb => '02',
129     Mar => '03',
130     Apr => '04',
131     May => '05',
132     Jun => '06',
133     Jul => '07',
134     Aug => '08',
135     Sep => '09',
136     Oct => '10',
137     Nov => '11',
138     Dec => '12'
139 );
140 @num2month = sort { $month2num{$a} <=> $month2num{$b} } keys %month2num;
141
142 # Use the stated preferred URL or figure it out automatically
143 $url ||= url( -path_info => 1 );
144 $url =~ s/^included:/http:/ if $ENV{SERVER_PROTOCOL} eq 'INCLUDED';
145
146 # NOTE: Since v3.12, it looks as if CGI.pm misbehaves for SSIs and
147 # always appends path_info to the url. To fix this, we always
148 # request an url with path_info, and always remove it from the end of the
149 # string.
150 my $pi_len = length $ENV{PATH_INFO};
151 my $might_be_pi = substr( $url, -$pi_len );
152 substr( $url, -length $ENV{PATH_INFO} ) = ''
153     if $might_be_pi eq $ENV{PATH_INFO};
154
155 $url =~ s!/$!!;
156
157 # Drop ending any / from dir settings
158 $datadir    =~ s!/$!!;
159 $plugin_dir =~ s!/$!!;
160 $static_dir =~ s!/$!!;
161
162 # Fix depth to take into account datadir's path
163 $depth += ( $datadir =~ tr[/][] ) - 1 if $depth;
164
165 # Global variable to be used in head/foot.{flavour} templates
166 $path_info = '';
167
168 if (    !$ENV{GATEWAY_INTERFACE}
169     and param('-password')
170     and $static_password
171     and param('-password') eq $static_password )
172 {
173     $static_or_dynamic = 'static';
174 }
175 else {
176     $static_or_dynamic = 'dynamic';
177     param( -name => '-quiet', -value => 1 );
178 }
179
180 # Path Info Magic
181 # Take a gander at HTTP's PATH_INFO for optional blog name, archive yr/mo/day
182 my @path_info = split m{/}, path_info() || param('path');
183 shift @path_info;
184
185 while ( $path_info[0]
186     and $path_info[0] =~ /^[a-zA-Z].*$/
187     and $path_info[0] !~ /(.*)\.(.*)/ )
188 {
189     $path_info .= '/' . shift @path_info;
190 }
191
192 # Flavour specified by ?flav={flav} or index.{flav}
193 $flavour = '';
194
195 if ( $path_info[$#path_info] =~ /(.+)\.(.+)$/ ) {
196     $flavour = $2;
197     $path_info .= "/$1.$2" if $1 ne 'index';
198     pop @path_info;
199 }
200 else {
201     $flavour = param('flav') || $default_flavour;
202 }
203
204 # Strip spurious slashes
205 $path_info =~ s!(^/*)|(/*$)!!g;
206
207 # Date fiddling
208 ( $path_info_yr, $path_info_mo, $path_info_da ) = @path_info;
209 $path_info_mo_num
210     = $path_info_mo
211     ? ( $path_info_mo =~ /\d{2}/
212     ? $path_info_mo
213     : ( $month2num{ ucfirst( lc $path_info_mo ) } || undef ) )
214     : undef;
215
216 # Define standard template subroutine, plugin-overridable at Plugins: Template
217 $template = sub {
218     my ( $path, $chunk, $flavour ) = @_;
219
220     do {
221         return join '', <$fh>
222             if $fh->open("< $datadir/$path/$chunk.$flavour");
223     } while ( $path =~ s/(\/*[^\/]*)$// and $1 );
224
225     # Check for definedness, since flavour can be the empty string
226     if ( defined $template{$flavour}{$chunk} ) {
227         return $template{$flavour}{$chunk};
228     }
229     elsif ( defined $template{error}{$chunk} ) {
230         return $template{error}{$chunk};
231     }
232     else {
233         return '';
234     }
235 };
236
237 # Bring in the templates
238 %template = ();
239 while (<DATA>) {
240     last if /^(__END__)$/;
241     my ( $ct, $comp, $txt ) = /^(\S+)\s(\S+)(?:\s(.*))?$/ or next;
242     $txt =~ s/\\n/\n/mg;
243     $template{$ct}{$comp} .= $txt . "\n";
244 }
245
246 # Plugins: Start
247 my $path_sep = $^O eq 'MSWin32' ? ';' : ':';
248 my @plugin_dirs = split /$path_sep/, $plugin_path;
249 unshift @plugin_dirs, $plugin_dir;
250 my @plugin_list = ();
251 my %plugin_hash = ();
252
253 # If $plugin_list is set, read plugins to use from that file
254 if ( $plugin_list ) {
255     if ( -r $plugin_list and $fh->open("< $plugin_list") ) {
256         @plugin_list = map { chomp $_; $_ } grep { /\S/ && !/^#/ } <$fh>;
257         $fh->close;
258     }
259     else {
260         warn "unable to read or open plugin_list '$plugin_list': $!";
261         $plugin_list = '';
262     }
263 }
264
265 # Otherwise walk @plugin_dirs to get list of plugins to use
266 if ( ! @plugin_list && @plugin_dirs ) {
267     for my $plugin_dir (@plugin_dirs) {
268         next unless -d $plugin_dir;
269         if ( opendir PLUGINS, $plugin_dir ) {
270             for my $plugin (
271                 grep { /^[\w:]+$/ && !/~$/ && -f "$plugin_dir/$_" }
272                 readdir(PLUGINS) )
273             {
274
275                 # Ignore duplicates
276                 next if $plugin_hash{$plugin};
277
278                 # Add to @plugin_list and %plugin_hash
279                 $plugin_hash{$plugin} = "$plugin_dir/$plugin";
280                 push @plugin_list, $plugin;
281             }
282             closedir PLUGINS;
283         }
284     }
285     @plugin_list = sort @plugin_list;
286 }
287
288 # Load all plugins in @plugin_list
289 unshift @INC, @plugin_dirs;
290 foreach my $plugin (@plugin_list) {
291     my ( $plugin_name, $off ) = $plugin =~ /^\d*([\w:]+?)(_?)$/;
292     my $plugin_file = $plugin_list ? $plugin_name : $plugin;
293     my $on_off = $off eq '_' ? -1 : 1;
294
295     # Allow perl module plugins
296     if ( $plugin =~ m/::/ && ( $plugin_list || -z $plugin_hash{$plugin} ) ) {
297
298      # For Blosxom::Plugin::Foo style plugins, we need to use a string require
299         eval "require $plugin_file";
300     }
301     else
302     { # we try first to load from $plugin_dir before attempting from $plugin_path
303         eval        { require "$plugin_dir/$plugin_file" }
304             or eval { require $plugin_file };
305     }
306
307     if ($@) {
308         warn "error finding or loading blosxom plugin '$plugin_name': $@";
309         next;
310     }
311     if ( $plugin_name->start() and ( $plugins{$plugin_name} = $on_off ) ) {
312         push @plugins, $plugin_name;
313     }
314
315 }
316 shift @INC foreach @plugin_dirs;
317
318 # Plugins: Template
319 # Allow for the first encountered plugin::template subroutine to override the
320 # default built-in template subroutine
321 foreach my $plugin (@plugins) {
322     if ( $plugins{$plugin} > 0 and $plugin->can('template') ) {
323         if ( my $tmp = $plugin->template() ) {
324             $template = $tmp;
325             last;
326         }
327     }
328 }
329
330 # Provide backward compatibility for Blosxom < 2.0rc1 plug-ins
331 sub load_template {
332     return &$template(@_);
333 }
334
335 # Define default entries subroutine
336 $entries = sub {
337     my ( %files, %indexes, %others );
338     find(
339         sub {
340             my $d;
341             my $curr_depth = $File::Find::dir =~ tr[/][];
342             return if $depth and $curr_depth > $depth;
343
344             if (
345
346                 # a match
347                 $File::Find::name
348                 =~ m!^$datadir/(?:(.*)/)?(.+)\.$file_extension$!
349
350                 # not an index, .file, and is readable
351                 and $2 ne 'index' and $2 !~ /^\./ and ( -r $File::Find::name )
352                 )
353             {
354
355                 # read modification time
356                 my $mtime = stat($File::Find::name)->mtime or return;
357
358                 # to show or not to show future entries
359                 return unless ( $show_future_entries or $mtime < time );
360
361                 # add the file and its associated mtime to the list of files
362                 $files{$File::Find::name} = $mtime;
363
364                 # static rendering bits
365                 my $static_file
366                     = "$static_dir/$1/index." . $static_flavours[0];
367                 if (   param('-all')
368                     or !-f $static_file
369                     or stat($static_file)->mtime < $mtime )
370                 {
371                     $indexes{$1} = 1;
372                     $d = join( '/', ( nice_date($mtime) )[ 5, 2, 3 ] );
373                     $indexes{$d} = $d;
374                     $indexes{ ( $1 ? "$1/" : '' ) . "$2.$file_extension" } = 1
375                         if $static_entries;
376                 }
377             }
378
379             # not an entries match
380             elsif ( !-d $File::Find::name and -r $File::Find::name ) {
381                 $others{$File::Find::name} = stat($File::Find::name)->mtime;
382             }
383         },
384         $datadir
385     );
386
387     return ( \%files, \%indexes, \%others );
388 };
389
390 # Plugins: Entries
391 # Allow for the first encountered plugin::entries subroutine to override the
392 # default built-in entries subroutine
393 foreach my $plugin (@plugins) {
394     if ( $plugins{$plugin} > 0 and $plugin->can('entries') ) {
395         if ( my $tmp = $plugin->entries() ) {
396             $entries = $tmp;
397             last;
398         }
399     }
400 }
401
402 my ( $files, $indexes, $others ) = &$entries();
403 %indexes = %$indexes;
404
405 # Static
406 if (    !$ENV{GATEWAY_INTERFACE}
407     and param('-password')
408     and $static_password
409     and param('-password') eq $static_password )
410 {
411
412     param('-quiet') or print "Blosxom is generating static index pages...\n";
413
414     # Home Page and Directory Indexes
415     my %done;
416     foreach my $path ( sort keys %indexes ) {
417         my $p = '';
418         foreach ( ( '', split /\//, $path ) ) {
419             $p .= "/$_";
420             $p =~ s!^/!!;
421             next if $done{$p}++;
422             mkdir "$static_dir/$p", 0755
423                 unless ( -d "$static_dir/$p" or $p =~ /\.$file_extension$/ );
424             foreach $flavour (@static_flavours) {
425                 my $content_type
426                     = ( &$template( $p, 'content_type', $flavour ) );
427                 $content_type =~ s!\n.*!!s;
428                 my $fn = $p =~ m!^(.+)\.$file_extension$! ? $1 : "$p/index";
429                 param('-quiet') or print "$fn.$flavour\n";
430                 my $fh_w = new FileHandle "> $static_dir/$fn.$flavour"
431                     or die "Couldn't open $static_dir/$p for writing: $!";
432                 $output = '';
433                 if ( $indexes{$path} == 1 ) {
434
435                     # category
436                     $path_info = $p;
437
438                     # individual story
439                     $path_info =~ s!\.$file_extension$!\.$flavour!;
440                     print $fh_w &generate( 'static', $path_info, '', $flavour,
441                         $content_type );
442                 }
443                 else {
444
445                     # date
446                     local (
447                         $path_info_yr, $path_info_mo,
448                         $path_info_da, $path_info
449                     ) = split /\//, $p, 4;
450                     unless ( defined $path_info ) { $path_info = "" }
451                     print $fh_w &generate( 'static', '', $p, $flavour,
452                         $content_type );
453                 }
454                 $fh_w->close;
455             }
456         }
457     }
458 }
459
460 # Dynamic
461 else {
462     my $content_type = ( &$template( $path_info, 'content_type', $flavour ) );
463     $content_type =~ s!\n.*!!s;
464
465     $content_type =~ s/(\$\w+(?:::\w+)*)/"defined $1 ? $1 : ''"/gee;
466     $header = { -type => $content_type };
467
468     print generate( 'dynamic', $path_info,
469         "$path_info_yr/$path_info_mo_num/$path_info_da",
470         $flavour, $content_type );
471 }
472
473 # Plugins: End
474 foreach my $plugin (@plugins) {
475     if ( $plugins{$plugin} > 0 and $plugin->can('end') ) {
476         $entries = $plugin->end();
477     }
478 }
479
480 # Generate
481 sub generate {
482     my ( $static_or_dynamic, $currentdir, $date, $flavour, $content_type )
483         = @_;
484
485     %files = %$files;
486     %others = ref $others ? %$others : ();
487
488     # Plugins: Filter
489     foreach my $plugin (@plugins) {
490         if ( $plugins{$plugin} > 0 and $plugin->can('filter') ) {
491             $entries = $plugin->filter( \%files, \%others );
492         }
493     }
494
495     my %f = %files;
496
497     # Plugins: Skip
498     # Allow plugins to decide if we can cut short story generation
499     my $skip;
500     foreach my $plugin (@plugins) {
501         if ( $plugins{$plugin} > 0 and $plugin->can('skip') ) {
502             if ( my $tmp = $plugin->skip() ) {
503                 $skip = $tmp;
504                 last;
505             }
506         }
507     }
508
509     # Define default interpolation subroutine
510     $interpolate = sub {
511
512         package blosxom;
513         my $template = shift;
514         $template =~ s/(\$\w+(?:::\w+)*)/"defined $1 ? $1 : ''"/gee;
515         return $template;
516     };
517
518     unless ( defined($skip) and $skip ) {
519
520         # Plugins: Interpolate
521         # Allow for the first encountered plugin::interpolate subroutine to
522         # override the default built-in interpolate subroutine
523         foreach my $plugin (@plugins) {
524             if ( $plugins{$plugin} > 0 and $plugin->can('interpolate') ) {
525                 if ( my $tmp = $plugin->interpolate() ) {
526                     $interpolate = $tmp;
527                     last;
528                 }
529             }
530         }
531
532         # Head
533         my $head = ( &$template( $currentdir, 'head', $flavour ) );
534
535         # Plugins: Head
536         foreach my $plugin (@plugins) {
537             if ( $plugins{$plugin} > 0 and $plugin->can('head') ) {
538                 $entries = $plugin->head( $currentdir, \$head );
539             }
540         }
541
542         $head = &$interpolate($head);
543
544         $output .= $head;
545
546         # Stories
547         my $curdate = '';
548         my $ne      = $num_entries;
549
550         if ( $currentdir =~ /(.*?)([^\/]+)\.(.+)$/ and $2 ne 'index' ) {
551             $currentdir = "$1$2.$file_extension";
552             %f = ( "$datadir/$currentdir" => $files{"$datadir/$currentdir"} )
553                 if $files{"$datadir/$currentdir"};
554         }
555         else {
556             $currentdir =~ s!/index\..+$!!;
557         }
558
559         # Define a default sort subroutine
560         my $sort = sub {
561             my ($files_ref) = @_;
562             return
563                 sort { $files_ref->{$b} <=> $files_ref->{$a} }
564                 keys %$files_ref;
565         };
566
567      # Plugins: Sort
568      # Allow for the first encountered plugin::sort subroutine to override the
569      # default built-in sort subroutine
570         foreach my $plugin (@plugins) {
571             if ( $plugins{$plugin} > 0 and $plugin->can('sort') ) {
572                 if ( my $tmp = $plugin->sort() ) {
573                     $sort = $tmp;
574                     last;
575                 }
576             }
577         }
578
579         foreach my $path_file ( &$sort( \%f, \%others ) ) {
580             last if $ne <= 0 && $date !~ /\d/;
581             use vars qw/ $path $fn /;
582             ( $path, $fn )
583                 = $path_file =~ m!^$datadir/(?:(.*)/)?(.*)\.$file_extension!;
584
585             # Only stories in the right hierarchy
586             $path =~ /^$currentdir/
587                 or $path_file eq "$datadir/$currentdir"
588                 or next;
589
590             # Prepend a slash for use in templates only if a path exists
591             $path &&= "/$path";
592
593             # Date fiddling for by-{year,month,day} archive views
594             use vars
595                 qw/ $dw $mo $mo_num $da $ti $yr $hr $min $hr12 $ampm $utc_offset/;
596             ( $dw, $mo, $mo_num, $da, $ti, $yr, $utc_offset )
597                 = nice_date( $files{"$path_file"} );
598             ( $hr, $min ) = split /:/, $ti;
599             ( $hr12, $ampm ) = $hr >= 12 ? ( $hr - 12, 'pm' ) : ( $hr, 'am' );
600             $hr12 =~ s/^0//;
601             if ( $hr12 == 0 ) { $hr12 = 12 }
602
603             # Only stories from the right date
604             my ( $path_info_yr, $path_info_mo_num, $path_info_da )
605                 = split /\//, $date;
606             next if $path_info_yr     && $yr != $path_info_yr;
607             last if $path_info_yr     && $yr < $path_info_yr;
608             next if $path_info_mo_num && $mo ne $num2month[$path_info_mo_num];
609             next if $path_info_da     && $da != $path_info_da;
610             last if $path_info_da     && $da < $path_info_da;
611
612             # Date
613             my $date = ( &$template( $path, 'date', $flavour ) );
614
615             # Plugins: Date
616             foreach my $plugin (@plugins) {
617                 if ( $plugins{$plugin} > 0 and $plugin->can('date') ) {
618                     $entries
619                         = $plugin->date( $currentdir, \$date,
620                         $files{$path_file}, $dw, $mo, $mo_num, $da, $ti,
621                         $yr );
622                 }
623             }
624
625             $date = &$interpolate($date);
626
627             if ( $date && $curdate ne $date ) {
628                 $curdate = $date;
629                 $output .= $date;
630             }
631
632             use vars qw/ $title $body $raw /;
633             if ( -f "$path_file" && $fh->open("< $path_file") ) {
634                 chomp( $title = <$fh> );
635                 chomp( $body = join '', <$fh> );
636                 $fh->close;
637                 $raw = "$title\n$body";
638             }
639             my $story = ( &$template( $path, 'story', $flavour ) );
640
641             # Plugins: Story
642             foreach my $plugin (@plugins) {
643                 if ( $plugins{$plugin} > 0 and $plugin->can('story') ) {
644                     $entries = $plugin->story( $path, $fn, \$story, \$title,
645                         \$body );
646                 }
647             }
648
649             if ( $content_type =~ m{\bxml\b} ) {
650
651                 # Escape <, >, and &, and to produce valid RSS
652                 my %escape = (
653                     '<' => '&lt;',
654                     '>' => '&gt;',
655                     '&' => '&amp;',
656                     '"' => '&quot;'
657                 );
658                 my $escape_re = join '|' => keys %escape;
659                 $title =~ s/($escape_re)/$escape{$1}/g;
660                 $body  =~ s/($escape_re)/$escape{$1}/g;
661             }
662
663             $story = &$interpolate($story);
664
665             $output .= $story;
666             $fh->close;
667
668             $ne--;
669         }
670
671         # Foot
672         my $foot = ( &$template( $currentdir, 'foot', $flavour ) );
673
674         # Plugins: Foot
675         foreach my $plugin (@plugins) {
676             if ( $plugins{$plugin} > 0 and $plugin->can('foot') ) {
677                 $entries = $plugin->foot( $currentdir, \$foot );
678             }
679         }
680
681         $foot = &$interpolate($foot);
682         $output .= $foot;
683
684         # Plugins: Last
685         foreach my $plugin (@plugins) {
686             if ( $plugins{$plugin} > 0 and $plugin->can('last') ) {
687                 $entries = $plugin->last();
688             }
689         }
690
691     }    # End skip
692
693     # Finally, add the header, if any and running dynamically
694     $output = header($header) . $output
695         if ( $static_or_dynamic eq 'dynamic' and $header );
696
697     $output;
698 }
699
700 sub nice_date {
701     my ($unixtime) = @_;
702
703     my $c_time = CORE::localtime($unixtime);
704     my ( $dw, $mo, $da, $hr, $min, $sec, $yr )
705         = ( $c_time
706             =~ /(\w{3}) +(\w{3}) +(\d{1,2}) +(\d{2}):(\d{2}):(\d{2}) +(\d{4})$/
707         );
708     $ti = "$hr:$min";
709     $da = sprintf( "%02d", $da );
710     my $mo_num = $month2num{$mo};
711
712     my $offset
713         = timegm( $sec, $min, $hr, $da, $mo_num - 1, $yr - 1900 ) - $unixtime;
714     my $utc_offset = sprintf( "%+03d", int( $offset / 3600 ) )
715         . sprintf( "%02d", ( $offset % 3600 ) / 60 );
716
717     return ( $dw, $mo, $mo_num, $da, $ti, $yr, $utc_offset );
718 }
719
720 # Default HTML and RSS template bits
721 __DATA__
722 html content_type text/html; charset=$blog_encoding
723
724 html head <html>
725 html head     <head>
726 html head         <meta http-equiv="content-type" content="text/html;charset=$blog_encoding" />
727 html head         <link rel="alternate" type="type="application/rss+xml" title="RSS" href="$url/index.rss" />
728 html head         <title>$blog_title $path_info_da $path_info_mo $path_info_yr
729 html head         </title>
730 html head     </head>
731 html head     <body>
732 html head         <center>
733 html head             <font size="+3">$blog_title</font><br />
734 html head             $path_info_da $path_info_mo $path_info_yr
735 html head         </center>
736 html head         <p />
737
738 html story        <p>
739 html story            <a name="$fn"><b>$title</b></a><br />
740 html story            $body<br />
741 html story            <br />
742 html story            posted at: $ti | path: <a href="$url$path">$path </a> | <a href="$url/$yr/$mo_num/$da#$fn">permanent link to this entry</a>
743 html story        </p>
744
745 html date         <h3>$dw, $da $mo $yr</h3>
746
747 html foot
748 html foot         <p />
749 html foot         <center>
750 html foot             <a href="http://blosxom.sourceforge.net/"><img src="http://blosxom.sourceforge.net/images/pb_blosxom.gif" border="0" /></a>
751 html foot         </center>
752 html foot     </body>
753 html foot </html>
754
755 rss content_type text/xml; charset=$blog_encoding
756
757 rss head <?xml version="1.0" encoding="$blog_encoding"?>
758 rss head <rss version="2.0">
759 rss head   <channel>
760 rss head     <title>$blog_title</title>
761 rss head     <link>$url/$path_info</link>
762 rss head     <description>$blog_description</description>
763 rss head     <language>$blog_language</language>
764 rss head     <docs>http://blogs.law.harvard.edu/tech/rss</docs>
765 rss head     <generator>blosxom/$version</generator>
766
767 rss story   <item>
768 rss story     <title>$title</title>
769 rss story     <pubDate>$dw, $da $mo $yr $ti:00 $utc_offset</pubDate>
770 rss story     <link>$url/$yr/$mo_num/$da#$fn</link>
771 rss story     <category>$path</category>
772 rss story     <guid isPermaLink="false">$path/$fn</guid>
773 rss story     <description>$body</description>
774 rss story   </item>
775
776 rss date 
777
778 rss foot   </channel>
779 rss foot </rss>
780
781 error content_type text/html
782
783 error head <html>
784 error head <body>
785 error head     <p><font color="red">Error: I'm afraid this is the first I've heard of a "$flavour" flavoured Blosxom.  Try dropping the "/+$flavour" bit from the end of the URL.</font></p>
786
787
788 error story <p><b>$title</b><br />
789 error story $body <a href="$url/$yr/$mo_num/$da#fn.$default_flavour">#</a></p>
790
791 error date <h3>$dw, $da $mo $yr</h3>
792
793 error foot     </body>
794 error foot </html>
795 __END__
796