# Blosxom Plugin: back_and_forth # Author(s): Kyo Nagashima # Version: 2009-05-22 # 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($next $prev $link_next $link_prev); # --- Configurable variables ----------- # Do you want to output as XHTML? my $as_xhtml = 0; # --- Plug-in package variables -------- my $xhtml = $as_xhtml ? ' /' : ''; my @file_info; # -------------------------------------- use FileHandle; my $fh = new FileHandle; sub start { return 0 unless $blosxom::path_info =~ /\.$blosxom::flavour$/; 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($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; } if ($index > 0) { 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; } return 1; } sub getinfo { my($index, $file_info) = @_; my $file = $file_info->[$index]; my($path, $fn) = $file =~ m!^$blosxom::datadir/(?:(.*)/)?(.*)\.$blosxom::file_extension!; my $url = "/blog/$path/$fn.$blosxom::flavour"; my $title = ''; if (-f $file and $fh->open($file)) { chomp($title = <$fh>); $fh->close; } return($url, $title); } 1;