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