#?SuikaWikiConfig/2.0 Plugin: @Name: Calender @Description: @@@: Calender @@lang:en @License: %%Perl%% @Author: @@Name: @@@@: Wakaba @@@lang:ja @@@script:Latn @@Mail[list]: w@suika.fam.cx @Date.RCS: $Date: 2004/05/18 11:25:11 $ @RequiredPlugin[list]: Phrase WikiResource WikiStructure WikiLinking @Use: my $WIKILINKING; my $WIKIRESOURCE; PluginConst: @NS_XHTML1: http://www.w3.org/1999/xhtml @WIKILINKING: {($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))} @WIKIRESOURCE: {($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))} FormattingRule: @Category[list]: view view-resource form-input @Name: if-calender @Description: @@@: Test whether the WikiPage is part of calender or not @@lang: en @Parameter: @@Name: day @@Type: CDATA @@Default: (none) @@Description: @@@@: Template to be evaluated when it is part of calender and has "day" information. @@@lang: en @Parameter: @@Name: false @@Type: CDATA @@Default: (none) @@Description: @@@@: Template to be evaluated when it is part of calender @@@lang: en @Parameter: @@Name: month @@Type: CDATA @@Default: (none) @@Description: @@@@: Template to be evaluated when it is part of calender and has "month" part. This template will not be used if "day" template is used. @@@lang: en @Parameter: @@Name: page @@Type: WikiName @@Default: (auto) @@Description: @@@@: WikiPage to be tested @@lang: en @Parameter: @@Name: true @@Type: CDATA @@Default: (none) @@Description: @@@@: Template to be evaluated when it is part of calender. This template will not be used if "year", "month" or "day" template is used. @@@lang: en @Parameter: @@Name: year @@Type: CDATA @@Default: (none) @@Description: @@@@: Template to be evaluated when it is part of calender. This template will not be used if "month" or "day" template is used. @@lang: en @Formatting: my $page = $o->{wiki}->name ($p->{page} or $o->{wiki}->{var}->{page}); my $date = __FUNCPACK__->wikiname_to_date (name => $page, o => $o); if ($date->{year}) { if ($date->{day} and $p->{day}) { __ATTRNODE:%day->{$p->{-parent}}__; } elsif ($date->{month} and $p->{month}) { __ATTRNODE:%month->{$p->{-parent}}__; } elsif ($p->{year}) { __ATTRNODE:%year->{$p->{-parent}}__; } else { __ATTRNODE:%true->{$p->{-parent}}__; } } else { __ATTRNODE:%false->{$p->{-parent}}__; } FormattingRule: @Category[list]: form-input view view-resource @Name: calender @Description: @@@: List of months in the year @@lang: en @Parameter: @@Name: label @@Type: template @@Default: (auto) @@Description: @@@@: Template to be used to construct day item @@@lang: en @Parameter: @@Name: month @@Type: <<1*2DIGIT>> @@Default: (auto) @@Description: @@@@: Month @@@lang: en @Parameter: @@Name: year @@Type: <<4*DIGIT>> @@Default: (auto) @@Description: @@@@: Year @@@lang: en @Formatting: require Time::Local; my $date = __FUNCPACK__->wikiname_to_date (name => $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page}), o => $o); my $year = $p->{year} || $date->{year} || (gmtime)[5] + 1900; my $month = $p->{month} || $date->{month} || (gmtime)[4] + 1; my $dow = 0; eval q{$dow = (gmtime (Time::Local::timegm_nocheck (0,0,0,1, $month-1, $year)))[6]}; my $lom = 0; eval {$lom = (gmtime (Time::Local::timegm_nocheck (0,0,0,0, $month==12?0:$month, $year)))[3]}; my $tbl = $p->{-parent}->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'table'); $tbl->set_attribute (class => 'calender'); $tbl->set_attribute (summary => $WIKIRESOURCE->get_op ('Calender:Table:Summary', $o) ->inner_text); __ATTRTEXT:%nocaption__; unless ($p->{nocaption}) { my $caption = $tbl->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'caption'); local $o->{link}->{option} = {-cal__year => $year, -cal__month => $month}; if ($p->{caption}) { __ATTRNODE:%caption->{$caption}__; } else { $WIKIRESOURCE->get_op ('Calender:Table:Caption', $o, $caption); } } my @dayname = qw(sun mon tue wed thu fri sat); for (@dayname) { $tbl->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'col') ->set_attribute (class => $_); } __ATTRTEXT:%noheader__; unless ($p->{noheader}) { my @wname = map {$WIKIRESOURCE->get_op ('Calender:Weekday:Label:'.$_, $o)} @dayname; my $row = $tbl->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'thead') ->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'tr'); for my $i (0..6) { my $cell = $row->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'th'); $cell->set_attribute (class => $dayname[$i]); $cell->set_attribute (scope => 'col'); $cell->append_node ($wname[$i]); } } my $tb = $tbl->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'tbody'); my $e_week; unless ($dow == 0) { ## 1st day is not sunday $e_week = $tb->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'tr'); for (1..$dow) { $e_week->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'td'); } } __ATTRTEXT:%day_label__; my $label = $p->{day_label} || $WIKIRESOURCE->get (name => 'Calender:Day:Label', o => $o, wiki => $o->{wiki}); __ATTRTEXT:%mode__; for my $day (1..$lom) { $e_week = $tb->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'tr') if $dow == 0; ## New week my $e_day = $e_week->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'td'); $e_day->set_attribute (class => $dayname[$dow]); $WIKILINKING->to_wikipage_in_html ({ label => $label, } => { base => $o->{wiki}->{var}->{page}, page_name_relative => __FUNCPACK__->date_to_wikiname (year => $year, month => $month, day => $day, base => $date->{base}, o => $o), wiki_mode => $p->{mode}, }, { o => $o, parent => $e_day, -cal__year => $year, -cal__month => $month, -cal__day => $day, }); $dow++; $dow = 0 if $dow == 7; } FormattingRule: @Category[list]: form-input view view-resource @Name: calender-months @Description: @@@: List of months in the year @@lang: en @Parameter: @@Name: label @@Type: template @@Default: (auto) @@Description: @@@@: Template to be used to construct month item @@@lang: en @Parameter: @@Name: year @@Type: <<4*DIGIT>> @@Default: (auto) @@Description: @@@@: Year @@@lang: en @Formatting: __ATTRTEXT:%year__; my $date = __FUNCPACK__->wikiname_to_date (name => $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page}), o => $o); my $year = $p->{year} || $date->{year} || (gmtime)[5] + 1900; my $list = $p->{-parent}->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'ol'); $list->set_attribute (class => 'calender year'); __ATTRTEXT:%label__; my $label = $p->{label} || $WIKIRESOURCE->get (name => 'Calender:MonthList:Item', wiki => $o->{wiki}, o => $o); for (1..12) { $WIKILINKING->to_wikipage_in_html ({ label => $label, } => { base => $o->{wiki}->{var}->{page}, page_name_relative => __FUNCPACK__->date_to_wikiname (year => $year, month => $_, base => $date->{base}, o => $o), }, { o => $o, parent => $list->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'li'), -cal__year => $year, -cal__month => $_, }); $list->append_text ("\n"); } FormattingRule: @Category[list]: page-link view-resource @Name: calender--year @Description: @@@: Year number @@lang: en @Formatting: $p->{-parent}->append_text ($o->{link}->{option}->{-cal__year} + 0); FormattingRule: @Category[list]: page-link view-resource @Name: calender--month @Description: @@@: Month number @@lang: en @Formatting: $p->{-parent}->append_text ($o->{link}->{option}->{-cal__month} + 0); FormattingRule: @Category[list]: page-link view-resource @Name: calender--day @Description: @@@: Day number @@lang: en @Formatting: $p->{-parent}->append_text ($o->{link}->{option}->{-cal__day} + 0); FormattingRule: @Category[list]: view view-resource form-input @Name: cal--year-page @Description: @@@: Year WikiPage name @@lang: en @Parameter: @@Name: page @@Type: WikiName @@Default: (auto) @@Description: @@@@: Some WikiPage in calender @@@lang: en @Parameter: @@Name: year @@Type: <<4*DIGIT>> @@Default: (auto) @@Description: @@@@: Year number @@@lang: en @Formatting: my $page = $o->{wiki}->name ($p->{page} or $o->{wiki}->{var}->{page}); my $date = __FUNCPACK__->wikiname_to_date (name => $page, o => $o); $p->{-parent}->append_text (__FUNCPACK__->date_to_wikiname (base => $date->{base}, year => $date->{year} || (gmtime)[5] + 1900, o => $o)->stringify (wiki => $o->{wiki})); FormattingRule: @Category[list]: view view-resource form-input @Name: cal--month-page @Description: @@@: Year-month WikiPage name @@lang: en @Parameter: @@Name: month @@Type: <<1*2DIGIT>> @@Default: (auto) @@Description: @@@@: Month number @@@lang: en @Parameter: @@Name: page @@Type: WikiName @@Default: (auto) @@Description: @@@@: Some WikiPage in calender @@@lang: en @Parameter: @@Name: year @@Type: <<4*DIGIT>> @@Default: (auto) @@Description: @@@@: Year number @@@lang: en @Formatting: my $page = $o->{wiki}->name ($p->{page} or $o->{wiki}->{var}->{page}); my $date = __FUNCPACK__->wikiname_to_date (name => $page, o => $o); $p->{-parent}->append_text (__FUNCPACK__->date_to_wikiname (base => $date->{base}, year => $p->{year} || $date->{year} || (gmtime)[5] + 1900, month => $p->{month} || $date->{month} || (gmtime)[4] + 1, o => $o)->stringify (wiki => $o->{wiki})); FormattingRule: @Category[list]: view view-resource form-input @Name: cal--day-page @Description: @@@: Year-month-day WikiPage name @@lang: en @Parameter: @@Name: day @@Type: <<1*2DIGIT>> @@Default: (auto) @@Description: @@@@: Day number @@@lang: en @Parameter: @@Name: month @@Type: <<1*2DIGIT>> @@Default: (auto) @@Description: @@@@: Month number @@@lang: en @Parameter: @@Name: page @@Type: WikiName @@Default: (auto) @@Description: @@@@: Some WikiPage in calender @@@lang: en @Parameter: @@Name: year @@Type: <<4*DIGIT>> @@Default: (auto) @@Description: @@@@: Year number @@@lang: en @Formatting: my $page = $o->{wiki}->name ($p->{page} or $o->{wiki}->{var}->{page}); my $date = __FUNCPACK__->wikiname_to_date (name => $page, o => $o); $p->{-parent}->append_text (__FUNCPACK__->date_to_wikiname (base => $date->{base}, year => $p->{year} || $date->{year} || (gmtime)[5] + 1900, month => $p->{month} || $date->{month} || (gmtime)[4] + 1, day => $p->{day} || $date->{day} || (gmtime)[3], o => $o)->stringify (wiki => $o->{wiki})); FormattingRule: @Category[list]: view @Name: link-calender-date @Description: @@@: Link to previous/next calender WikiPage @@lang: en @Formatting: my $page = $o->{wiki}->name ($p->{page} or $o->{wiki}->{var}->{page}); my $date = __FUNCPACK__->wikiname_to_date (name => $page, o => $o); my $year = $p->{year} || $date->{year} || return; my $month = $p->{month} || $date->{month}; my $day = $p->{day} || $date->{day}; my ($Year, $Month, $Day) = (0, 0, 0); my ($yeaR, $montH, $daY) = (0, 0, 0); my %page; if ($day) { ## 2003-04-01 require Time::Local; (undef, undef, undef, $Day, $Month, $Year) = gmtime (Time::Local::timegm_nocheck (0,0,0,$day, $month - 1, $year) - 24 * 3600); $Month++; $Year += 1900; $page{prev} = {year => $Year, month => $Month, day => $Day}; (undef, undef, undef, $daY, $montH, $yeaR) = gmtime (Time::Local::timegm_nocheck (0,0,0,$day, $month - 1, $year) + 25 * 3600); $montH++; $yeaR += 1900; $page{next} = {year => $yeaR, month => $montH, day => $daY}; $page{up} = {year => $year, month => $month}; (undef, undef, undef, $Day, $Month, $Year) = gmtime (Time::Local::timegm_nocheck (0,0,0,$day, $month - 1, $year) - 7 * 24 * 3600); $Month++; $Year += 1900; $page{'prev-week'} = {year => $Year, month => $Month, day => $Day}; (undef, undef, undef, $daY, $montH, $yeaR) = gmtime (Time::Local::timegm_nocheck (0,0,0,$day, $month - 1, $year) + 7 * 25 * 3600); $montH++; $yeaR += 1900; $page{'next-week'} = {year => $yeaR, month => $montH, day => $daY}; } elsif ($month) { ## 2003-04 ($Year, $Month) = ($year, $month - 1); ($Month = 12, $Year--) if $Month == 0; $page{prev} = {year => $Year, month => $Month}; ($yeaR, $montH) = ($year, $month + 1); ($montH = 1, $yeaR++) if $montH == 13; $page{next} = {year => $yeaR, month => $montH}; $page{up} = {year => $year}; } else { ## 2003 $Year = $year - 1; $page{prev} = {year => $Year}; $yeaR = $year + 1; $page{next} = {year => $yeaR}; } my @gmtime = gmtime; $page{today} = {year => $gmtime[5] + 1900, month => $gmtime[4] + 1, day => $gmtime[3]}; __ATTRTEXT:%mode__;__ATTRTEXT:%with_lm__;__ATTRTEXT:%up_to_date__; for my $rel (qw/prev next up prev-week next-week today/) { next unless $page{$rel}; $WIKILINKING->to_wikipage_in_html ({ label => qq(%html-link;\n), -ht__alt_description => $WIKIRESOURCE->get (name => 'Calender:Link:'.$rel .($page{$rel}->{day}?':ymd': $page{$rel}->{month}?':ym':':y') .':Description', o => $o, wiki => $o->{wiki}), } => { base => $page, page_name_relative => __FUNCPACK__->date_to_wikiname (base => $date->{base}, o => $o, %{$page{$rel}}), wiki_mode => $p->{mode}, _with_lm => $p->{with_lm}, _up_to_date => $p->{up_to_date}, }, { o => $o, parent => $p->{-parent}, -rel => $rel, -cal__year => $page{$rel}->{year}, -cal__month => $page{$rel}->{month}, -cal__day => $page{$rel}->{day}, }); } Function: @Name: wikiname_to_date @Description: @@@: Return what time is the WikiPage means, if it is part of calender. @@lang: en @Main: my (undef, %opt) = @_; if ($opt{name}->[$#{$opt{name}}] =~ /^([0-9]{4,})(?:-([0-9][0-9])(?:-([0-9][0-9]))?)?$/) { {year => $1, month => $2, day => $3, base => $opt{o}->{wiki}->name ([@{$opt{name}}[0..$#{$opt{name}}-1]])}; } else { {base => $opt{name}}; } Function: @Name: date_to_wikiname @Description: @@@: Generates WikiName from date @@lang: en @Main: my (undef, %opt) = @_; my $date = sprintf '%04d', $opt{year}; if ($opt{month}) { $date .= sprintf '-%02d', $opt{month}; $date .= sprintf '-%02d', $opt{day} if $opt{day}; } my $clone = $opt{base}->clone; $clone->append_component ($date); $clone; ViewFragment: @Template[list]:wr--read-body @Order: -10 @Description: @@@: "Read" mode body -- Calender @@lang:en @Formatting: %if-calender ( month => {%calender;}p, year => {%calender-months;}p, ); ViewFragment: @Template[list]: links @Order: -100 @Description: @@@: Link to previous/next WikiPage in calender @@lang:en @Formatting: %link-calender-date; Resource: @Calender:Day:Label: %link-to-it ( label => {%calender--day;}p, description=>{%page-name(absolute);; %if-linked-wikipage-exist( true=>{%page-headline;}, false=>{(%res(name=>{Link:toWikiPage:NotExist:Description});)}, );}p, class=>{%if-linked-wikipage-exist(false=>{not-exist});}p, ); @Calender:Link:prev:y:Description: %calender--year; (%page-name;) @Calender:Link:next:y:Description: %calender--year; (%page-name;) @Calender:Link:up:y:Description: %calender--year; (%page-name;) @Calender:Link:prev:ym:Description: %calender--year;-%calender--month; (%page-name;) @Calender:Link:next:ym:Description: %calender--year;-%calender--month; (%page-name;) @Calender:Link:up:ym:Description: %calender--year;-%calender--month; (%page-name;) @Calender:Link:prev:ymd:Description: %calender--year;-%calender--month;-%calender--day; (%page-name;) @Calender:Link:next:ymd:Description: %calender--year;-%calender--month;-%calender--day; (%page-name;) @Calender:Link:prev-week:ymd:Description: %calender--year;-%calender--month;-%calender--day; (%page-name;) @Calender:Link:next-week:ymd:Description: %calender--year;-%calender--month;-%calender--day; (%page-name;) @Calender:Link:today:ymd:Description: @@@: Today's WikiPage (%page-name;) @@lang: en @Calender:MonthList:Item: %link-to-it ( label => {%calender--month;}p, description=>{%page-name(absolute);; %if-linked-wikipage-exist( true=>{%page-headline;}, false=>{(%res(name=>{Link:toWikiPage:NotExist:Description});)}, );}p, class=>{%if-linked-wikipage-exist(false=>{not-exist});}p, ); @Calender:Table:Caption: %link-to-wikipage ( label => {%percent;link-to-it (label => {%calender--year;});}p, page => {%cal--year-page;}p, rel => {up up}, );-%link-to-wikipage ( label => {%percent;link-to-it (label => {%calender--month;});}p, page => {%cal--month-page;}p, rel => {up}, ); @Calender:Table:Summary: @@@: A calender. Days are listed with columns assigned to days in week (i.e. Sunday, Monday, ..., and Saturday) @@lang: en @Calender:Weekday:Long:sun: @@@: Sunday @@lang: en @Calender:Weekday:Long:mon: @@@: Monday @@lang: en @Calender:Weekday:Long:tue: @@@: Tuesday @@lang: en @Calender:Weekday:Long:wed: @@@: Wednesday @@lang: en @Calender:Weekday:Long:thu: @@@: Thursday @@lang: en @Calender:Weekday:Long:fri: @@@: Friday @@lang: en @Calender:Weekday:Long:sat: @@@: Saturday @@lang: en @Calender:Weekday:Short:sun: @@@: Sun @@lang: en @Calender:Weekday:Short:mon: @@@: Mon @@lang: en @Calender:Weekday:Short:tue: @@@: Tue @@lang: en @Calender:Weekday:Short:wed: @@@: Wed @@lang: en @Calender:Weekday:Short:thu: @@@: Thu @@lang: en @Calender:Weekday:Short:fri: @@@: Fri @@lang: en @Calender:Weekday:Short:sat: @@@: Sat @@lang: en @Calender:Weekday:Label:sun: %abbr ( short => {%res (name => {Calender:Weekday:Short:sun});}p, long => {%res (name => {Calender:Weekday:Long:sun});}p, ); @Calender:Weekday:Label:mon: %abbr ( short => {%res (name => {Calender:Weekday:Short:mon});}p, long => {%res (name => {Calender:Weekday:Long:mon});}p, ); @Calender:Weekday:Label:tue: %abbr ( short => {%res (name => {Calender:Weekday:Short:tue});}p, long => {%res (name => {Calender:Weekday:Long:tue});}p, ); @Calender:Weekday:Label:wed: %abbr ( short => {%res (name => {Calender:Weekday:Short:wed});}p, long => {%res (name => {Calender:Weekday:Long:wed});}p, ); @Calender:Weekday:Label:thu: %abbr ( short => {%res (name => {Calender:Weekday:Short:thu});}p, long => {%res (name => {Calender:Weekday:Long:thu});}p, ); @Calender:Weekday:Label:fri: %abbr ( short => {%res (name => {Calender:Weekday:Short:fri});}p, long => {%res (name => {Calender:Weekday:Long:fri});}p, ); @Calender:Weekday:Label:sat: %abbr ( short => {%res (name => {Calender:Weekday:Short:sat});}p, long => {%res (name => {Calender:Weekday:Long:sat});}p, );