' . "\n";
$func_args = func_get_args();
// Default values
$pagename = $func_args[0]; // 基準となるページ名
$page_YM = ''; // 一覧表示する年月
$limit_base = 0; // 先頭から数えて何ページ目から表示するか (先頭)
$limit_pitch = 0; // 何件づつ表示するか
$limit_page = 0; // サーチするページ数
$mode = 'past'; // 動作モード
$date_sep = '-'; // 日付のセパレータ calendar2なら '-', calendarなら ''
// Check $func_args[1]
$matches = array();
if (preg_match('/[0-9]{4}' . $date_sep . '[0-9]{2}/', $func_args[1])) {
// 指定年月の一覧表示
$page_YM = $func_args[1];
$limit_page = 31;
} else if (preg_match('/this/si', $func_args[1])) {
// 今月の一覧表示
$page_YM = get_date('Y' . $date_sep . 'm');
$limit_page = 31;
} else if (preg_match('/^[0-9]+$/', $func_args[1])) {
// n日分表示
$limit_pitch = $func_args[1];
$limit_page = $func_args[1];
} else if (preg_match('/(-?[0-9]+)\*([0-9]+)/', $func_args[1], $matches)) {
// 先頭より数えて x ページ目から、y件づつ表示
$limit_base = $matches[1];
$limit_pitch = $matches[2];
$limit_page = $matches[1] + $matches[2]; // 読み飛ばす + 表示する
} else {
return '#calendar_viewer(): ' . $_err_calendar_viewer_param2 . '
' . "\n";
}
// $func_args[2]: Mode setting
if (isset($func_args[2]) && preg_match('/^(past|view|future)$/si', $func_args[2]))
$mode = $func_args[2];
// $func_args[3]: Change default delimiter
if (isset($func_args[3])) $date_sep = $func_args[3];
// Avoid Loop etc.
if (isset($viewed[$pagename])) {
$s_page = htmlsc($pagename);
return "#calendar_viewer(): You already view: $s_page
";
} else {
$viewed[$pagename] = TRUE; // Valid
}
// 一覧表示するページ名とファイル名のパターン ファイル名には年月を含む
if ($pagename == '') {
// pagename無しのyyyy-mm-ddに対応するための処理
$pagepattern = '';
$pagepattern_len = 0;
$filepattern = encode($page_YM);
$filepattern_len = strlen($filepattern);
} else {
$pagepattern = strip_bracket($pagename) . '/';
$pagepattern_len = strlen($pagepattern);
$filepattern = encode($pagepattern . $page_YM);
$filepattern_len = strlen($filepattern);
}
// ページリストの取得
$pagelist = array();
if ($dir = @opendir(DATA_DIR)) {
$_date = get_date('Y' . $date_sep . 'm' . $date_sep . 'd');
$page_date = '';
while($file = readdir($dir)) {
if ($file == '..' || $file == '.') continue;
if (substr($file, 0, $filepattern_len) != $filepattern) continue;
$page = decode(trim(preg_replace('/\.txt$/', ' ', $file)));
$page_date = substr($page, $pagepattern_len);
// Verify the $page_date pattern (Default: yyyy-mm-dd).
// Past-mode hates the future, and
// Future-mode hates the past.
if ((plugin_calendar_viewer_isValidDate($page_date, $date_sep) == FALSE) ||
($page_date > $_date && ($mode == 'past')) ||
($page_date < $_date && ($mode == 'future')))
continue;
$pagelist[] = $page;
}
}
closedir($dir);
if ($mode == 'past') {
rsort($pagelist, SORT_STRING); // New => Old
} else {
sort($pagelist, SORT_STRING); // Old => New
}
// Include start
$tmppage = $vars['page'];
$return_body = '';
// $limit_page の件数までインクルード
$tmp = max($limit_base, 0); // Skip minus
while ($tmp < $limit_page) {
if (! isset($pagelist[$tmp])) break;
$page = $pagelist[$tmp];
$get['page'] = $post['page'] = $vars['page'] = $page;
// 現状で閲覧許可がある場合だけ表示する
if (check_readable($page, FALSE, FALSE)) {
$body = convert_html(get_source($page));
} else {
$body = str_replace('$1', $page, $_msg_calendar_viewer_restrict);
}
$r_page = pagename_urlencode($page);
if (PLUGIN_CALENDAR_VIEWER_DATE_FORMAT !== FALSE) {
$time = strtotime(basename($page)); // $date_sep must be assumed '-' or ''!
if ($time == -1) {
$s_page = htmlsc($page); // Failed. Why?
} else {
$week = $weeklabels[date('w', $time)];
$s_page = htmlsc(str_replace(
array('$w' ),
array($week),
date(PLUGIN_CALENDAR_VIEWER_DATE_FORMAT, $time)
));
}
} else {
$s_page = htmlsc($page);
}
if (PKWK_READONLY) {
$link = $script . '?' . $r_page;
} else {
$link = $script . '?cmd=edit&page=' . $r_page;
}
$link = '' . $s_page . '';
$head = '