Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
PukiWiki の calendar_view plugin の中で block level plugin を無視するパッチ
diff --git a/plugin/calendar_viewer.inc.php b/plugin/calendar_viewer.inc.php
index cafc33b..874d899 100644
--- a/plugin/calendar_viewer.inc.php
+++ b/plugin/calendar_viewer.inc.php
@@ -68,6 +68,7 @@ function plugin_calendar_viewer_convert()
$limit_page = 0; // サーチするページ数
$mode = 'past'; // 動作モード
$date_sep = '-'; // 日付のセパレータ calendar2なら '-', calendarなら ''
+ $ignore_blockplugin = false;
// Check $func_args[1]
$matches = array();
@@ -99,6 +100,11 @@ function plugin_calendar_viewer_convert()
// $func_args[3]: Change default delimiter
if (isset($func_args[3])) $date_sep = $func_args[3];
+ if ($func_args[4]) {
+ $ignore_blockplugin = true;
+ }
+
+
// Avoid Loop etc.
if (isset($viewed[$pagename])) {
$s_page = htmlspecialchars($pagename);
@@ -166,7 +172,11 @@ function plugin_calendar_viewer_convert()
// 現状で閲覧許可がある場合だけ表示する
if (check_readable($page, FALSE, FALSE)) {
+ if ( $ignore_blockplugin ) {
+ $body = convert_html(strip_blockplugin(get_source($page)));
+ } else {
$body = convert_html(get_source($page));
+ }
} else {
$body = str_replace('$1', $page, $_msg_calendar_viewer_restrict);
}
@@ -263,6 +273,9 @@ function plugin_calendar_viewer_convert()
$left_link = $right_link = '';
$link = $script . '?plugin=calendar_viewer&mode=' . $mode .
'&file=' . $enc_pagename . '&date_sep=' . $s_date_sep . '&';
+ if ( $ignore_blockplugin ) {
+ $link .= 'ignore_blockplugin&';
+ }
if ($left_YM != '')
$left_link = '<a href="' . $link .
'date=' . $left_YM . '">' . $left_text . '</a>';
@@ -300,7 +313,8 @@ function plugin_calendar_viewer_action()
if ($page_YM == '') $page_YM = get_date('Y' . $date_sep . 'm');
$mode = $vars['mode'];
- $args_array = array($vars['page'], $page_YM, $mode, $date_sep);
+ $ignore_blockplugin = isset( $vars['ignore_blockplugin'] );
+ $args_array = array($vars['page'], $page_YM, $mode, $date_sep, $ignore_blockplugin);
$return_vars_array['body'] = call_user_func_array('plugin_calendar_viewer_convert', $args_array);
//$return_vars_array['msg'] = 'calendar_viewer ' . $vars['page'] . '/' . $page_YM;
@@ -328,4 +342,18 @@ function plugin_calendar_viewer_isValidDate($aStr, $aSepList = '-/ .')
return FALSE;
}
}
-?>
+
+/**
+ * free block level plugin
+ *
+ * @param array $src Wiki source
+ */
+function strip_blockplugin( $src ) {
+ $result = array();
+ foreach ( $src as $line ) {
+ if ( !preg_match( '/^#/', $line ) ) {
+ array_push( $result, $line );
+ }
+ }
+ return $result;
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment