サマリ | 表示中のページに対応した月を表示するカレンダー |
---|---|
リビジョン | 080521 |
対応バージョン | 1.4.7 |
投稿者 | tomas3 |
投稿日 | 2008-06-09 (月) 16:33:51 |
calendar2プラグインを日記などで使用していて、カレンダーをmenubarに表示している場合を想定しています。
たとえば、次のようなページがあり、
menubarの中で
#calendar2(日記,off)
とすれば、常にカレンダーが表示できます。 そして、calendar2プラグインの変わりに、本プラグインを使用し、
#autocalendar(日記)
とすると、日記/2008-05-31のページを表示している場合は、2008年5月のカレンダーを、日記/2008-06-01のページを表示しているときは、2008年6月のカレンダーを表示します。
mixiのカレンダーがこうなっていて、日記を順番に見ていくときに便利だと思ったので作成しました。
ファイルが添付できませんので、以下のコードを、pluginフォルダにautocalendar.inc.phpとして保存してください(エンコードに注意願います)
calendar2プラグインをラップするように書いています。グローバル変数&titleを調べて、引数で指定したページの子ページを表示しているとみなせば、年月指定つきでcalendar2プラグインを呼び出します。その他の場合は、そのままcalendar2プラグインを呼び出しています。
<?php //********************************** // autocalendar ver.080521 // by tomas3 // // for calendar2 plugin of Pukiwiki //********************************** //choose calendar2 or minicalendar(Pukiwiki Plus!). define('PLUGIN_AUTOCALENDAR_BASEPLUGIN', 'calendar2'); function plugin_autocalendar_convert() { //プラグイン引数チェック //手抜き。省略されたら、現在のページにするのが普通のはず $args = func_get_args(); if(count($args) != 1) return "<span style=\"color:red\">plugin autocalendar: no target parameter.</span>"; $target = $args[0]; //同じ親か global $title; if(mb_substr($title, 0, mb_strlen($target) + 1) != $target . "/") { // return "debug: 同じ親じゃ無い $target "; } else { //子ページかどうか $sub_title = mb_substr($title, mb_strlen($target) + 1); // return "debug: " . $sub_title; if(false) { //ここのifに、条件を厳しくするコードが入れられます。ex.孫 があるページはダメ //現在は、孫ページがあっても、子ページ名が日付フォーマットと一致していれば動作させる } else { $sub_title = mb_substr($sub_title, 0, mb_strlen("yyyy-mm-")); //日付であるかの確認 1900年から2100年としてある。(yyyy-mm-) if( strlen($sub_title) != mb_strlen($sub_title) || mb_substr($sub_title, 4, 1) != "-" || mb_substr($sub_title, 7, 1) != "-" ) { // return "debug: 'yyyy-mm-*'じゃない $target "; } else { $year = mb_substr($sub_title, 0, 4); $month = mb_substr($sub_title, 5, 2); if( (int) $year < 1900 || (int) $year > 2100 || (int) $month < 1 || (int) $month > 12 ) { // return "debug: 日付のレンジがおかしい $target "; } else { //ここまで来たら、年月を指定するべきときのはず array_push($args, $year . $month); } } } } //一覧表示offオプションを追加してcalendarプラグインを呼び出し。 array_push($args, "off"); return exist_plugin_convert(PLUGIN_AUTOCALENDAR_BASEPLUGIN) ? do_plugin_convert(PLUGIN_AUTOCALENDAR_BASEPLUGIN, csv_implode(',', $args)) : ""; } ?>
GPL(?よくわかりませんが、コピーレフトなやつで)