3 Here's a patch to the calendar plugin. If you specify an event preprocessor in a post, such as:
5 [[event time="2008-06-24"]]
7 That date will be used instead of the post creation time when displaying the calendar.
9 > Thanks for coming up with a patch.. Let me make sure I understand its
12 > The meta plugin already allows modifying the page creation time,
13 > which is what the calendar plugin uses.
15 > So, it seems to me that the use of this patch is for recording events in
16 > the future. You'd not want a page for a future event to claim it was
17 > created in the future. I suppose you could also use it for events in the
18 > past, if you didn't want to change the creation time for some reason.
19 > (Perhaps you're doing a calendar of historical events, for example.)
21 > Accurate? --[[Joey]]
23 --- calendar.pm.orig 2008-06-24 22:36:09.000000000 -0400
24 +++ calendar.pm 2008-06-24 22:51:11.000000000 -0400
35 hook(type => "needsbuild", id => "version", call => \&needsbuild);
36 hook(type => "preprocess", id => "calendar", call => \&preprocess);
37 + hook(type => "preprocess", id => "event", call => \&preprocess_event);
40 sub is_leap_year (@) { #{{{
45 +sub preprocess_event (@) { #{{{
47 + # if now time is given, use now
48 + $params{time} = localtime unless defined $params{time};
50 + my $timestamp = str2time($params{time});
51 + if ( defined $timestamp) {
52 + $pagestate{$params{page}}{event}{mtime}=$timestamp;
54 + # remove the event block entirely
58 sub preprocess (@) { #{{{
60 $params{pages} = "*" unless defined $params{pages};
62 if (! defined $cache{$pagespec}) {
63 foreach my $p (keys %pagesources) {
64 next unless pagespec_match($p, $pagespec);
65 - my $mtime = $IkiWiki::pagectime{$p};
67 + # use time defined by event preprocessor if it's available
68 + if (defined $pagestate{$p}{event}{mtime}) {
69 + $mtime = $pagestate{$p}{event}{mtime};
71 + $mtime = $IkiWiki::pagectime{$p};
73 my $src = $pagesources{$p};
74 my @date = localtime($mtime);