tagging: Allow using titles in for related stories.
[matthijs/upstream/blosxom-plugins.git] / general / recententries
1 # Blosxom Plugin: Recent Entries
2 # Author(s): Gregory Bair - http://mypage.iu.edu/~gbair/
3 #            Gavin Carr - http://www.openfusion.net/
4 # Version: 0.4
5 # Blosxom Home: http://blosxom.sourceforge.net/
6 # Use: insert $recententries::recententries in one of the flavour templates.
7
8 package recententries;
9
10 use strict;
11 use File::Spec;
12
13 #-------------- Configurable Options ----------------
14
15 # How many titles do you want to show? 
16 my $title_num = 20;
17
18 # What comes before each title? below adds a line between each title - good for long titles.
19 my $title_before = qq!<div style="border-bottom:1px solid #369;">!;
20
21 # What comes after?
22 my $title_after = qq!</div>!;
23
24 #----------------------------------------------------
25
26 use vars qw($recententries);
27
28 sub start { 1 }
29
30 sub filter{
31         my ($pkg, $files_ref) = @_;
32         my $tn = 1;
33
34         # Put each file name (the key of %$files_ref) into an array, but sort 
35     # them by modification time (value) first
36         my @files = sort { $$files_ref{$b} <=> $$files_ref{$a} } keys %$files_ref;
37
38         foreach my $file (@files)
39         {
40         last if $tn >= $title_num;
41
42         open (STORY, $file) || die "Cannot open file $file : $!";
43         my @story = <STORY>;
44         close STORY;
45         
46         # The title is always the first line in an entry.  Get that.
47         my $storytitle = $story[0];
48         chomp $storytitle;
49
50         my $link = '';
51
52         # Use permalink if it's available
53         if (defined $permalink::root_format) {
54             my $rel_file = $file;
55             $rel_file =~ s/^$blosxom::datadir//;
56             $rel_file =~ s/\.$blosxom::file_extension$//;
57             $link = permalink::get_link( $rel_file );
58         }
59     
60         if (! $link) {
61             my ($volume, $directory, $filename) = File::Spec->splitpath($file);
62             $filename =~ s/\.$blosxom::file_extension$//;
63         
64             #Change the file into a URL we can use.
65             my $newvol = File::Spec->catfile($volume, $directory, '');
66             $newvol =~ s/$blosxom::datadir/$blosxom::url/g;
67
68             $link = "$newvol#$filename";
69         }
70         
71         # Create our variable.
72         $recententries .= sprintf qq(%s<a href="%s">%s</a>%s\n), 
73             $title_before, $link, $storytitle, $title_after;
74         
75         # Increment $tn.
76         $tn++;
77         }
78                 
79         #test(%files);
80         1;
81 }
82
83 1;
84
85 __END__
86
87 =head1 NAME
88
89 Blosxom Plugin: recententries
90
91 =head1 SYNOPSIS
92
93 Purpose: Populates $recententries::recententries with a list of the most 
94 recent entries. The number is specified by a configuration variable.
95
96 =head1 AUTHORS
97
98 Gregory Bair gregindy@softhome.net, http://mypage.iu.edu/~gbair/
99 Gavin Carr   gavin@openfusion.net,  http://www.openfusion.net/
100
101 =head1 Changelog
102
103 0.2 used qq!! instead of "" in configs
104
105 0.3 simplified the sorting algorithm at the suggestion of Todd Larason.
106
107 0.4 fixed File::Spec problems on OSes without volumes, and added L<permalink> support.
108
109 =cut
110