/[pub]/suikawiki/script/lib/SuikaWiki/Plugin/Calender.wps
Suika

Contents of /suikawiki/script/lib/SuikaWiki/Plugin/Calender.wps

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations) (download)
Sat May 10 05:51:16 2003 UTC (22 years ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +0 -0 lines
FILE REMOVED
Some plugins are moved to optional plugin directory

1 wakaba 1.1 Name:
2     Calender
3     FullName:
4     Simple Calender Generator
5     URI:
6     IW:SuikaWiki:WikiForm
7    
8     {
9     Name:
10     wikiform_input/calender
11     FullName:
12     Calender of specified year and month
13     Format:
14     require Time::Local;
15     my @dayname = qw/sun mon tue wed thr fri sat/;
16     my ($year, $month) = ($p->{year} || (gmtime)[5]+1900, $p->{month} || (gmtime)[4]+1);
17 wakaba 1.4 if (!$p->{year}) {
18 wakaba 1.5 my ($y, $m) = iso8601date_to_parts (long_name_to_date ($p->{page} || $o->{page}));
19 wakaba 1.4 if ($y) {
20     $year = $y; $month = $m if $m;
21     }
22     }
23 wakaba 1.1 my $dow = 0; eval q($dow = (gmtime (Time::Local::timegm_nocheck (0,0,0,1, $month-1, $year)))[6]);
24     my $lom = 0; eval q($lom = (gmtime (Time::Local::timegm_nocheck (0,0,0,0, $month==12?0:$month, $year)))[3]);
25     $r .= q(<table class="calender">);
26     $r .= qq(<caption>@{[$o->escape($p->{caption} || "$yearǯ$month��")]}</caption>) unless $p->{nocaption};
27 wakaba 1.3 $r .= q(<col class="sun" /><colgroup class="weekday"><col class="mon" /><col class="tue" /><col class="wed" /><col class="thr" /><col class="fri" /></colgroup><col class="sat" />);
28 wakaba 1.1 unless ($p->{noheader}) {
29     $r .= q(<thead><tr>);
30     my @wname = split /\s+/, ($p->{dayname} || q/�� �� �� �� �� �� ��/);
31     for my $dow (0..6) {
32 wakaba 1.4 $r .= qq(<th class="@{[$dayname[$dow]]}" scope="col">@{[$o->escape ($wname[$dow])]}</th>);
33 wakaba 1.1 }
34     $r .= "</tr></thead>";
35     }
36     $r .= "<tbody>";
37 wakaba 1.2 $r .= '<tr>'. ('<td></td>' x $dow) unless $dow == 0;
38 wakaba 1.1 for my $day (1..$lom) {
39     $r .= "<tr>" if $dow == 0;
40 wakaba 1.4 $r .= qq(<td class="@{[$dayname[$dow]]}">);
41 wakaba 1.5 my $page = short_name_to_full_name ($p->{page}||$o->{page}=>sprintf ('%04d-%02d-%02d', $year, $month, $day));
42 wakaba 1.6 #if ($o->_database_exist ($page)) {
43 wakaba 1.5 $r .= $o->_html_wikilink ($page, label => $day);
44 wakaba 1.6 #} else {
45     # $r .= $day;
46     #}
47 wakaba 1.4 $r .= qq(</td>);
48 wakaba 1.1 $dow++; ($dow = 0, $r .= "</tr>\n") if $dow == 7;
49     }
50     $r .= <<EOH;
51     </tbody>
52     </table>
53     EOH
54     }
55    
56 wakaba 1.4 {
57     Name:
58     wikiview/link-calender-date
59     FullName:
60     Link element whose destination anchor is the prev/next/.. year/month/day
61     Format:
62 wakaba 1.5 my $page = long_name_to_date ($p->{page} || $o->{page});
63     if ($page =~ /^([0-9]{4,})(?:-([0-9]{1,2})(?:-([0-9]{1,2}))?)?$/) {
64 wakaba 1.4 my ($year, $month, $day) = ($1, $2, $3);
65     my ($Year, $Month, $Day) = (0, 0, 0);
66     my ($yeaR, $montH, $daY) = (0, 0, 0);
67     my %page;
68 wakaba 1.5 $page{_base} = $p->{page} || $o->{page};
69 wakaba 1.4 if ($day) { ## 2003-04-01
70     require Time::Local;
71     (undef, undef, undef, $Day, $Month, $Year)
72 wakaba 1.5 = gmtime (Time::Local::timegm_nocheck (0,0,0,$day, $month - 1, $year) - 24 * 3600);
73 wakaba 1.4 $Month++; $Year += 1900;
74     $page{prev} = sprintf '%04d-%02d-%02d', $Year, $Month, $Day;
75     (undef, undef, undef, $daY, $montH, $yeaR)
76     = gmtime (Time::Local::timegm_nocheck (0,0,0,$day, $month - 1, $year) + 25 * 3600);
77     $montH++; $yeaR += 1900;
78     $page{next} = sprintf '%04d-%02d-%02d', $yeaR, $montH, $daY;
79     $page{up} = sprintf '%04d-%02d', $year, $month;
80     } elsif ($month) { ## 2003-04
81     ($Year, $Month) = ($year, $month - 1);
82     (($Month = 12) && $Year--) if $Month == 0;
83     $page{prev} = sprintf '%04d-%02d', $Year, $Month;
84     ($yeaR, $montH) = ($year, $month + 1);
85     (($montH = 1) && $yeaR++) if $montH == 13;
86     $page{next} = sprintf '%04d-%02d', $yeaR, $montH;
87     $page{up} = sprintf '%04d', $year;
88     } else { ## 2003
89     $Year = $year - 1;
90     $page{prev} = sprintf '%04d', $Year;
91     $yeaR = $year + 1;
92     $page{next} = sprintf '%04d', $yeaR;
93     }
94    
95     for my $rel ('prev', 'next', 'up') {
96     next unless length $page{$rel};
97     $p->{rel} = $rel;
98 wakaba 1.5 $page{$rel} = short_name_to_full_name ($page{_base} => $page{$rel});
99 wakaba 1.4 $p->{href} = $o->_uri_wiki_page ($page{$rel}, %$o);
100     $p->{title} = $page{$rel}; ## TO DO: support custom title
101    
102     $r .= qq(<link);
103     for my $attr (qw/rel rev href class type hreflang charset/) {
104     $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
105     }
106     for my $attr (qw/title/) {
107     $r .= qq( $attr="@{[$o->formatter('view')->replace($p->{$attr},$o)]}") if $p->{$attr};
108     }
109     $r .= '/' if $o->{media}->{type} =~ /xml/;
110     $r .= '>';
111     }
112     }
113     }
114    
115     {
116     Name:
117     wikiview/if-calender
118     FullName:
119     Check whether the WikiPage is part of calender or not
120     Format:
121     my $tf = 0;
122 wakaba 1.5 my ($y, $m, $d) = iso8601date_to_parts (long_name_to_date ($p->{page} || $o->{page}));
123 wakaba 1.4 if ($y && !(($p->{month} && !$m) || ($p->{day} && !$d))) {
124     $tf = 1;
125     }
126     $r = $o->formatter ('view')->replace (($tf ? $p->{true} : $p->{false}), $o);
127     }
128    
129     {
130     Name:
131     wikiform_input/calender-months
132     FullName:
133     Months' list
134     Format:
135     my ($year) = $p->{year} || (gmtime)[5]+1900;
136     if (!$p->{year}) {
137 wakaba 1.5 my ($y, $m) = iso8601date_to_parts (long_name_to_date ($p->{page} || $o->{page}));
138 wakaba 1.4 $year = $y if $y;
139     }
140     $r = '<ol class="calender year">';
141     for my $month (1..12) {
142     $r .= '<li>';
143 wakaba 1.5 my $page = short_name_to_full_name (($p->{page} || $o->{page}) => sprintf ('%04d-%02d', $year, $month));
144 wakaba 1.6 #if ($o->_database_exist ($page)) {
145 wakaba 1.5 $r .= $o->_html_wikilink ($page, label => $month);
146 wakaba 1.6 #} else {
147     # $r .= $month;
148     #}
149 wakaba 1.4 $r .= qq(</li>);
150     }
151     $r .= '</ol>';
152     }
153    
154     MODULE:
155     sub iso8601date_to_parts ($) {
156     my $date = shift;
157     if ($date =~ /^([0-9]{4,})(?:-([0-9]{1,2})(?:-([0-9]{1,2}))?)?$/) {
158     return ($1, $2, $3);
159     }
160     (0, 0, 0);
161     }
162 wakaba 1.5 sub long_name_to_date ($) {
163     if ($SuikaWiki::Name::Space::VERSION) {
164     SuikaWiki::Name::Space::get_short_name (shift);
165     } else {
166     shift;
167     }
168     }
169     sub short_name_to_full_name ($$) {
170     if ($SuikaWiki::Name::Space::VERSION) {
171     SuikaWiki::Name::Space::resolve_relative_name ($_[0] => '..//'.$_[1]);
172     } else {
173     $_[1];
174     }
175     }
176     SuikaWiki::View->template ('links')->add_line (q(%link-calender-date(class=>wiki);));
177 wakaba 1.1 POD:LICENSE:
178     Copyright 2002 Wakaba <w@suika.fam.cx>
179    
180     %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24  
Google Analytics is used in this page; Cookies are used. 忍者AdMax is used in this page; Cookies are used. Privacy policy.