wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / cal3.pl
blob1b81521aedfba1558e2203f6800cf858543f44df
1 # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
2 # 2004 Tilmann Holst <spam@tholst.de>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the
16 # Free Software Foundation, Inc.
17 # 59 Temple Place, Suite 330
18 # Boston, MA 02111-1307 USA
20 # You may need to set $calcmd below.
21 # Without the cal program (shipped with almost every unix) this extension
22 # is useless. This extension will not work under Windows/IIS unless cal
23 # is installed.
25 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/cal3.pl">cal3.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Cal3_Extension">Cal3 Extension</a></p>';
27 *OldCalendarGetHeader = *GetHeader;
28 *GetHeader = *NewCalendarGetHeader;
30 sub NewCalendarGetHeader {
31 my ($csec, $cmin, $chour, $cmday, $cmon, $cyear) = gmtime();
32 $cyear += 1900;
33 $cmon += 1;
35 my qw($cal $prevmon $prevyear $nextmon $nextyear);
37 # check if previous month is in previous year
38 if ($cmon == 1){
39 $prevmon = "12";
40 $prevyear = ($cyear - 1);
41 } else {
42 $prevmon = ($cmon - 1);
43 $prevyear = $cyear;
45 # check if next month is in next year
46 if ($cmon == "12") {
47 $nextmon = "1";
48 $nextyear = ($cyear + 1);
49 } else {
50 $nextmon = ($cmon + 1);
51 $nextyear = $cyear;
53 my $header = OldCalendarGetHeader(@_);
55 # commenting out the last line of this paragraph makes cal3 a cal2
56 # extension.
57 $cal = Cal($nextmon,$nextyear);
58 $cal .= Cal($cmon,$cyear);
59 $cal .= Cal($prevmon,$prevyear);
61 $header =~ s/<div class="header">/$cal<div class="header">/;
62 return $header;
65 sub Cal {
66 my ($month,$year) = @_;
67 # set $calcmd to an appropriate value
68 my $calcmd = 'cal'; # week starts with sunday
69 # my $calcmd = 'cal -m'; # week starts with monday
70 # my $calcmd = 'export LC_ALL=de_DE.UTF-8;/insert/path/here/cal -m'; # example with different path to cal and different locale
71 my $cal = `$calcmd $month $year`;
72 return unless $cal;
73 my ($sec, $min, $hour, $mday, $mon, $myyear) = gmtime($Now);
74 $cal =~ s|\b( ?\d?\d)\b|{
75 my $day = $1;
76 my $date = sprintf("%d-%02d-%02d", $year, $month, $day);
77 my $class;
78 if ($month == ($mon + 1)) {
79 $class = ($day == $mday) ? 'today'
80 : ($IndexHash{$date} ? 'exists' : 'wanted');
81 } else {
82 $class = ($IndexHash{$date} ? 'exists' : 'wanted');
84 "<a class=\"$class\" href=\"$ScriptName/$date\">$day</a>";
85 }|ge;
86 return "<div class=\"cal\"><pre>$cal</pre></div>";