Permalink
Browse files

calendar.pl: allow previous and next month

Stefan Kamphausen provided a reason for liking the deprecated cal3
extension: he likes cal3 because it also displays the next and
previous month as opposed to calendar.pl which only displays the
current month.

This commit allows users to get the same behaviour by setting
$CalendarOnEveryPage to values greater than 1: 1 shows the current
month on every page, but 2 shows the previous and the current month on
every page, and 3 shows the previous, the current and the next month
on every page.
  • Loading branch information...
kensanata committed Aug 31, 2016
1 parent e3cacaa commit 90eb428787b81a342a44bc4f657adffe4f0643a0
Showing with 25 additions and 10 deletions.
  1. +20 −5 modules/calendar.pl
  2. +5 −5 t/calendar.t
@@ -23,6 +23,7 @@
our ($CalendarOnEveryPage, $CalAsTable, $CalStartMonday);
$CalendarOnEveryPage = 0; # 1=on every page is a month-div situated in the header, use css to control
# 2=this month and the previous month; 3=this, previous and next month
$CalAsTable = 0; # 0=every month-div is "free", 1=every month-div is caught in a table, use css to control
$CalStartMonday = 0; # 0=week starts with Su, 1=week starts with Mo
@@ -34,8 +35,22 @@ sub NewCalendarGetHeader {
return $header unless $CalendarOnEveryPage;
my $action = GetParam('action', 'browse');
return $header if grep(/^$action$/, ('calendar', 'edit'));
my $cal = Cal();
$header =~ s/<div class="header">/$cal<div class="header">/;
my $cal;
my ($sec, $min, $hour, $mday, $mon, $year) = localtime($Now);
$year += 1900;
# $mon is 0 based and thus good for previous month
if ($mon < 1) { $year -= 1; $mon += 12; };
$cal .= Cal($year, $mon) if $CalendarOnEveryPage > 1;
# the current month
$mon += 1;
if ($mon > 12) { $year += 1; $mon -= 12; };
$cal .= Cal($year, $mon) if $CalendarOnEveryPage;
# the next month
$mon += 1;
if ($mon > 12) { $year += 1; $mon -= 12; };
$cal .= Cal($year, $mon) if $CalendarOnEveryPage > 2;
# insert calendars before header div
$header =~ s!<div class="header">!<div class="cal">$cal</div><div class="header">!;
return $header;
}
@@ -85,7 +100,7 @@ sub Cal {
$year_text, 'local collection year'));
}
}}e;
return "<div class=\"cal month\"><pre>$cal</pre></div>";
return "<div class=\"month\"><pre>$cal</pre></div>";
}
$Action{collect} = \&DoCollect;
@@ -126,7 +141,7 @@ sub CalendarRule {
my $oldpos = pos;
Clean(CloseHtmlEnvironments());
Dirty($1);
print Cal($2, $3);
print $q->div({-class => 'cal'}, Cal($2, $3));
pos = $oldpos;
return AddHtmlEnvironment('p');
} elsif (/\G(month:([+-]\d\d?))/cg
@@ -141,7 +156,7 @@ sub CalendarRule {
$mon += 1 + $delta;
while ($mon < 1) { $year -= 1; $mon += 12; };
while ($mon > 12) { $year += 1; $mon -= 12; };
print Cal($year, $mon, undef, $id);
print $q->div({-class => 'cal'}, Cal($year, $mon, undef, $id));
pos = $oldpos;
return AddHtmlEnvironment('p');
}
@@ -34,18 +34,18 @@ test_page(update_page("with_cal", "zulu\n\ncalendar:2006\n\nwarrior\n"),
'</pre></div><p>warrior</p></div><div class="wrapper close"></div></div><div class="footer">');
test_page(update_page("with_cal", "zulu\n\nmonth:2006-09\n\nwarrior\n"),
'<p>zulu</p><div class="cal month"><pre>',
'</pre></div><p>warrior</p></div><div class="wrapper close"></div></div><div class="footer">');
'<p>zulu</p><div class="cal"><div class="month"><pre>',
'</pre></div></div><p>warrior</p></div><div class="wrapper close"></div></div><div class="footer">');
test_page(update_page("with_cal", "zulu\n\nmonth:+0\n\nwarrior\n"),
'<p>zulu</p><div class="cal month"><pre>',
'</pre></div><p>warrior</p></div><div class="wrapper close"></div></div><div class="footer">');
'<p>zulu</p><div class="cal"><div class="month"><pre>',
'</pre></div></div><p>warrior</p></div><div class="wrapper close"></div></div><div class="footer">');
xpath_test(get_page('action=calendar'),
# yearly navigation
'//div[@class="content cal year"]/p[@class="nav"]/a[@href="http://localhost/wiki.pl?action=calendar;year=' . $year_prev . '"][text()="Previous"]/following-sibling::text()[string()=" | "]/following-sibling::a[@href="http://localhost/wiki.pl?action=calendar;year=' . $year_next . '"][text()="Next"]',
# monthly collection
'//div[@class="cal month"]/pre/span[@class="title"]/a[@class="local collection month"][@href="http://localhost/wiki.pl?action=collect;match=%5e' . sprintf("%d-%02d", $year, $mon) . '"]',
'//div[contains(@class,"cal")]/div[@class="month"]/pre/span[@class="title"]/a[@class="local collection month"][@href="http://localhost/wiki.pl?action=collect;match=%5e' . sprintf("%d-%02d", $year, $mon) . '"]',
# today day edit
'//a[@class="edit today"][@href="http://localhost/wiki.pl?action=edit;id=' . $today . '"][normalize-space(text())="' . $mday . '"]',
# other day edit

0 comments on commit 90eb428

Please sign in to comment.