Update flavourpathinfo to use Blosxom::Debug.
[blosxom-plugins.git] / general / entries_index
blob007c96e031be52e427439d315ebb864895b09037
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
6 package entries_index;
8 # --- Configurable variables -----
10 # --------------------------------
12 use File::stat;
13 use File::Find;
14 use Data::Dumper;
15 use CGI qw/:standard/;
17 sub start {
18   1;
21 sub entries {
22   return sub {
23     my(%files, %indexes);
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     }
31     my $reindex = 0;
32     for my $file (keys %files) { -f $file or do { $reindex++; delete $files{$file} }; }
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     );
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     }
74     return (\%files, \%indexes);
75   };
81 __END__
83 =head1 NAME
85 Blosxom Plug-in: entries_index
87 =head1 SYNOPSIS
89 Purpose: Preserves original creation timestamp on weblog entries, 
90 allowing for editing of entries without altering the original 
91 creation time.
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).
98 Replaces the default $blosxom::entries subroutine
100 =head1 VERSION
102 2003-03-23
104 Version number coincides with the version of Blosxom with which the 
105 current version was first bundled.
107 =head1 AUTHOR
109 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
111 This plugin is now maintained by the Blosxom Sourceforge Team,
112 <blosxom-devel@lists.sourceforge.net>.
114 =head1 SEE ALSO
116 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
118 Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html
120 =head1 BUGS
122 None known; please send bug reports and feedback to the Blosxom
123 development mailing list <blosxom-devel@lists.sourceforge.net>.
125 =head1 LICENSE
127 Blosxom and this Blosxom Plug-in
128 Copyright 2003, Rael Dornfest 
130 Permission is hereby granted, free of charge, to any person obtaining a
131 copy of this software and associated documentation files (the "Software"),
132 to deal in the Software without restriction, including without limitation
133 the rights to use, copy, modify, merge, publish, distribute, sublicense,
134 and/or sell copies of the Software, and to permit persons to whom the
135 Software is furnished to do so, subject to the following conditions:
137 The above copyright notice and this permission notice shall be included
138 in all copies or substantial portions of the Software.
140 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
141 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
142 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
143 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
144 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
145 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
146 OTHER DEALINGS IN THE SOFTWARE.