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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Sat May 10 04:28:24 2003 UTC revision 1.3 by wakaba, Tue Aug 19 03:53:47 2003 UTC
# Line 4  FullName: Line 4  FullName:
4          Simple Calender Generator          Simple Calender Generator
5  URI:  URI:
6          IW:SuikaWiki:WikiForm          IW:SuikaWiki:WikiForm
7    Initialize:
8            SuikaWiki::Plugin->feature ('SuikaWiki::Markup::XML');
9            my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
10    
11  {  {
12  Name:  Name:
# Line 12  FullName: Line 15  FullName:
15          Calender of specified year and month          Calender of specified year and month
16  Format:  Format:
17          require Time::Local;          require Time::Local;
18          my @dayname = qw/sun mon tue wed thr fri sat/;          my @dayname = qw/sun mon tue wed thr fri sat/;  ## class names
19          my ($year, $month) = ($p->{year} || (gmtime)[5]+1900, $p->{month} || (gmtime)[4]+1);          my ($year, $month) = ($p->{year} || (gmtime)[5]+1900, $p->{month} || (gmtime)[4]+1);
20          if (!$p->{year}) {          if (!$p->{year}) {
21            my ($y, $m) = iso8601date_to_parts (long_name_to_date ($p->{page} || $o->{page}));            my ($y, $m) = iso8601date_to_parts (long_name_to_date ($p->{page} || $o->{page}));
# Line 22  Format: Line 25  Format:
25          }          }
26          my $dow = 0; eval q($dow = (gmtime (Time::Local::timegm_nocheck (0,0,0,1, $month-1, $year)))[6]);          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]);          my $lom = 0; eval q($lom = (gmtime (Time::Local::timegm_nocheck (0,0,0,0, $month==12?0:$month, $year)))[3]);
28          $r .= q(<table class="calender">);          
29          $r .= qq(<caption>@{[$o->escape($p->{caption} || "$year年$month月")]}</caption>) unless $p->{nocaption};          $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'table');
30          $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" />);            $r->set_attribute (class => 'calender');
31          unless ($p->{noheader}) {            $r->set_attribute (summary => $o->resource ('Calender:Table:Summary'));
32            $r .= q(<thead><tr>);            unless ($p->{nocaption}) {
33            my @wname = split /\s+/, ($p->{dayname} || q/日 月 火 水 木 金 土/);              ## TODO: use resource
34            for my $dow (0..6) {              $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'caption')
35              $r .= qq(<th class="@{[$dayname[$dow]]}" scope="col">@{[$o->escape ($wname[$dow])]}</th>);                ->append_text ($p->{caption} || "$year年$month月");
36            }            }
37            $r .= "</tr></thead>";            for (@dayname) {
38          }              $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'col')
39          $r .= "<tbody>";                ->set_attribute (class => $_);
40          $r .= '<tr>'. ('<td></td>' x $dow) unless $dow == 0;            }
41          for my $day (1..$lom) {            unless ($p->{noheader}) {
42            $r .= "<tr>" if $dow == 0;              my @wname = split /\s+/, ($p->{dayname} || q/日 月 火 水 木 金 土/);
43            $r .= qq(<td class="@{[$dayname[$dow]]}">);              my $row = $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'thead')
44            my $page = short_name_to_full_name ($p->{page}||$o->{page}=>sprintf ('%04d-%02d-%02d', $year, $month, $day));                          ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr');
45            #if ($o->_database_exist ($page)) {              for my $i (0..6) {
46              $r .= $o->_html_wikilink ($page, label => $day);                for ($row->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'th')) {
47            #} else {                  $_->set_attribute (class => $dayname[$i]);
48            #  $r .= $day;                  $_->set_attribute (scope => 'col');
49            #}                  $_->append_text ($wname[$i]);
50            $r .= qq(</td>);                }
51            $dow++; ($dow = 0, $r .= "</tr>\n") if $dow == 7;              }
52          }            }     # not noheader
53          $r .= <<EOH;            my $tb = $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tbody');
54          </tbody>              my $e_week;
55          </table>              unless ($dow == 0) {        ## 1st day is not sunday
56          EOH                $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                    $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                  $dow++; $dow = 0 if $dow == 7;
81                }
82              # tbody
83            # table
84    }
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  }  }
94    
95  {  {
# Line 100  Format: Line 139  Format:
139              $p->{title} = $page{$rel};  ## TO DO: support custom title              $p->{title} = $page{$rel};  ## TO DO: support custom title
140                            
141              $r .= qq(<link);              $r .= qq(<link);
142                for my $attr (qw/rel rev href class type hreflang charset/) {                for my $attr (qw/rel rev href class title type hreflang charset/) {
143                  $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};                  $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
144                }                }
               for my $attr (qw/title/) {  
                 $r .= qq( $attr="@{[$o->formatter('view')->replace($p->{$attr},$o)]}") if $p->{$attr};  
               }  
145              $r .= '/' if $o->{media}->{type} =~ /xml/;              $r .= '/' if $o->{media}->{type} =~ /xml/;
146              $r .= '>';              $r .= '>';
147            }            }
# Line 175  MODULE: Line 211  MODULE:
211          }          }
212          SuikaWiki::View->template ('links')->add_line (q(%link-calender-date(class=>wiki);));          SuikaWiki::View->template ('links')->add_line (q(%link-calender-date(class=>wiki);));
213  POD:LICENSE:  POD:LICENSE:
214          Copyright 2002 Wakaba <w@suika.fam.cx>          Copyright 2002-2003 Wakaba <w@suika.fam.cx>
215                    
216          %%GNUGPL2%%          %%GNUGPL2%%

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24