# vim: ft=perl # Blosxom Plugin: previous_next # Author(s): Jason Thaxter # Version: 1.0 # Documentation: See the bottom of this file or type: perldoc previous_next package previous_next; # --- Configurable variables ----- # enabled: use or no (for config plugin, etc) # default: yes $enabled; # sprintf format for the "previous" link # default: previous $previous_tmpl; # sprintf format for the "next" link # default: next $next_tmpl; # sprintf format for the "previous/next" link # default: %s::%s $previous_next_tmpl; # -------------------------------- $enabled = 1 unless defined $enabled; $previous_tmpl ||= 'previous'; $next_tmpl ||= 'next'; $previous_next_tmpl = "%s::%s"; # here's what the variables for template use use vars qw( $next $previous $previous_next ); $next; # use as $previous_next::next in story.flavour templates $previous; # use as $previous_next::previous in story.flavour templates $previous_next; # use as $previous_next::previous_next in story.flavour templates use CGI qw(:standard); sub start { return $enabled; } sub story { my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; # only operate when showing an individual story return unless path_info() =~ m/$path\/$filename/; # and make it a real one my $story_entry = "$blosxom::datadir$path/$filename.$blosxom::file_extension"; next unless -f $story_entry; my $story_mtime = $blosxom::files{$story_entry}; # find the previous and next entries in %blosxom::files my ( $previous_entry, $next_entry ); foreach my $entry ( sort keys %blosxom::files ) { # *this* story is not "previous" or next" next if $entry eq $story_entry; my $mtime = $blosxom::files{$entry}; # set previous and next if ( $story_mtime > $mtime and ( $mtime > $blosxom::files{$previous_entry} or not $previous_entry ) ) { $previous_entry = $entry; } elsif ( $story_mtime < $mtime and ( $mtime < $blosxom::files{$next_entry} or not $next_entry ) ) { $next_entry = $entry; } } # # Make links for substitution # if ($previous_entry){ $previous_href = $previous_entry; $previous_href =~ s/$blosxom::file_extension$/$blosxom::flavour/; $previous_href =~ s/^$blosxom::datadir/$blosxom::url/; $previous = sprintf($previous_tmpl,$previous_href); } if ($next_entry){ $next_href = $next_entry; $next_href =~ s/$blosxom::file_extension$/$blosxom::flavour/; $next_href =~ s/^$blosxom::datadir/$blosxom::url/; $next = sprintf($next_tmpl,$next_href); } $previous_next = sprintf($previous_next_tmpl,$previous,$next); } 1; __END__ =head1 NAME Blosxom Plug-in: previous_next =head1 SYNOPSIS This is intended for use in story templates. It should work in C as well. When showing aggregate entries - by date or by category - this will do nothing. When showing individual stories, it has a purpose. Populates some template variables with previous and next links for the previous and next story. C<$previous_next::previous> links to the previous story, C<$previous_next::next> links to the next story, and C<$previous_next::previous_next> links to both. When files have the same nodifi same modification time, it goes alphabetically. =head1 VERSION Version 1.0 =head1 AUTHOR Jason Thaxter , http://ahab.com/ =head1 SEE ALSO Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/ Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml =head1 BUGS Address bug reports and comments to the Blosxom mailing list [http://www.yahoogroups.com/group/blosxom] or to the author. =head1 LICENSE This Blosxom Plug-in Copyright 2004, Jason Thaxter Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.