function plugin_calendar_convert() { global $vars, $post, $get, $_labels; //global $_calendar_plugin_edit, $_calendar_plugin_empty; global $_calendar_msg; if (!isset($vars['page'])) { return ''; } /* from Plus! */ $today_view = TRUE; $today_args = 'view'; $date_str = Time::getZoneTimeDate('Ym'); $base = Utility::stripBracket($vars['page']); $today_view = TRUE; if (func_num_args() > 0) { $args = func_get_args(); foreach ($args as $arg) { if (is_numeric($arg) && strlen($arg) == 6) { $date_str = $arg; } else { if ($arg == 'off') { $today_view = FALSE; } else { if ($arg == 'past' || $arg == 'pastex' || $arg == 'future' || $arg == 'futureex' || $arg == 'view' || $arg == 'viewex') { /* from Plus! */ $today_args = $arg; } else { $base = Utility::stripBracket($arg); } } } } } if ($base == '*') { $base = ''; $prefix = ''; } else { $prefix = $base . '/'; } $s_base = Utility::htmlsc($base); $s_prefix = Utility::htmlsc($prefix); $yr = substr($date_str, 0, 4); $mon = substr($date_str, 4, 2); if ($yr != get_date('Y') || $mon != get_date('m')) { $now_day = 1; $other_month = 1; } else { $now_day = get_date('d'); $other_month = 0; } $today = getdate(mktime(0, 0, 0, $mon, $now_day, $yr)); $m_num = $today['mon']; $d_num = $today['mday']; $year = $today['year']; $f_today = getdate(mktime(0, 0, 0, $m_num, 1, $year)); $wday = $f_today['wday']; $day = 1; $m_name = Time::format($today[0], false, $_calendar_msg['_calendar_title_format']); $y = substr($date_str, 0, 4) + 0; $m = substr($date_str, 4, 2) + 0; $format = '%04d%02d'; $prev_link = Router::get_cmd_uri('calendar', '', '', array('file' => $base, 'mode' => $today_args, 'date' => $m == 1 ? sprintf($format, $y - 1, 12) : sprintf($format, $y, $m - 1))); $next_link = Router::get_cmd_uri('calendar', '', '', array('file' => $base, 'mode' => $today_args, 'date' => $m == 12 ? sprintf($format, $y + 1, 1) : sprintf($format, $y, $m + 1))); $this_date_str = sprintf($format, $y, $m); $page_YM = sprintf('%04d-%02d', $y, $m); $ret = ''; if ($today_view === TRUE) { $ret .= '<div class="clearfix">' . "\n" . '<div class="style_calendar_viewer">' . "\n"; // カレンダーのdivタグ($today_view有効時のみ出力) } $ret .= <<<EOD <table class="table table-bordered style_calendar" summary="calendar" data-sortable="false"> \t<thead> \t\t<tr> \t\t\t<td class="style_calendar_top" colspan="7"> \t\t\t\t<nav> \t\t\t\t\t<ul class="style_calendar_navi"> \t\t\t\t\t\t<li class="style_calendar_prev"><a href="{$prev_link}"><<</a></li> \t\t\t\t\t\t<li class="style_calendar_title"><strong>{$m_name}</strong></li> \t\t\t\t\t\t<li class="style_calendar_next"><a href="{$next_link}">>></a></li> \t\t\t\t\t</ul> \t\t\t\t</nav> EOD; if ($vars['cmd'] == 'calendar' || $vars['cmd'] == 'calendar_viewer') { $base_link = Factory::Wiki($base)->uri(); } else { $base_link = Router::get_cmd_uri('calendar', '', '', array('file' => $base, 'mode' => $today_args, 'date' => sprintf($format, $y, $m))); } if ($prefix) { $ret .= "\n" . ' [<a href="' . $base_link . '">' . $s_base . '</a>]'; } $ret .= "\n" . ' </td>' . "\n" . ' </tr>' . "\n" . ' </thead>' . "\n" . ' <tbody>' . "\n" . ' <tr>' . "\n"; for ($i = 0; $i < 7; $i++) { if ($i == 0) { $class = 'week_sun'; } else { if ($i == 6) { $class = 'week_sat'; } else { $class = 'week_day'; } } $ret .= ' <th class="style_calendar_week"><abbr title="' . $_labels['week'][$i][1] . '" class="' . $class . '">' . $_labels['week'][$i][0] . '</abbr></th>' . "\n"; } unset($i, $class); $ret .= ' </tr>' . "\n" . ' <tr>' . "\n"; // Blank for ($i = 0; $i < $wday; $i++) { $ret .= ' <td class="blank-cell"></td>' . "\n"; } while (checkdate($m_num, $day, $year)) { $dt = sprintf(PLUGIN_CALENDAR_PAGENAME_FORMAT, $year, $m_num, $day); $page = $prefix . $dt; $s_page = Utility::htmlsc($page); $wiki = Factory::Wiki($page); if ($wday == 0 && $day > 1) { $ret .= ' </tr>' . "\n" . ' <tr>' . "\n"; } /* from Plus! */ $h_today = PublicHolidayFactory::factory('JP', $year, $m_num, $day); $hday = $h_today['rc']; $style = 'style_calendar_day'; // Weekday if (!$other_month && $day == $today['mday'] && $m_num == $today['mon'] && $year == $today['year']) { // Today $style = 'style_calendar_today'; } else { if ($hday !== 0) { // Holiday $style = 'style_calendar_holiday'; } else { if ($wday == 0) { // Sunday $style = 'style_calendar_sun'; } else { if ($wday == 6) { // Saturday $style = 'style_calendar_sat'; } } } } if ($wiki->has()) { $link = '<a href="' . $wiki->uri() . '" title="' . $s_page . '"><strong>' . $day . '</strong></a>'; } else { if (PKWK_READONLY) { $link = $day; } else { $link = '<a href="' . $wiki->uri('edit', array('refer' => $base)) . '" title="' . $s_page . '" rel="nofollow">' . $day . '</a>'; } } $ret .= '<td class="style_td ' . $style . '">' . $link . '</td>' . "\n"; ++$day; $wday = ++$wday % 7; } if ($wday > 0) { while ($wday++ < 7) { // Blank $ret .= '<td class="style_td_blank"></td>' . "\n"; } } $ret .= '</tr>' . "\n" . '</tbody>' . "\n" . '</table>' . "\n"; if ($today_view) { $ret .= '</div>' . "\n"; // カレンダーのdivタグを閉じる $ret .= '<section class="style_calendar_post">' . "\n"; if ($today_args == '') { $str = '<article id="' . $tpage . '" class="style_calendar_post">' . "\n"; $tpage = $prefix . sprintf(PLUGIN_CALENDAR_PANENAME_FORMAT, $today['year'], $today['mon'], $today['mday']); $t_wiki = Factory::Wiki($tpage); if ($t_wiki->has()) { $_page = $vars['page']; $get['page'] = $post['page'] = $vars['page'] = $tpage; preg_replace('/^#navi/', '/\\/\\/#navi/', $source); $str .= $t_wiki->render(); $str .= '<hr /><a href="' . $t_wiki->uri('edit', $tpage) . '">' . $_calendar_msg['_edit'] . '</a>'; $get['page'] = $post['page'] = $vars['page'] = $_page; } else { $str .= sprintf($_calendar_msg['_empty'], make_pagelink($prefix . sprintf(PLUGIN_CALENDAR_PANENAME_FORMAT, $today['year'], $today['mon'], $today['mday']))); } $str .= '</article>' . "\n"; } else { $aryargs = array(rawurldecode($base), $page_YM, $today_args); if (exist_plugin('calendar_viewer')) { T_bindtextdomain('calendar_viewer', LANG_DIR); T_textdomain('calendar_viewer'); $str = call_user_func_array('plugin_calendar_viewer_convert', $aryargs); T_textdomain('calendar'); } } $ret .= $str . "\n"; $ret .= '</section>' . "\n"; $ret .= '</div>' . "\n"; } return $ret; }
function plugin_calendar_viewer_convert() { global $vars, $get, $post, $_labels; // global $_msg_calendar_viewer_right, $_msg_calendar_viewer_left; // global $_msg_calendar_viewer_restrict, $_err_calendar_viewer_param2; global $_symbol_paraedit, $trackback; $_calendar_viewer_msg = array('_err_param2' => T_('Wrong second parameter.'), '_msg_right' => T_('Next %d >>'), '_msg_left' => T_('<< Prev %d'), '_msg_restrict' => T_('Due to the blocking, the calendar_viewer cannot refer to $1.'), '_title_format' => T_('%1s, %2s %3s %4s')); if (!isset($vars['page'])) { return ''; } static $viewed = array(); if (func_num_args() < 2) { 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なら '' // 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(): ' . $_calendar_viewer_msg['_err_param2'] . '<br />' . "\n"; } } } } // $func_args[2]: Mode setting if (isset($func_args[2]) && preg_match('/^(past|pastex|view|viewex|future|futureex)$/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])) { if ($viewed[$pagename] > PLUGIN_CALENDAR_MAX_VIEWS) { $s_page = htmlsc($pagename); return '#calendar_viewer(): You already view: ' . $s_page . '<br />'; } $viewed[$pagename]++; // Valid } else { $viewed[$pagename] = 1; // 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' || $page_date >= $_date && $mode == 'pastex' || $page_date <= $_date && $mode == 'futureex') { continue; } $pagelist[] = $page; } } closedir($dir); if ($mode == 'past' || $mode == 'pastex' || $mode == 'viewex') { 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; $wiki = Factory::Wiki($page); // 現状で閲覧許可がある場合だけ表示する if ($wiki->isReadable()) { if (function_exists('convert_filter')) { $body = RendererFactory::factory(convert_filter($wiki->get())); } else { $body = $wiki->render(); } } else { $body = str_replace('$1', $page, $_calendar_viewer_msg['_msg_restrict']); } 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 = $_labels['week'][date('w', $time)][0]; $month = $_labels['month'][preg_replace('/^0/', '', date('m', $time))][0]; $s_page = htmlsc(str_replace(array('$w', '$m'), array($week, $month), date(PLUGIN_CALENDAR_VIEWER_DATE_FORMAT, $time))); } } else { $s_page = htmlsc($page); } // if (PKWK_READONLY) { if (Auth::check_role('readonly')) { $link = get_page_uri($page); } else { $link = get_cmd_uri('edit', $page, '', array('page' => $page)); } $link = '<a class="anchor_super" href="' . $link . '">' . $_symbol_paraedit . '</a>'; $head = '<h1>' . $s_page . $link . '</h1>' . "\n"; $page_title = basepagename($page); $tail = ''; if (PLUGIN_CALENDAR_VIEWER_HOLIDAYVIEW === TRUE) { $time = strtotime($page_title); if ($time != -1) { $yy = intval(date('Y', $time)); $mm = intval(date('n', $time)); $dd = intval(date('d', $time)); $h_today = PublicHolidayFactory::factory('JP', $yy, $mm, $dd); if ($h_today['rc'] != 0) { $classname = 'date_holiday'; $weekclass = 'week_sun'; } else { switch ($h_today['w']) { case 0: $classname = 'date_holiday'; $weekclass = 'week_sun'; break; case 6: $classname = 'date_weekend'; $weekclass = 'week_sat'; default: $classname = 'date_weekday'; $weekclass = 'week_day'; break; } } } } if (PLUGIN_CALENDAR_VIEWER_COMMENT === TRUE) { if (is_page(':config/plugin/addline/comment') && exist_plugin_inline('addline')) { $comm = RendererFactory::factory(array('&addline(comment,above){comment};')); $comm = preg_replace(array("'<p>'si", "'</p>'si"), array("", ""), $comm); $tail .= str_replace('>comment', '><img src="' . IMAGE_URI . 'plus/comment.png" width="15" height="15" alt="Comment" title="Comment" />Comment', $comm); } } if (PLUGIN_CALENDAR_VIEWER_TRACKBACK === TRUE && $trackback) { $tb_link = get_cmd_uri('tb', '', '', array('__mode' => 'view', 'tb_id' => tb_get_id($page))); $tail .= '<a class="pkwk-icon_linktext cmd-trackback" href="' . $tb_link . '">' . 'Trackback(' . tb_count($page) . ')' . '</a>' . "\n"; } $page_id = str_replace('/', '_', $page); $return_body .= '<article id="' . $page_id . '">' . "\n"; $return_body .= $head . $body; $return_body .= '</article>' . "\n"; ++$tmp; } // ここで、前後のリンクを表示 // ?plugin=calendar_viewer&file=ページ名&date=yyyy-mm $page = substr($pagepattern, 0, $pagepattern_len - 1); $r_page = rawurlencode($page); 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_year; $next_month = 1; } $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) { --$prev_year; $prev_month = 12; } $prev_YM = sprintf('%04d%s%02d', $prev_year, $date_sep, $prev_month); if ($mode == 'past') { $right_YM = $prev_YM; $right_text = $prev_YM . '>>'; // >> $left_YM = $next_YM; $left_text = '<<' . $next_YM; // << } else { $left_YM = $prev_YM; $left_text = '<<' . $prev_YM; // << $right_YM = $next_YM; $right_text = $next_YM . '>>'; // >> } } else { // n件表示時 if ($limit_base <= 0) { $left_YM = ''; // 表示しない (それより前の項目はない) } else { $left_YM = $limit_base - $limit_pitch . '*' . $limit_pitch; $left_text = sprintf($_calendar_viewer_msg['_msg_left'], $limit_pitch); } if ($limit_base + $limit_pitch >= count($pagelist)) { $right_YM = ''; // 表示しない (それより後の項目はない) } else { $right_YM = $limit_base + $limit_pitch . '*' . $limit_pitch; $right_text = sprintf($_calendar_viewer_msg['_msg_right'], $limit_pitch); } } // ナビゲート用のリンクを末尾に追加 if ($left_YM != '' || $right_YM != '') { $s_date_sep = htmlsc($date_sep); $left_link = $right_link = ''; if ($left_YM != '') { $left_link = '<a href="' . get_cmd_uri('calendar_viewer', '', '', array('mode' => $mode, 'file' => $page, 'date_sep' => $date_sep, 'date' => $left_YM)) . '">' . $left_text . '</a>'; } if ($right_YM != '') { $right_link = '<a href="' . get_cmd_uri('calendar_viewer', '', '', array('mode' => $mode, 'file' => $page, 'date_sep' => $date_sep, 'date' => $right_YM)) . '">' . $right_text . '</a>'; } $center_link = '<a href="' . get_page_uri($page) . '">' . $page . '</a>'; // past modeは<<新 旧>> 他は<<旧 新>> $nav = '<nav class="calendar_viewer_navi">' . "\n"; $nav .= <<<EOD <ul class="navi"> \t<li class="navi_left">{$left_link}</li> \t<li class="navi_none">{$center_link}</li> \t<li class="navi_right">{$right_link}</li> </ul> <hr /> EOD; $nav .= '</nav>' . "\n"; } $get['page'] = $post['page'] = $vars['page'] = $tmppage; return $nav . $return_body; }