dragoness_e: (Default)
Dragoness Eclectic ([personal profile] dragoness_e) wrote2005-03-01 09:51 am

blosxom plugin: future_dayz

Future_dayz displays entries from the most-recent $past_days to the present, to the next $future_days, instead of the normal $num_entries posts. (However, $num_entries still sets the limit on how many posts from the most-recent $num_days days will be displayed.)  'start time' ($origin) is always Right Now; this plug-in was designed so I could run a calendar of future events using blosxom.
# Blosxom Plugin: future_dayz
# Author:Cynthia Higginbotham <mailto:dragoness77@republicofnewhome.org>
#   (based on Stu Mackenzie's num_dayz plugin)
# Version: v0.1
# License: GPL2
# future_dayz home: My hard drive
# 
# Documentation at the bottom of this file or type: perldoc future_dayz

# Blosxom normally displays the most recent $num_entries posts (5, 10,
# 100); future_dayz displays posts from the more recent $past_days
# posts, and on into $future_days into the future.The maximum number of
# posts that will be displayed is still set by $num_entries.

# 'start time' ($origin) is always Right Now; this plug-in was
# designed so I could run a calendar of future events using
# blosxom. It will detect whether the entries are sorted ascending or
# descending by date, and filter accordingly.

package future_dayz;

# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
#
#  Configuration Section
#
# = = = = = = = = = = = = = = = =
#
# Use this plugin?
$future_dayz_on = 0
    unless defined $future_dayz_on;

# How many days' posts should be displayed?
$past_days = 2;
  
$future_days = 365;


# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

use vars qw($future_dayz_on $past_days $future_days);

use strict;

sub start {
  1;
}

sub filter {
  $future_dayz_on or return 0;               # only run when requested

  my($pkg, $files_ref) = @_;

  my ($origin, $future_secs, $past_secs, $leftover_secs, $SECS_PER_DAY);
  my ($earliest_valid_mtime, $latest_valid_mtime);

  $SECS_PER_DAY = (60 * 60 * 24);

  # $num_secs = $num_days in seconds
  $future_secs = $future_days * $SECS_PER_DAY;
  $past_secs = $past_days * $SECS_PER_DAY;
  $origin = time();
  $leftover_secs = $origin % $SECS_PER_DAY;

  # How many seconds ago/ahead is cut-off time from beginning of today?
  $earliest_valid_mtime = $origin - ($past_secs + $leftover_secs);
  $latest_valid_mtime = $origin + ($future_secs - $leftover_secs);

  foreach my $key ( keys %$files_ref ) {
      (($$files_ref{$key} > $earliest_valid_mtime) and
       ($$files_ref{$key} < $latest_valid_mtime))  
	  or delete $$files_ref{$key};

  }

  1;
}


1;

__END__


=head1 NAME

Blosxom Plug-in: future_dayz


=head1 SYNOPSIS

* Entries from the most-recent $past_days to the present, to the next
  $future_days are displayed, instead of the normal $num_entries
  posts. (However, $num_entries still sets the limit on how many posts
  from the most-recent $num_days days will be displayed.)

* can be turned off/on on a per-config file basis.

=head1 INSTALLATION

Locate the future_dayz plugin you downloaded; open the file and enter 
the three CONFIGURATION values; save the file with unix line ends. 
Upload or drop the future_dayz file into your blosxom plugins folder. 
Blog on.


=head1 CONFIGURATION

With any luck, the instructions in the "Configuration Section" 
at the top of this file are sufficient;

=head1 USAGE NOTES

=head1 BUGS


=head1 VERSION

2005-02-28 (v0.1): Made it live

=head1 LICENSE

this Blosxom Plug-in
Copyright 2005, Cynthia Higginbotham

See the Gnu Public License, 2.0