# Blosxom Plugin: back_and_forth # Author(s): Kyo Nagashima # Version: 1.2 # Blosxom Home/Docs/Licensing: http://www.blosxom.com/ # This plugin is altenate version of "prevnextentry" plugin. # "prevnextentry" plugin maybe found at: # http://bulknews.net/lib/archives/prevnextentry-0.1 package back_and_forth; use strict; use vars qw($main $prev $next $link_main $link_prev $link_next); # --- Configurable variables ----------- # --- Plug-in package variables -------- my @file_info; # -------------------------------------- use FileHandle; sub start { return 0 unless $blosxom::path_info =~ /\./; return 1; } sub filter { my ($pkg, $files_ref) = @_; @file_info = sort {$files_ref->{$b} <=> $files_ref->{$a}} keys %$files_ref; return 1; } sub head { my($pkg, $path, $head_ref) = @_; $path =~ s/\.$blosxom::flavour/\.$blosxom::file_extension/; my %path2idx = map {$file_info[$_] => $_} 0..$#file_info; my $index = $path2idx{"$blosxom::datadir/$path"}; if ($index < $#file_info) { my($prev_url, $prev_title) = &getinfo($index + 1, \@file_info); $link_prev = qq!!; $prev = &$blosxom::template($path, 'back_and_forth_prev', $blosxom::flavour) || '

« $back_and_forth::prev_title

'; $prev =~ s/\$back_and_forth::prev_url/$prev_url/ge; $prev =~ s/\$back_and_forth::prev_title/$prev_title/ge; } if ($index > 0) { my($next_url, $next_title) = &getinfo($index - 1, \@file_info); $link_next = qq!!; $next = &$blosxom::template($path, 'back_and_forth_next', $blosxom::flavour) || '

$back_and_forth::next_title »

'; $next =~ s/\$back_and_forth::next_url/$next_url/ge; $next =~ s/\$back_and_forth::next_title/$next_title/ge; } $main = &$blosxom::template($path, 'back_and_forth_main', $blosxom::flavour) || 'Main'; $main =~ s/\$blosxom::url/$blosxom::url/ge; $link_main = qq!!; return 1; } sub getinfo { my($ai, $pi) = @_; my $file = $pi->[$ai]; my($path, $fn) = $file =~ m!^$blosxom::datadir/(?:(.*)/)?(.*)\.$blosxom::file_extension!; my $url = "$blosxom::url/$path/$fn.$blosxom::flavour"; my $fh = new FileHandle; my $title = ''; if (-f $file && $fh->open("< $file")) { chomp($title = <$fh>); $fh->close; } return($url, $title); } 1;