<?php
-/*
- * PukiWiki calendar_viewer plugin
- * $Id: calendar_viewer.inc.php,v 1.28 2004/12/30 09:40:39 henoheno Exp $
- * Based on calendar and recent plugin
+// PukiWiki - Yet another WikiWikiWeb clone
+// calendar_viewer.inc.php
+// Copyright 2002-2021 PukiWiki Development Team
+// License: GPL v2 or (at your option) any later version
+//
+// Calendar viewer plugin - List pages that calendar/calnedar2 plugin created
+// (Based on calendar and recent plugin)
+
+// Page title's date format
+// * See PHP date() manual for detail
+// * '$\w' = weeklabel defined in $_msg_week
+define('PLUGIN_CALENDAR_VIEWER_DATE_FORMAT',
+ // FALSE // 'pagename/2004-02-09' -- As is
+ // 'D, d M, Y' // 'Mon, 09 Feb, 2004'
+ // 'F d, Y' // 'February 09, 2004'
+ // '[Y-m-d]' // '[2004-02-09]'
+ 'Y/n/j ($\w)' // '2004/2/9 (Mon)'
+ );
+/**
+ * Limit of show count per pagename
*/
+define('PLUGIN_CALENDAR_VIEWER_MAX_SHOW_COUNT', 4);
+
+// ----
+define('PLUGIN_CALENDAR_VIEWER_USAGE',
+ '#calendar_viewer(pagename,this|yyyy-mm|n|x*y[,mode[,separater]])');
/*
- * ³µÍ×
- * calendar¥×¥é¥°¥¤¥ó¤äcalendar2¥×¥é¥°¥¤¥ó¤ÇºîÀ®¤·¤¿¥Ú¡¼¥¸¤ò°ìÍ÷ɽ¼¨¤¹¤ë¤¿¤á¤Î¥×¥é¥°¥¤¥ó¤Ç¤¹¡£
- * »È¤¤Êý
- * #calendar_viewer(pagename,(this|yyyy-mm|n|x*y),[mode],[separater])
- *
** pagename
- * - calendar or calendar2¥×¥é¥°¥¤¥ó¤òµ½Ò¤·¤Æ¤ë¥Ú¡¼¥¸Ì¾
+ * - A working root of calendar or calendar2 plugin
+ * pagename/2004-12-30
+ * pagename/2004-12-31
+ * ...
*
** (yyyy-mm|n|this)
- * this - º£·î¤Î¥Ú¡¼¥¸¤ò°ìÍ÷ɽ¼¨
- * yyyy-mm - yyyy-mm¤Ç»ØÄꤷ¤¿Ç¯·î¤Î¥Ú¡¼¥¸¤ò°ìÍ÷ɽ¼¨
- * n - ÀèƬ¤«¤én·ï¤ò°ìÍ÷ɽ¼¨
- * x*n - ÀèƬ¤è¤ê¿ô¤¨¤Æ x ¥Ú¡¼¥¸ÌÜ(ÀèƬ¤Ï0)¤«¤é¡¢y·ï¤Å¤Ä°ìÍ÷ɽ¼¨
+ * this - Show 'this month'
+ * yyyy-mm - Show pages at year:yyyy and month:mm
+ * n - Show first n pages
+ * x*n - Show first n pages from x-th page (0 = first)
*
** [mode]
- * Default:past
- * past - º£Æü°ÊÁ°¤Î¥Ú¡¼¥¸¤Î°ìÍ÷ɽ¼¨¥â¡¼¥É¡£¹¹¿·ÍúÎò¤äÆüµ¸þ¤
- * future - º£Æü°Ê¹ß¤Î¥Ú¡¼¥¸¤Î°ìÍ÷ɽ¼¨¥â¡¼¥É¡£¥¤¥Ù¥ó¥ÈͽÄê¤ä¥¹¥±¥¸¥å¡¼¥ë¸þ¤
- * view - ²áµî¤«¤é̤Íè¤Ø¤Î°ìÍ÷ɽ¼¨¥â¡¼¥É¡£É½¼¨Í޻ߤ¹¤ë¥Ú¡¼¥¸¤Ï¤¢¤ê¤Þ¤»¤ó
+ * past - Show today, and the past below. Recommended for ChangeLogs and diaries (default)
+ * future - Show today, and the future below. Recommended for event planning and scheduling
+ * view - Show all, from the past to the future
*
** [separater]
- * - ǯ·îÆü¤ò¶èÀڤ륻¥Ñ¥ì¡¼¥¿¤ò»ØÄê¡£
- * - ¾Êά²Äǽ¡£¥Ç¥Õ¥©¥ë¥È¤Ï-¡£¡Êcalendar2¤Ê¤é¾Êά¤ÇOK¡Ë
+ * - Specify separator of yyyy/mm/dd
+ * - Default: '-' (yyyy-mm-dd)
*
* TODO
- * past or future ¤Ç·îñ°Ìɽ¼¨¤¹¤ë¤È¤¤Ë¡¢¤½¤ì¤¾¤ìÍè·î¡¢Àè·î¤Î°ìÍ÷¤Ø¤Î¥ê¥ó¥¯¤òɽ¼¨¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë
+ * Stop showing links 'next month' and 'previous month' with past/future mode for 'this month'
+ * #calendar_viewer(pagename,this,past)
*/
function plugin_calendar_viewer_convert()
{
- global $vars, $get, $post, $script;
- global $_err_calendar_viewer_param, $_err_calendar_viewer_param2;
+ global $vars, $get, $post, $weeklabels;
global $_msg_calendar_viewer_right, $_msg_calendar_viewer_left;
- global $_msg_calendar_viewer_restrict;
+ global $_msg_calendar_viewer_restrict, $_err_calendar_viewer_param2;
- static $viewed = array();
+ static $show_count = array();
if (func_num_args() < 2)
- return '#calendar_viewer(): ' . $_err_calendar_viewer_param . '<br />' . "\n";
+ return PLUGIN_CALENDAR_VIEWER_USAGE . '<br />' . "\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¤Ê¤é ''
+ $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Æüʬɽ¼¨
+ // 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·ï¤Å¤Äɽ¼¨
+ // 先頭より数えて x ページ目から、y件づつ表示
$limit_base = $matches[1];
$limit_pitch = $matches[2];
- $limit_page = $matches[1] + $matches[2]; // ÆɤßÈô¤Ð¤¹ + ɽ¼¨¤¹¤ë
+ $limit_page = $matches[1] + $matches[2]; // 読み飛ばす + 表示する
} else {
return '#calendar_viewer(): ' . $_err_calendar_viewer_param2 . '<br />' . "\n";
}
if (isset($func_args[3])) $date_sep = $func_args[3];
// Avoid Loop etc.
- if (isset($viewed[$pagename])) {
- $s_page = htmlspecialchars($pagename);
- return "#calendar_viewer(): You already view: $s_page<br />";
- } else {
- $viewed[$pagename] = TRUE; // Valid
+ if (!isset($show_count[$pagename])) {
+ $show_count[$pagename] = 0;
}
-
- // °ìÍ÷ɽ¼¨¤¹¤ë¥Ú¡¼¥¸Ì¾¤È¥Õ¥¡¥¤¥ë̾¤Î¥Ñ¥¿¡¼¥ó¡¡¥Õ¥¡¥¤¥ë̾¤Ë¤Ïǯ·î¤ò´Þ¤à
- if ($pagename == '') {
- // pagename̵¤·¤Îyyyy-mm-dd¤ËÂбþ¤¹¤ë¤¿¤á¤Î½èÍý
- $pagepattern = '';
- $pagepattern_len = 0;
- $filepattern = encode($page_YM);
- $filepattern_len = strlen($filepattern);
+ $show_count[$pagename] += 1;
+ if ($show_count[$pagename] > PLUGIN_CALENDAR_VIEWER_MAX_SHOW_COUNT) {
+ $s_page = htmlsc($pagename);
+ return "#calendar_viewer(): Exceeded the limit of show count: $s_page<br />";
+ }
+ // page name pattern
+ $simple_pagename = strip_bracket($pagename);
+ if ($pagename === '') {
+ // Support non-pagename yyyy-mm-dd pattern
+ $pagepattern = $page_YM;
+ $page_datestart_idx = 0;
} else {
- $pagepattern = strip_bracket($pagename) . '/';
- $pagepattern_len = strlen($pagepattern);
- $filepattern = encode($pagepattern . $page_YM);
- $filepattern_len = strlen($filepattern);
+ $pagepattern = $simple_pagename . '/' . $page_YM;
+ $page_datestart_idx = strlen($simple_pagename) + 1;
}
-
- // ¥Ú¡¼¥¸¥ê¥¹¥È¤Î¼èÆÀ
+ $pagepattern_len = strlen($pagepattern);
+ // Get pagelist
$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;
+ $_date = get_date('Y' . $date_sep . 'm' . $date_sep . 'd');
+ foreach (get_existpages() as $page) {
+ if (strncmp($page, $pagepattern, $pagepattern_len) !== 0) continue;
+ $page_date = substr($page, $page_datestart_idx);
+ // 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); // New => Old
+ rsort($pagelist, SORT_STRING); // New => Old
} else {
- sort($pagelist); // Old => New
+ sort($pagelist, SORT_STRING); // Old => New
}
-
// Include start
$tmppage = $vars['page'];
$return_body = '';
- // $limit_page ¤Î·ï¿ô¤Þ¤Ç¥¤¥ó¥¯¥ë¡¼¥É
+ // $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);
}
+ if (PLUGIN_CALENDAR_VIEWER_DATE_FORMAT !== FALSE) {
+ $time = strtotime(basename($page)); // $date_sep must be assumed '-' or ''!
+ if ($time === FALSE || $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);
+ }
- $r_page = rawurlencode($page);
- $s_page = htmlspecialchars($page);
- $link = '<a href="' . $script . '?cmd=edit&page=' . $r_page . '">' . $s_page . '</a>';
- $head = '<h1>' . $link . '</h1>' . "\n";
+ if (PKWK_READONLY) {
+ $link = get_page_uri($page);
+ } else {
+ $link = get_base_uri() . '?cmd=edit&page=' . pagename_urlencode($page);
+ }
+ $link_html = '<a href="' . $link . '">' . $s_page . '</a>';
+ $head = '<h1>' . $link_html . '</h1>' . "\n";
$return_body .= $head . $body;
-
++$tmp;
}
- // ¤³¤³¤Ç¡¢Á°¸å¤Î¥ê¥ó¥¯¤òɽ¼¨
- // ?plugin=calendar_viewer&file=¥Ú¡¼¥¸Ì¾&date=yyyy-mm
- $enc_pagename = rawurlencode(substr($pagepattern, 0, $pagepattern_len - 1));
-
+ // ここで、前後のリンクを表示
+ // ?plugin=calendar_viewer&file=ページ名&date=yyyy-mm
if ($page_YM != '') {
- // ǯ·îɽ¼¨»þ
+ // 年月表示時
$date_sep_len = strlen($date_sep);
$this_year = substr($page_YM, 0, 4);
$this_month = substr($page_YM, 4 + $date_sep_len, 2);
- // ¼¡·î
+ // 次月
$next_year = $this_year;
$next_month = $this_month + 1;
if ($next_month > 12) {
}
$next_YM = sprintf('%04d%s%02d', $next_year, $date_sep, $next_month);
- // Á°·î
+ // 前月
$prev_year = $this_year;
$prev_month = $this_month - 1;
if ($prev_month < 1) {
$right_text = $next_YM . '>>'; // >>
}
} else {
- // n·ïɽ¼¨»þ
+ // n件表示時
if ($limit_base <= 0) {
- $left_YM = ''; // ɽ¼¨¤·¤Ê¤¤ (¤½¤ì¤è¤êÁ°¤Î¹àÌܤϤʤ¤)
+ $left_YM = ''; // 表示しない (それより前の項目はない)
} else {
$left_YM = $limit_base - $limit_pitch . '*' . $limit_pitch;
$left_text = sprintf($_msg_calendar_viewer_left, $limit_pitch);
}
if ($limit_base + $limit_pitch >= count($pagelist)) {
- $right_YM = ''; // ɽ¼¨¤·¤Ê¤¤ (¤½¤ì¤è¤ê¸å¤Î¹àÌܤϤʤ¤)
+ $right_YM = ''; // 表示しない (それより後の項目はない)
} else {
$right_YM = $limit_base + $limit_pitch . '*' . $limit_pitch;
$right_text = sprintf($_msg_calendar_viewer_right, $limit_pitch);
}
}
- // ¥Ê¥Ó¥²¡¼¥ÈÍѤΥê¥ó¥¯¤òËöÈø¤ËÄɲÃ
+ // ナビゲート用のリンクを末尾に追加
if ($left_YM != '' || $right_YM != '') {
- $s_date_sep = htmlspecialchars($date_sep);
+ $s_date_sep = htmlsc($date_sep);
$left_link = $right_link = '';
- $link = $script . '?plugin=calendar_viewer&mode=' . $mode .
- '&file=' . $enc_pagename . '&date_sep=' . $s_date_sep . '&';
+ $link = get_base_uri() . '?plugin=calendar_viewer&mode=' . $mode .
+ '&file=' . rawurlencode($simple_pagename) .
+ '&date_sep=' . $s_date_sep . '&';
if ($left_YM != '')
$left_link = '<a href="' . $link .
'date=' . $left_YM . '">' . $left_text . '</a>';
if ($right_YM != '')
$right_link = '<a href="' . $link .
'date=' . $right_YM . '">' . $right_text . '</a>';
- // past mode¤Ï<<¿· µì>> ¾¤Ï<<µì ¿·>>
+ // past modeは<<新 旧>> 他は<<旧 新>>
$return_body .=
- '<table width ="100%"><tr>' .
- '<td align="left">' . $left_link . '</td>' .
- '<td align="right">' . $right_link . '</td>' .
- '</tr></table>';
+ '<div class="calendar_viewer">' .
+ '<span class="calendar_viewer_left">' . $left_link . '</span>' .
+ '<span class="calendar_viewer_right">' . $right_link . '</span>' .
+ '</div>';
}
$get['page'] = $post['page'] = $vars['page'] = $tmppage;
function plugin_calendar_viewer_action()
{
- global $vars, $get, $post, $script;
+ global $vars, $get, $post;
$date_sep = '-';
$return_vars_array['body'] = call_user_func_array('plugin_calendar_viewer_convert', $args_array);
//$return_vars_array['msg'] = 'calendar_viewer ' . $vars['page'] . '/' . $page_YM;
- $return_vars_array['msg'] = 'calendar_viewer ' . htmlspecialchars($vars['page']);
+ $return_vars_array['msg'] = 'calendar_viewer ' . htmlsc($vars['page']);
if ($vars['page'] != '') $return_vars_array['msg'] .= '/';
if (preg_match('/\*/', $page_YM)) {
- // ¤¦¡¼¤ó¡¢n·ïɽ¼¨¤Î»þ¤Ï¤Ê¤ó¤Æ¥Ú¡¼¥¸Ì¾¤Ë¤·¤¿¤é¤¤¤¤¡©
+ // うーん、n件表示の時はなんてページ名にしたらいい?
} else {
- $return_vars_array['msg'] .= htmlspecialchars($page_YM);
+ $return_vars_array['msg'] .= htmlsc($page_YM);
}
$vars['page'] = $page;
{
$matches = array();
if ($aSepList == '') {
- // yyymmdd¤È¤·¤Æ¥Á¥§¥Ã¥¯¡Ê¼êÈ´¤(^^;¡Ë
+ // yyymmddとしてチェック(手抜き(^^;)
return checkdate(substr($aStr, 4, 2), substr($aStr, 6, 2), substr($aStr, 0, 4));
- } else if (ereg("^([0-9]{2,4})[$aSepList]([0-9]{1,2})[$aSepList]([0-9]{1,2})$", $aStr, $matches) ) {
+ } else if (preg_match("#^([0-9]{2,4})[$aSepList]([0-9]{1,2})[$aSepList]([0-9]{1,2})$#", $aStr, $matches) ) {
return checkdate($matches[2], $matches[3], $matches[1]);
} else {
return FALSE;
}
}
-
-?>