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