# Blosxom Plugin: entries_timestamp
# Author(s): Gavin Carr <gavin@openfusion.com.au>
-# Version: 0.001000
+# Version: 0.002000
# Documentation: See the bottom of this file or type: perldoc entries_timestamp
package entries_timestamp;
use Time::Local;
use CGI ();
-#use Blosxom::Debug debug_level => 1;
+# Uncomment next line to enable debug output (don't uncomment debug() lines)
+#use Blosxom::Debug debug_level => 2;
# --- Configurable variables -----
+my %config = ();
+
# Where should I store the entries_timestamp index file?
# IMO timestamps are metadata rather than state, but you may well not care.
-my $meta_dir = "$blosxom::datadir/../meta";
-#my $meta_dir = $blosxom::plugin_state_dir;
+$config{meta_dir} = "$blosxom::datadir/../meta";
+#$config{meta_dir} = $blosxom::plugin_state_dir;
# What name should my entries_timestamp index file be called?
# If you want to migrate from entries_index, you can just use the original
# entries_index .entries_index.index file, or or just copy/rename it.
-my $entries_index = 'entries_timestamp.index';
-#my $entries_index = '.entries_index.index';
+$config{entries_index} = 'entries_timestamp.index';
+#$config{entries_index} = '.entries_index.index';
# Reindexing password. If entries_timestamp finds a '?reindex=$reindex_password'
# parameter it will check and resync machine timestamps to the human versions
-my $reindex_password = 'abracad'; # CHANGEME!
+$config{reindex_password} = 'abracad'; # CHANGEME!
# --------------------------------
+# __END_CONFIG__
my $q = CGI->new;
-use vars qw($VAR1 $VAR2 $VAR3);
+use vars qw($TS_MACHINE $TS_HUMAN $SYMLINKS $VAR1 $VAR2 $VAR3);
sub start { 1 }
return sub {
my(%indexes, %files_ts, %files_ts_str, %files_symlinks);
- # Read $entries_index
- if ( open ENTRIES, "$meta_dir/$entries_index" ) {
+ # Read $config{entries_index}
+ if ( open ENTRIES, "$config{meta_dir}/$config{entries_index}" ) {
my $index = join '', <ENTRIES>;
close ENTRIES;
- if ( $index =~ m/\$VAR1 = \{/ ) {
+ if ( $index =~ m/\$(TS_\w+|VAR1) = \{/ ) {
eval $index;
if ( $@ ) {
- warn "(entries_timestamp) eval of $entries_index failed: $@";
+ warn "(entries_timestamp) eval of $config{entries_index} failed: $@";
return;
}
else {
- %files_ts = %$VAR1;
- %files_ts_str = %$VAR2 if keys %$VAR2;
- %files_symlinks = %$VAR3 if keys %$VAR3;
+ if ($TS_MACHINE && keys %$TS_MACHINE) {
+ %files_ts = %$TS_MACHINE;
+ } elsif ($VAR1 && keys %$VAR1) {
+ %files_ts = %$VAR1;
+ }
+ if ($TS_HUMAN && keys %$TS_HUMAN) {
+ %files_ts_str = %$TS_HUMAN;
+ } elsif ($VAR2 && keys %$VAR2) {
+ %files_ts_str = %$VAR2;
+ }
+ if ($SYMLINKS && keys %$SYMLINKS) {
+ %files_symlinks = %$SYMLINKS;
+ } elsif ($VAR3 && keys %$VAR3) {
+ %files_symlinks = %$VAR3;
+ }
}
}
}
# If asked to reindex, check and sync machine timestamps to the human ones
if ( my $reindex = $q->param('reindex') ) {
- if ( $reindex eq $reindex_password ) {
+ if ( $reindex eq $config{reindex_password} ) {
if ( my $reindex_ts = parse_ts( $files_ts_str{$File::Find::name} )) {
if ($reindex_ts != $files_ts{$File::Find::name}) {
# debug(1, "reindex: updating timestamp on '$File::Find::name'\n");
# If updates, save back to index
if ( $index_mods ) {
- # debug(1, "index_mods $index_mods, saving \%files to $meta_dir/$entries_index");
- if ( open ENTRIES, "> $meta_dir/$entries_index" ) {
- print ENTRIES Dumper \%files_ts, \%files_ts_str, \%files_symlinks;
+ # debug(1, "index_mods $index_mods, saving \%files to $config{meta_dir}/$config{entries_index}");
+ if ( open ENTRIES, "> $config{meta_dir}/$config{entries_index}" ) {
+ print ENTRIES Data::Dumper->Dump([ \%files_ts_str, \%files_ts, \%files_symlinks ],
+ [ qw(TS_HUMAN TS_MACHINE SYMLINKS) ] );
close ENTRIES;
}
else {
- warn "(entries_timestamp) couldn't open $meta_dir/$entries_index for writing: $!\n";
+ warn "(entries_timestamp) couldn't open $config{meta_dir}/$config{entries_index} for writing: $!\n";
}
}