Add a bunch of Rael plugins.
[matthijs/upstream/blosxom-plugins.git] / general / entries_index
1 # Blosxom Plugin: entries_index
2 # Author(s): Rael Dornfest <rael@oreilly.com> 
3 # Version: 2003-03-23
4 # Documentation: See the bottom of this file or type: perldoc entries_index
5
6 package entries_index;
7
8 # --- Configurable variables -----
9
10 # --------------------------------
11
12 use File::stat;
13 use File::Find;
14 use Data::Dumper;
15 use CGI qw/:standard/;
16
17 sub start {
18   1;
19 }
20
21 sub entries {
22   return sub {
23     my(%files, %indexes);
24
25     if ( open ENTRIES, "$blosxom::plugin_state_dir/.entries_index.index" ) {
26       my $index = join '', <ENTRIES>;
27       close ENTRIES;
28       $index =~ /\$VAR1 = \{/ and eval($index) and !$@ and %files = %$VAR1;
29     }
30
31     my $reindex = 0;
32     for my $file (keys %files) { -f $file or do { $reindex++; delete $files{$file} }; }
33
34     find(
35       sub {
36         my $d; 
37         my $curr_depth = $File::Find::dir =~ tr[/][]; 
38         if ( $blosxom::depth and $curr_depth > $blosxom::depth ) {
39           $files{$File::Find::name} and delete $files{$File::Find::name};
40           return;
41         }
42      
43         $File::Find::name =~ m!^$blosxom::datadir/(?:(.*)/)?(.+)\.$blosxom::file_extension$!
44           and $2 ne 'index' and $2 !~ /^\./ and (-r $File::Find::name)
45             # to show or not to show future entries
46             and (
47               $blosxom::show_future_entries
48               or stat($File::Find::name)->mtime <= time
49             ) 
50               and ( $files{$File::Find::name} || ++$reindex )
51                 and ( $files{$File::Find::name} = $files{$File::Find::name} || stat($File::Find::name)->mtime )
52                   # Static
53                   and (
54                     param('-all') 
55                     or !-f "$blosxom::static_dir/$1/index." . $blosxom::static_flavours[0]
56                     or stat("$blosxom::static_dir/$1/index." . $blosxom::static_flavours[0])->mtime < stat($File::Find::name)->mtime
57                   )
58                     and $indexes{$1} = 1
59                       and $d = join('/', (blosxom::nice_date($files{$File::Find::name}))[5,2,3])
60                         and $indexes{$d} = $d
61                           and $blosxom::static_entries and $indexes{ ($1 ? "$1/" : '') . "$2.$blosxom::file_extension" } = 1;
62       }, $blosxom::datadir
63     );
64
65     if ( $reindex ) {
66       if ( open ENTRIES, "> $blosxom::plugin_state_dir/.entries_index.index" ) {
67         print ENTRIES Dumper \%files;
68         close ENTRIES;
69       } else {
70         warn "couldn't > $blosxom::plugin_state_dir/.entries_index.index: $!\n";
71       }
72     }
73
74     return (\%files, \%indexes);
75   };
76
77 }
78
79 1;
80
81 __END__
82
83 =head1 NAME
84
85 Blosxom Plug-in: entries_index
86
87 =head1 SYNOPSIS
88
89 Purpose: Preserves original creation timestamp on weblog entries, 
90 allowing for editing of entries without altering the original 
91 creation time.
92
93 Maintains an index ($blosxom::plugin_state_dir/.entries_index.index) of 
94 filenames and their creation times.  Adds new entries to the index 
95 the first time Blosxom encounters them (read: is run after their 
96 creation).
97
98 Replaces the default $blosxom::entries subroutine
99
100 =head1 VERSION
101
102 2003-03-23
103
104 Version number coincides with the version of Blosxom with which the 
105 current version was first bundled.
106
107 =head1 AUTHOR
108
109 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
110
111 =head1 SEE ALSO
112
113 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
114
115 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
116
117 =head1 BUGS
118
119 Address bug reports and comments to the Blosxom mailing list 
120 [http://www.yahoogroups.com/group/blosxom].
121
122 =head1 LICENSE
123
124 Blosxom and this Blosxom Plug-in
125 Copyright 2003, Rael Dornfest 
126
127 Permission is hereby granted, free of charge, to any person obtaining a
128 copy of this software and associated documentation files (the "Software"),
129 to deal in the Software without restriction, including without limitation
130 the rights to use, copy, modify, merge, publish, distribute, sublicense,
131 and/or sell copies of the Software, and to permit persons to whom the
132 Software is furnished to do so, subject to the following conditions:
133
134 The above copyright notice and this permission notice shall be included
135 in all copies or substantial portions of the Software.
136
137 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
138 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
139 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
140 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
141 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
142 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
143 OTHER DEALINGS IN THE SOFTWARE.