/[pub]/suikawiki/script/misc/plugins/Calender.wps
Suika

Contents of /suikawiki/script/misc/plugins/Calender.wps

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Sat Feb 14 10:53:48 2004 UTC (21 years, 2 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
FILE REMOVED
Removed

1 wakaba 1.1 Name:
2     Calender
3     FullName:
4     Simple Calender Generator
5     URI:
6     IW:SuikaWiki:WikiForm
7 wakaba 1.2 Initialize:
8     SuikaWiki::Plugin->feature ('SuikaWiki::Markup::XML');
9     my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
10 wakaba 1.1
11     {
12     Name:
13     wikiform_input/calender
14     FullName:
15     Calender of specified year and month
16     Format:
17     require Time::Local;
18 wakaba 1.2 my @dayname = qw/sun mon tue wed thr fri sat/; ## class names
19 wakaba 1.1 my ($year, $month) = ($p->{year} || (gmtime)[5]+1900, $p->{month} || (gmtime)[4]+1);
20     if (!$p->{year}) {
21     my ($y, $m) = iso8601date_to_parts (long_name_to_date ($p->{page} || $o->{page}));
22     if ($y) {
23     $year = $y; $month = $m if $m;
24     }
25     }
26     my $dow = 0; eval q($dow = (gmtime (Time::Local::timegm_nocheck (0,0,0,1, $month-1, $year)))[6]);
27     my $lom = 0; eval q($lom = (gmtime (Time::Local::timegm_nocheck (0,0,0,0, $month==12?0:$month, $year)))[3]);
28 wakaba 1.2
29     $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'table');
30     $r->set_attribute (class => 'calender');
31     $r->set_attribute (summary => $o->resource ('Calender:Table:Summary'));
32     unless ($p->{nocaption}) {
33     ## TODO: use resource
34     $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'caption')
35     ->append_text ($p->{caption} || "$year年$month月");
36     }
37     for (@dayname) {
38     $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'col')
39     ->set_attribute (class => $_);
40     }
41     unless ($p->{noheader}) {
42     my @wname = split /\s+/, ($p->{dayname} || q/日 月 火 水 木 金 土/);
43     my $row = $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'thead')
44     ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr');
45     for my $i (0..6) {
46     for ($row->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'th')) {
47     $_->set_attribute (class => $dayname[$i]);
48     $_->set_attribute (scope => 'col');
49     $_->append_text ($wname[$i]);
50     }
51     }
52     } # not noheader
53     my $tb = $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tbody');
54     my $e_week;
55     unless ($dow == 0) { ## 1st day is not sunday
56     $e_week = $tb->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr');
57     for (1..$dow) {
58     $e_week->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'td');
59     }
60     }
61    
62     for my $day (1..$lom) {
63     $e_week = $tb->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr')
64     if $dow == 0; ## New week
65     my $e_day = $e_week->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'td');
66     $e_day->set_attribute (class => $dayname[$dow]);
67     my $page = short_name_to_full_name (($p->{page} || $o->{page}) => sprintf ('%04d-%02d-%02d', $year, $month, $day));
68 wakaba 1.3 $e_day->append_node (SuikaWiki::Plugin::WikiLinking
69     ->to_wikipage_in_html ({
70     label => ($p->{day_label}
71     || $o->resource ('Calender:Day:Label')),
72     } => {
73     base => $page,
74     page_name_relative => $page,
75     wiki_mode => $p->{mode},
76     c__day => $day,
77     }, {
78     o => $o,
79     }));
80 wakaba 1.2 $dow++; $dow = 0 if $dow == 7;
81     }
82     # tbody
83     # table
84 wakaba 1.3 }
85    
86     {
87     Name:
88     wikipage-link/calender--day
89     FullName:
90     Day of WikiPage linked to
91     Format:
92     $r = $o->{link}->{dest}->{c__day} + 0;
93 wakaba 1.1 }
94    
95     {
96     Name:
97     wikiview/link-calender-date
98     FullName:
99     Link element whose destination anchor is the prev/next/.. year/month/day
100     Format:
101     my $page = long_name_to_date ($p->{page} || $o->{page});
102     if ($page =~ /^([0-9]{4,})(?:-([0-9]{1,2})(?:-([0-9]{1,2}))?)?$/) {
103     my ($year, $month, $day) = ($1, $2, $3);
104     my ($Year, $Month, $Day) = (0, 0, 0);
105     my ($yeaR, $montH, $daY) = (0, 0, 0);
106     my %page;
107     $page{_base} = $p->{page} || $o->{page};
108     if ($day) { ## 2003-04-01
109     require Time::Local;
110     (undef, undef, undef, $Day, $Month, $Year)
111     = gmtime (Time::Local::timegm_nocheck (0,0,0,$day, $month - 1, $year) - 24 * 3600);
112     $Month++; $Year += 1900;
113     $page{prev} = sprintf '%04d-%02d-%02d', $Year, $Month, $Day;
114     (undef, undef, undef, $daY, $montH, $yeaR)
115     = gmtime (Time::Local::timegm_nocheck (0,0,0,$day, $month - 1, $year) + 25 * 3600);
116     $montH++; $yeaR += 1900;
117     $page{next} = sprintf '%04d-%02d-%02d', $yeaR, $montH, $daY;
118     $page{up} = sprintf '%04d-%02d', $year, $month;
119     } elsif ($month) { ## 2003-04
120     ($Year, $Month) = ($year, $month - 1);
121     (($Month = 12) && $Year--) if $Month == 0;
122     $page{prev} = sprintf '%04d-%02d', $Year, $Month;
123     ($yeaR, $montH) = ($year, $month + 1);
124     (($montH = 1) && $yeaR++) if $montH == 13;
125     $page{next} = sprintf '%04d-%02d', $yeaR, $montH;
126     $page{up} = sprintf '%04d', $year;
127     } else { ## 2003
128     $Year = $year - 1;
129     $page{prev} = sprintf '%04d', $Year;
130     $yeaR = $year + 1;
131     $page{next} = sprintf '%04d', $yeaR;
132     }
133    
134     for my $rel ('prev', 'next', 'up') {
135     next unless length $page{$rel};
136     $p->{rel} = $rel;
137     $page{$rel} = short_name_to_full_name ($page{_base} => $page{$rel});
138     $p->{href} = $o->_uri_wiki_page ($page{$rel}, %$o);
139     $p->{title} = $page{$rel}; ## TO DO: support custom title
140    
141     $r .= qq(<link);
142 wakaba 1.2 for my $attr (qw/rel rev href class title type hreflang charset/) {
143 wakaba 1.1 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
144     }
145     $r .= '/' if $o->{media}->{type} =~ /xml/;
146     $r .= '>';
147     }
148     }
149     }
150    
151     {
152     Name:
153     wikiview/if-calender
154     FullName:
155     Check whether the WikiPage is part of calender or not
156     Format:
157     my $tf = 0;
158     my ($y, $m, $d) = iso8601date_to_parts (long_name_to_date ($p->{page} || $o->{page}));
159     if ($y && !(($p->{month} && !$m) || ($p->{day} && !$d))) {
160     $tf = 1;
161     }
162     $r = $o->formatter ('view')->replace (($tf ? $p->{true} : $p->{false}), $o);
163     }
164    
165     {
166     Name:
167     wikiform_input/calender-months
168     FullName:
169     Months' list
170     Format:
171     my ($year) = $p->{year} || (gmtime)[5]+1900;
172     if (!$p->{year}) {
173     my ($y, $m) = iso8601date_to_parts (long_name_to_date ($p->{page} || $o->{page}));
174     $year = $y if $y;
175     }
176     $r = '<ol class="calender year">';
177     for my $month (1..12) {
178     $r .= '<li>';
179     my $page = short_name_to_full_name (($p->{page} || $o->{page}) => sprintf ('%04d-%02d', $year, $month));
180     #if ($o->_database_exist ($page)) {
181     $r .= $o->_html_wikilink ($page, label => $month);
182     #} else {
183     # $r .= $month;
184     #}
185     $r .= qq(</li>);
186     }
187     $r .= '</ol>';
188     }
189    
190     MODULE:
191     sub iso8601date_to_parts ($) {
192     my $date = shift;
193     if ($date =~ /^([0-9]{4,})(?:-([0-9]{1,2})(?:-([0-9]{1,2}))?)?$/) {
194     return ($1, $2, $3);
195     }
196     (0, 0, 0);
197     }
198     sub long_name_to_date ($) {
199     if ($SuikaWiki::Name::Space::VERSION) {
200     SuikaWiki::Name::Space::get_short_name (shift);
201     } else {
202     shift;
203     }
204     }
205     sub short_name_to_full_name ($$) {
206     if ($SuikaWiki::Name::Space::VERSION) {
207     SuikaWiki::Name::Space::resolve_relative_name ($_[0] => '..//'.$_[1]);
208     } else {
209     $_[1];
210     }
211     }
212     SuikaWiki::View->template ('links')->add_line (q(%link-calender-date(class=>wiki);));
213     POD:LICENSE:
214 wakaba 1.2 Copyright 2002-2003 Wakaba <w@suika.fam.cx>
215 wakaba 1.1
216     %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24