add test case for RSS url munging
[ikiwiki.git] / doc / todo / Set_arbitrary_date_to_be_used_by_calendar_plugin.mdwn
blob4bc828e6ee703e1cfc3c933ea72610e91f757210
1 [[!tag patch plugins/calendar]]
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. 
24 Longer term plans:
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
35                 @@ -23,6 +23,8 @@
36                  use IkiWiki 2.00;
37                  use Time::Local;
38                  use POSIX;
39                 +use Date::Parse;
40                 +use Data::Dumper;
41                  
42                  my %cache;
43                  my %linkcache;
44                 @@ -32,6 +34,7 @@
45                  sub import {
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);
49                  }
50                  
51                  sub is_leap_year (@) {
52                 @@ -58,6 +61,7 @@
53                         my $nmonth   = $params{nmonth};
54                         my $pyear    = $params{pyear};
55                         my $nyear    = $params{nyear};
56                 +       my $detail   = $params{detail};
57                  
58                         my @list;
59                         my $calendar="\n";
60                 @@ -153,33 +157,58 @@
61                                 }
62                                 
63                                 my $tag;
64                 +               my $display_day;
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';
70                 -                       }
71                 -                       else {
72                 -                               $tag='month-calendar-day-link';
73                 -                       }
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};
80                 +               }
81                 +               elsif ($day >= $future_dom) {
82                 +                       $tag='month-calendar-day-future';
83                 +               }
84                 +               elsif($params{detail} == 0 && 
85                 +                       !defined $cache{$pagespec}{"$year/$mtag/$day"}) {
86                 +                       $tag='month-calendar-day-nolink';
87                 +               } 
88                 +               elsif($params{detail} == 0 && 
89                 +                       defined $cache{$pagespec}{"$year/$mtag/$day"}) {
90                 +                       $tag='month-calendar-day-link';
91                                 }
92                                 else {
93                 -                       if ($day == $today) {
94                 -                               $tag='month-calendar-day-this-day';
95                 -                       }
96                 -                       elsif ($day == $future_dom) {
97                 -                               $tag='month-calendar-day-future';
98                 +                       $tag='month-calendar-day';
99                 +               }
100                 +
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"});
112                                         }
113                                         else {
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};
120                 +                                       }
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>};
127                 +                               }
128                                         }
129                 -                       $calendar.=qq{\t\t<td class="$tag $downame{$wday}">$day</td>\n};
130                                 }
131                 +               else {
132                 +                       $calendar.=qq{$day_label\n};
133                 +               }
134                 +               $calendar.=qq{</td>\n};
135                         }
136                  
137                         # finish off the week
138                 @@ -304,6 +333,18 @@
139                         return $calendar;
140                  }
141                  
142                 +sub preprocess_event (@) {
143                 +       my %params=@_;
144                 +       # if now time is given, use now
145                 +       $params{begin} = localtime($time)            unless defined $params{begin};
146                 +
147                 +       my $timestamp = str2time($params{begin});
148                 +       if ( defined $timestamp) {
149                 +               $pagestate{$params{page}}{event}{begin}=$timestamp;
150                 +       }
151                 +       return "<!-- $params{begin} -->";
152                 +} #}}
153                 +
154                  sub preprocess (@) {
155                         my %params=@_;
156                         $params{pages} = "*"            unless defined $params{pages};
157                 @@ -311,6 +352,8 @@
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};
163                  
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);
177                 -
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"}++;
183                 +                       my $begin = '';
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};
192                 +                       }
193                 +                       if($begin ne '') {
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);
200                 +
201                 +                               $linkcache{"$year/$mtag/$mday"}{$p} = "$dest";
202                 +                               $cache{$pagespec}{"$year"}++;
203                 +                               $cache{$pagespec}{"$year/$mtag"}++;
204                 +                               $cache{$pagespec}{"$year/$mtag/$mday"}++;
205                 +                       }
206                                 }
207                         }
208