3 Here's my next version of the patch - still a work in progress.
5 It provides the following new features. The features are designed to preserve the behavior of the existing plugin by default.
7 * If you specify an event preprocessor in a post, such as:
9 [[!event time="2008-06-24"]]
11 That date will be used instead of the post creation time when displaying the calendar.
13 * When specifying a calendar preprocessor, you can now add the following new parameters:
15 * time_src: by default it is set to auto. auto means that when determining the date to use for a given post, take the date given in the event preprocessor directive if it exists and if not, use the creation time of the post. The other option is event which means: take the date given in the event preprocessor directive. If there is not event preprocessor in a post, don't include the post.
16 * detail: by default it is set to 0. If set to 0, display the monthly calendar as a series of days. Each day is a link to the post on that day. If there is more than one post on a day, only one is linked to. If set to 1 - then display the title of each post on the day as a link to the post. Is 0 and 1 the best values here? On/Off? Yes/no?
18 The following changes are in the works:
20 * Switch to using HTML::CalendarMonth to create the html output
22 * Display the start time when detail is set to 1.
26 * Support recurring events
28 * Support for end time on events (including end time that is on a different day than the start time)
30 * Convincing the world to switch to base 10 calendar system.
33 --- calendar.pm.orig 2008-06-24 22:36:09.000000000 -0400
34 +++ calendar.pm 2008-06-28 22:02:15.000000000 -0400
46 hook(type => "needsbuild", id => "version", call => \&needsbuild);
47 hook(type => "preprocess", id => "calendar", call => \&preprocess);
48 + hook(type => "preprocess", id => "event", call => \&preprocess_event);
51 sub is_leap_year (@) {
53 my $nmonth = $params{nmonth};
54 my $pyear = $params{pyear};
55 my $nyear = $params{nyear};
56 + my $detail = $params{detail};
65 my $mtag = sprintf("%02d", $month);
66 - if (defined $cache{$pagespec}{"$year/$mtag/$day"}) {
67 - if ($day == $today) {
68 + if ($day == $today) {
69 $tag='month-calendar-day-this-day';
72 - $tag='month-calendar-day-link';
74 - $calendar.=qq{\t\t<td class="$tag $downame{$wday}">};
75 - $calendar.=htmllink($params{page}, $params{destpage},
76 - pagename($linkcache{"$year/$mtag/$day"}),
77 - "linktext" => "$day");
78 - push @list, pagename($linkcache{"$year/$mtag/$day"});
79 - $calendar.=qq{</td>\n};
81 + elsif ($day >= $future_dom) {
82 + $tag='month-calendar-day-future';
84 + elsif($params{detail} == 0 &&
85 + !defined $cache{$pagespec}{"$year/$mtag/$day"}) {
86 + $tag='month-calendar-day-nolink';
88 + elsif($params{detail} == 0 &&
89 + defined $cache{$pagespec}{"$year/$mtag/$day"}) {
90 + $tag='month-calendar-day-link';
93 - if ($day == $today) {
94 - $tag='month-calendar-day-this-day';
96 - elsif ($day == $future_dom) {
97 - $tag='month-calendar-day-future';
98 + $tag='month-calendar-day';
101 + $calendar.=qq{\t\t<td class="$tag $downame{$wday}">};
102 + my $day_label = qq{<span class="month-calendar-day-label">$day</span>};
103 + if (defined $cache{$pagespec}{"$year/$mtag/$day"}) {
104 + my $srcpage; my $destpage;
105 + if($params{detail} == 0) {
106 + # pull off the first page
107 + (($srcpage,$destpage) = each(%{$linkcache{"$year/$mtag/$day"}}));
108 + $calendar.=htmllink($params{page}, $params{destpage},
109 + pagename($destpage),
110 + "linktext" => "$day_label");
111 + push @list, pagename($linkcache{"$year/$mtag/$day"});
114 - $tag='month-calendar-day-nolink';
115 + $calendar.=qq{$day_label\n};
116 + while(($srcpage,$destpage) = each(%{$linkcache{"$year/$mtag/$day"}})) {
117 + my $title = IkiWiki::basename(pagename($srcpage));
118 + if (exists $pagestate{$srcpage}{meta}{title} ) {
119 + $title = $pagestate{$srcpage}{meta}{title};
121 + $calendar.=qq{\t\t<div class="$tag $downame{$wday}">};
122 + $calendar.=htmllink($params{page}, $params{destpage},
123 + pagename($destpage),
124 + "linktext" => $title);
125 + push @list, pagename($linkcache{"$year/$mtag/$day"}{"$srcpage"});
126 + $calendar.=qq{\t\t</div>};
129 - $calendar.=qq{\t\t<td class="$tag $downame{$wday}">$day</td>\n};
132 + $calendar.=qq{$day_label\n};
134 + $calendar.=qq{</td>\n};
137 # finish off the week
142 +sub preprocess_event (@) {
144 + # if now time is given, use now
145 + $params{begin} = localtime($time) unless defined $params{begin};
147 + my $timestamp = str2time($params{begin});
148 + if ( defined $timestamp) {
149 + $pagestate{$params{page}}{event}{begin}=$timestamp;
151 + return "<!-- $params{begin} -->";
156 $params{pages} = "*" unless defined $params{pages};
158 $params{month} = sprintf("%02d", $params{month}) if defined $params{month};
159 $params{week_start_day} = 0 unless defined $params{week_start_day};
160 $params{months_per_row} = 3 unless defined $params{months_per_row};
161 + $params{time_src} = 'auto' unless defined $params{time_src};
162 + $params{detail} = 0 unless defined $params{detail};
164 if (! defined $params{year} || ! defined $params{month}) {
165 # Record that the calendar next changes at midnight.
166 @@ -355,19 +398,29 @@
167 if (! defined $cache{$pagespec}) {
168 foreach my $p (keys %pagesources) {
169 next unless pagespec_match($p, $pagespec);
170 - my $mtime = $IkiWiki::pagectime{$p};
171 - my $src = $pagesources{$p};
172 - my @date = localtime($mtime);
173 - my $mday = $date[3];
174 - my $month = $date[4] + 1;
175 - my $year = $date[5] + 1900;
176 - my $mtag = sprintf("%02d", $month);
178 - # Only one posting per day is being linked to.
179 - $linkcache{"$year/$mtag/$mday"} = "$src";
180 - $cache{$pagespec}{"$year"}++;
181 - $cache{$pagespec}{"$year/$mtag"}++;
182 - $cache{$pagespec}{"$year/$mtag/$mday"}++;
184 + # use time defined by event preprocessor if it's available
185 + if (defined $pagestate{$p}{event}{begin}) {
186 + $begin = $pagestate{$p}{event}{begin};
187 + # fall back on ctime if time_src is set to auto
188 + # set time_src to 'event' to skip posts that don't
189 + # have the event preprocessor
190 + } elsif ($params{time_src} eq 'auto') {
191 + $begin = $IkiWiki::pagectime{$p};
194 + my $dest = $pagesources{$p};
195 + my @date = localtime($begin);
196 + my $mday = $date[3];
197 + my $month = $date[4] + 1;
198 + my $year = $date[5] + 1900;
199 + my $mtag = sprintf("%02d", $month);
201 + $linkcache{"$year/$mtag/$mday"}{$p} = "$dest";
202 + $cache{$pagespec}{"$year"}++;
203 + $cache{$pagespec}{"$year/$mtag"}++;
204 + $cache{$pagespec}{"$year/$mtag/$mday"}++;