Replace atomfeed $feed_url with $path_info_full, for correct self links.
[blosxom-plugins.git] / barijaona / prevnextstory
blob5edc3f4e85ebc526429f5028fdbc0591fbe41589
1 # Blosxom Plugin: prevnexstory
2 # Author(s): Barijaona Ramaholimihaso
3 # Based on chrono_nav plugin by Victor Ganata <aswang@fatoprofugus.net>
4 # and tree plug-in by Ryan Schram 
5 # Ideas From: Tatsuhiko Miyagawa 
6 # Version: 2006-01-01blosxom2
7 # Documentation: See the bottom of this file or type: perldoc tree
9 package prevnextstory;
12 use strict; 
13 use vars qw($prevlink $nextlink $prevtitle $nexttitle $prevdate $nextdate @file_info @dir_info $files_ref @monthname @monthabbr);
14 # --- Configuration Variables ---
16 @monthname = qw/January February March 
17                 April   May      June 
18                 July    August   September 
19                 October November December/ if ($#monthname != 11);
20 @monthabbr = qw/Jan    Feb       Mar 
21                 Apr    May       Jun 
22                 Jul    Aug       Sep  
23                 Oct    Nov       Dec/ if ($#monthabbr != 11);
25 # -------------------------------------------------------------------
27 $prevlink;
28 $nextlink;
29 $prevtitle;
30 $nexttitle;
31 $prevdate;
32 $nextdate;
33 @file_info;
34 @dir_info;
36 sub start {
37     return 1;
40 sub skip { 
41     %$files_ref = %blosxom::files;
42     # Take %files and find all the places blosxom will generate a story page. 
43     @file_info = sort { $files_ref->{$b} <=> $files_ref->{$a} } keys %$files_ref;
44 0; 
49 sub head {
50     if (($blosxom::path_info =~ /$blosxom::flavour$/) or (($blosxom::path_info =~ /$blosxom::file_extension$/) && ($blosxom::static_or_dynamic eq "static"))) { 
51      # It's an individual story file.
52        my %path2idx = map { $file_info[$_] => $_ } 0..$#file_info;
54        my $key = "$blosxom::datadir/$blosxom::path_info";
55        $key =~ s#$blosxom::flavour#$blosxom::file_extension#;
56        my $index = $path2idx{"$key"};
57        if ($index < $#file_info ){ ($prevlink , $prevtitle, $prevdate) = make_link($index + 1) ;}
58                         else {undef $prevlink};
59        if ($index > 0 ){ ($nextlink , $nexttitle, $nextdate) = make_link($index - 1) ;}
60                         else {undef $nextlink;};
62     }
63     elsif (($blosxom::path_info eq "") && ($blosxom::path_info_yr eq "")) {
64      # it's the blog main page
65        if ($blosxom::num_entries <= $#file_info ){($prevlink, $prevtitle, $prevdate) = make_link($blosxom::num_entries) ;}
66                         else { undef $prevlink ;};
69     }
70     else
71     {undef $prevlink;
72     undef $nextlink;};
76 sub make_link {
77     my ($array_index) = @_;
78     my $file = $file_info[$array_index];
79     my($path, $fn) = $file =~ m!^$blosxom::datadir/(?:(.*)/)?(.*)\.$blosxom::file_extension!;
80         my $title='';
82     my $fh = FileHandle->new();
83     if (-f $file && $fh->open("< $file")) {
84         chomp($title = <$fh>);
85         $fh->close;
86         }
87         $path = $path . ( $path ne "" ? "/" : "") ;
88         my @date = localtime($files_ref->{$file_info[$array_index]});
89     my $mday  = $date[3];
90     my $month = $date[4];
91     my $year  = $date[5] + 1900;
92     
93     #here we format the date as a text
94         my $datetext = $mday." ".$monthname[$month]." ".$year ;
95         return (qq($blosxom::url/$path$fn.$blosxom::flavour), $title, $datetext);
104 __END__
106 =head1 NAME
108 Blosxom Plug-in: chrono_nav
110 =head1 SYNOPSIS
112 Populates the prevnexstory namespace with links for pointing to preceding 
113 and following stories (arranged chronologically). I suggest you use it with interpolate_fancy for testing whether $prevnextstory::prevlink and $prevnextstory::nextlink are defined to avoid spurious links to appear when there is no older or fresher story.
115 =head1 INSTALLATION
117 Drop this plugin into your plugin directory. Place substitution
118 variables $prevnextstory::prevlink and $prevnextstory::nextlink in your flavour file as an href value for an anchor element. You can also use $prevnextstory::prevtitle and $prevnextstory::nextlink to get the titles of those stories, and $prevnextstory::prevdate and $prevnextstory::nextdate to get their publication dates. If you need the dates, you will have to adapt the @monthname and @monthabbr lists to your needs, and in some cases modify the formatting performed by the make_list subroutine  (default date format is DD/MM/YYYY, with month names in French).
120 =head1 VERSION
122 2005-02-12blosxom2
124 Version number is the date on which this version of the plug-in was created.
126 =head2 CHANGES
128 2006-01-01blosxom2 : take into account the corrections of $path_info in recent versions of blosxom.cgi 
130 2004-08-22blosxom2 : First published version
132 =head1 AUTHOR(S)
134 Barijaona Ramaholimihaso
135 Based on chrono_nav plugin by Victor Ganata (<aswang@fatoprofugus.net>, http://blog.fatoprofugus.net )
136 which was itself based on tree plugin by Ryan Schram (http://www.rschram.org)
137 with inspiration and some code techniques used in prevnextentry from Tatsuhiko Miyagawa (http://www.bulknews.net) 
139 =head1 SEE ALSO
141 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net
143 Blosxom Plugin Docs: http://blosxom.sourceforge.net/plugins/
145 =head1 BUGS
147 None known; please send bug reports and feedback to the Blosxom development mailing list <blosxom-devel@lists.sourceforge.net>.
149 =head1 LICENSE
151 Copyright 2003-2007, Barijaona Ramaholimihaso
153 Blosxom and config Plug-in
154 Copyright 2003, Rael Dornfest 
156 Permission is hereby granted, free of charge, to any person obtaining a
157 copy of this software and associated documentation files (the "Software"),
158 to deal in the Software without restriction, including without limitation
159 the rights to use, copy, modify, merge, publish, distribute, sublicense,
160 and/or sell copies of the Software, and to permit persons to whom the
161 Software is furnished to do so, subject to the following conditions:
163 The above copyright notice and this permission notice shall be included
164 in all copies or substantial portions of the Software.
166 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
169 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
170 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
171 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
172 OTHER DEALINGS IN THE SOFTWARE.