#!/usr/bin/perl -w # Blosxom Plugin: calendar # Author: Todd Larason (jtl@molehill.org) with features by Ben Guaraldi (benj@bluesock.org) # Version: 0+1i # Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom # Categories plugin Home/Docs/Licensing: # http://molelog.molehill.org/blox/Computers/Internet/Web/Blosxom/Calendar/ package calendar; # --- Configuration Variables --- # output format # 'table' -> simple table; simplest, suitable for most people my $output_format = 'table'; # names in your preferred language my @monthname = qw/January February March April May June July August September October November December/; my @weekdayname = qw/Sun Mon Tue Wed Thu Fri Sat/; # Do you want < and >'s that point to the next and previous # month? If so, leave $nav = 1. Else, put $nav = 0. $nav = 1; # Put the date that you want your calendar to start at. # (e.g,, Mine starts at 9/1/04, so when you're in September, # you can't go backwards any more months.) $calstartdate = "20040901"; (undef, undef, undef, $dd, $mm, $yyyy) = localtime(time); $calenddate = sprintf("%04d%02d%02d", $yyyy+1900, $mm+1, $dd); # The end date is set to the present date. If you want to have the # calendar go into the future, then uncomment this line and enter the # desired date: # $calenddate = "20100901"; # --- End of Configuration Section --- use Time::Local; $calendar = ''; my %days; sub report_month_start { my ($year, $month, $monthname) = @_; my $results = ''; local $_; my $prevday, $nextday, $prevmonth, $nextmonth, $prevyear, $nextyear, $tempmonth; $prevyear = $nextyear = $year; $prevmonth = $month - 1; $nextmonth = $month + 1; if ($month == 1) { $prevmonth = 12; $prevyear = $year - 1; } elsif ($month == 12) { $nextmonth = 1; $nextyear = $year + 1; } $prevday = days_in_month($prevyear, $prevmonth); $nextday = "01"; $prevmonth = prependzero($prevmonth); $nextmonth = prependzero($nextmonth); $tempmonth = prependzero($month); if ($output_format eq 'table') { $results = qq!!; if ($nav) { if ("$prevyear$prevmonth" . "32" > $calstartdate) { $results .= qq!\n!; } else { $results .= qq!\n!; } } $results .= qq!\n!; if ($nav) { if ("$nextyear$nextmonth" . "01" <= $calenddate) { $results .= qq!\n!; } else { $results .= qq!\n!; } } $results .= qq!\n\n!; $results .= qq!\n! foreach (@weekdayname); $results .= qq!\n!; } else { warn "Unsupported output_format: $output_format"; } return $results; } sub report_week_start { return qq!\n! if ($output_format eq 'table'); return qq!!; } sub report_day_noday { return qq!\n! if ($output_format eq 'table'); return qq!!; } sub report_day_link { my ($year, $month, $day) = @_; my $zday, $zmonth; $zmonth = prependzero($month); $zday = prependzero($day); return qq!\n! if ($output_format eq 'table'); return qq!!; } sub report_day_nolink { my ($year, $month, $day) = @_; return qq!\n! if ($output_format eq 'table'); return qq!!; } sub report_week_end { return qq!\n! if ($output_format eq 'table'); return qq!!; } sub report_month_end { return qq!
! . qq!$monthname $year
$_
 
\n! if ($output_format eq 'table'); return qq!!; } sub days_in_month { my ($year, $month) = @_; my $days = (31,28,31,30,31,30,31,31,30,31,30,31)[$month-1]; if ($month == 2 && ($year % 4 == 0 && (($year % 100 != 0) || ($year % 400 == 0)))) { $days++; } return $days; } sub build_calendar { my $results; my ($now, @now, $monthstart, @monthstart); my ($year, $month, $day, $days, $wday, $today); $now = time; @now = localtime($now); $year = $blosxom::path_info_yr ? $blosxom::path_info_yr : $now[5] + 1900; $month = $blosxom::path_info_mo ? $blosxom::path_info_mo + 0 : $now[4] + 1; $today = $blosxom::path_info_da ? $blosxom::path_info_da + 0 : $now[3]; $days = days_in_month($year, $month); # XXX this isn't quite right in the face of daylight savings time # $monthstart = $now - ($now[3]-1)*86400; $monthstart = timelocal(0,0,0,1,$month-1,$year-1900); @monthstart = localtime($monthstart); $results = report_month_start($year, $month, $monthname[$month-1]); # First, skip over the first partial week (possibly empty) # before the month started for ($wday = 0; $wday < $monthstart[6]; $wday++) { $results .= report_week_start() if ($wday == 0); $results .= report_day_noday(); } # now do the month itself for ($day = 1; $day <= $days; $day++) { $results .= report_week_start() if ($wday == 0); if ($days{"$year/$month/$day"}) { $results .= report_day_link($year, $month, $day); } else { $results .= report_day_nolink($year, $month, $day); } if (++$wday == 7) { $wday = 0; $results .= report_week_end(); } } # and finish up the last week, if any left if ($wday) { while (++$wday <= 7) { $results .= report_day_noday(); } $results .= report_week_end(); } $results .= report_month_end(); return $results; } sub start { return 1; } sub filter { my ($pkg, $files) = @_; foreach (keys %{$files}) { my @date = localtime($files->{$_}); my $mday = $date[3]; my $month = $date[4] + 1; my $year = $date[5] + 1900; $days{"$year"}++; $days{"$year/$month"}++; $days{"$year/$month/$mday"}++; } $calendar = build_calendar(); } sub prependzero { my $num = $_[0]; if (length($num) == 1) { return "0$num"; } return $num; } 1;