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