function plugin_rewritemap_action() { global $vars; if (empty($vars['page'])) { return; } if (exist_plugin('statichtml')) { $vars['page'] = PluginStatichtml::decode($vars['page']); } $page = plugin_rewritemap_get_pagename($vars['page']); if (is_page($page)) { check_readable($page, true, true); header_lastmod($page); $vars['page'] = $page; return array('msg' => '', 'body' => ''); } $redirect = plugin_rewritemap_get_redirect($page); $nextpage = plugin_rewritemap_get_pagename($redirect); if (is_page($nextpage)) { header('HTTP/1.0 301 Moved Permanently'); header('Location: ' . plugin_rewritemap_url($nextpage)); exit; } else { header('HTTP/1.0 404 Not Found'); exit('404 - Not Found'); } }
function plugin_diff_action() { global $vars, $script; global $layout_pages, $style_name; $editable = edit_auth($page, FALSE, FALSE); if (!$editable) { header("Location: {$script}"); exit; } $page = isset($vars['page']) ? $vars['page'] : ''; check_readable($page, true, true); //レイアウト部品の場合、スタイルを変更する $is_layout = FALSE; if (isset($layout_pages) && isset($layout_pages[$page])) { $style_name = '..'; $is_layout = TRUE; } $action = isset($vars['action']) ? $vars['action'] : ''; switch ($action) { case 'delete': $retval = plugin_diff_delete($page); break; default: $retval = plugin_diff_view($page); break; } return $retval; }
function plugin_skeylist_convert() { global $vars; global $_skeylist_msg; global $referer; if (!$referer) { return ''; } list($page, $max) = func_get_args(); if (empty($page)) { $page = htmlspecialchars($vars['page'], ENT_QUOTES); } check_readable($page, false); $max = empty($max) ? 10 : htmlspecialchars($max, ENT_QUOTES); // $data = tb_get(tb_get_filename($page,'.ref')); $data = ref_get_data($page); if (count($data) == 0) { return ''; } // データ無し $data = skeylist_analysis($data); // 0:検索キー 1:参照カウンタ usort($data, create_function('$a,$b', 'return $b[1] - $a[1];')); $data = skeylist_print($data, $max); return '<div>' . $data . "</div>\n"; }
function plugin_read_action() { global $vars, $_title_invalidwn, $_msg_invalidiwn; $page = isset($vars['page']) ? $vars['page'] : ''; if (is_page($page)) { // ページを表示 check_readable($page, true, true); header_lastmod($page); return array('msg' => '', 'body' => ''); } else { if (!PKWK_SAFE_MODE && is_interwiki($page)) { return do_plugin_action('interwiki'); // InterWikiNameを処理 } else { if (is_pagename($page)) { $vars['cmd'] = 'edit'; return do_plugin_action('edit'); // 存在しないので、編集フォームを表示 } else { // 無効なページ名 return array('msg' => $_title_invalidwn, 'body' => str_replace('$1', htmlsc($page), str_replace('$2', 'WikiName', $_msg_invalidiwn))); } } } }
function plugin_read_action() { global $vars, $_title_invalidwn, $_msg_invalidiwn; $page = isset($vars['page']) ? $vars['page'] : ''; if (is_page($page)) { // ページを表示 check_readable($page, true, true); header_lastmod($page); return array('msg' => '', 'body' => ''); // } else if (! PKWK_SAFE_MODE && is_interwiki($page)) { } else { if (!auth::check_role('safemode') && is_interwiki($page)) { return do_plugin_action('interwiki'); // InterWikiNameを処理 } else { if (is_pagename($page)) { $realpages = get_autoaliases($page); if (count($realpages) == 1) { $realpage = $realpages[0]; if (is_page($realpage)) { header('HTTP/1.0 301 Moved Permanently'); header('Location: ' . get_page_location_uri($realpage)); return; } elseif (is_url($realpage)) { header('HTTP/1.0 301 Moved Permanently'); header('Location: ' . $realpage); return; } elseif (is_interwiki($realpage)) { header('HTTP/1.0 301 Moved Permanently'); $vars['page'] = $realpage; return do_plugin_action('interwiki'); // header('Location'); } else { // 存在しない場合、直接編集フォームに飛ばす // To avoid infinite loop header('Location: ' . get_location_uri('edit', $realpage)); return; } } elseif (count($realpages) >= 2) { $body = '<p>'; $body .= _('This pagename is an alias to') . '<br />'; $link = ''; foreach ($realpages as $realpage) { $link .= '[[' . $realpage . '>' . $realpage . ']]&br;'; } $body .= make_link($link); $body .= '</p>'; return array('msg' => _('Redirect'), 'body' => $body); } $vars['cmd'] = 'edit'; return do_plugin_action('edit'); // 存在しないので、編集フォームを表示 } else { // 無効なページ名 return array('msg' => $_title_invalidwn, 'body' => str_replace('$1', htmlspecialchars($page), str_replace('$2', 'WikiName', $_msg_invalidiwn))); } } } }
/** * Check validity of page * * @access static * @param string $page * @param array $options * @return $options */ function check_page($page, $current) { $page = get_fullname($page, $current); if (!is_page($page)) { sonots::mythrow('Page "' . htmlspecialchars($page) . '" does not exist.'); return; } if (!check_readable($page, FALSE, FALSE)) { sonots::mythrow('Page "' . htmlspecialchars($page) . '" is not readable.'); return; } return $page; }
function plugin_source_action() { global $vars, $_source_messages; if (PKWK_SAFE_MODE) { die_message('PKWK_SAFE_MODE prohibits this'); } $page = isset($vars['page']) ? $vars['page'] : ''; $vars['refer'] = $page; if (!is_page($page) || !check_readable($page, false, false)) { return array('msg' => $_source_messages['msg_notfound'], 'body' => $_source_messages['err_notfound']); } return array('msg' => $_source_messages['msg_title'], 'body' => '<pre id="source">' . htmlsc(join('', get_source($page))) . '</pre>'); }
function plugin_code_action() { global $vars; global $_source_messages; // if (PKWK_SAFE_MODE) die_message('PKWK_SAFE_MODE prohibits this'); if (auth::check_role('safemode')) { die_message('PKWK_SAFE_MODE prohibits this'); } $vars['refer'] = $vars['page']; if (!is_page($vars['page']) || !check_readable($vars['page'], false, false)) { return array('msg' => $_source_messages['msg_notfound'], 'body' => $_source_messages['err_notfound']); } return array('msg' => $_source_messages['msg_title'], 'body' => plugin_code_convert('pukiwiki', join('', get_source($vars['page'])) . "\n")); }
function plugin_read_action() { global $vars, $script; global $post; $qm = get_qm(); $qt = get_qt(); $page = isset($vars['page']) ? $vars['page'] : ''; //キャッシュを無効化 if (isset($vars['word'])) { $qt->enable_cache = false; } if (is_page($page)) { // ページを表示 check_readable($page, true, true); header_lastmod($page); return array('msg' => '', 'body' => ''); } else { if (!PKWK_SAFE_MODE && is_interwiki($page)) { return do_plugin_action('interwiki'); // InterWikiNameを処理 } else { if (is_pagename($page)) { $vars['cmd'] = 'edit'; // 編集権限があれば、編集モードへ。なければ、メッセージを表示 $editable = edit_auth($page, FALSE, FALSE); if ($editable) { return do_plugin_action('edit'); // 存在しないので、編集フォームを表示 } else { //404 NOT FOUND header('HTTP/1.1 404 Not Found'); return array('msg' => $qm->m['fmt_err_notfoundpage_title'], 'body' => $qm->replace('fmt_err_notfoundpage', $script)); } } else { //EUCエンコーディングかチェック if (mb_detect_encoding($post['page'], 'UTF-8,EUC-JP') == 'EUC-JP') { $u_page = mb_convert_encoding($post['page'], 'UTF-8', 'EUC-JP'); $enc_page = rawurlencode($u_page); //redirect header("HTTP/1.1 301 Moved Permanently"); header('Location: ' . $script . '?' . $enc_page); exit; } // 無効なページ名 return array('msg' => $qm->m['fmt_title_invalidiwn'], 'body' => $qm->replace('fmt_err_invalidiwn', h($page), 'WikiName')); } } } }
function plugin_diff_action() { global $vars; $page = isset($vars['page']) ? $vars['page'] : ''; check_readable($page, true, true); $action = isset($vars['action']) ? $vars['action'] : ''; switch ($action) { case 'delete': $retval = plugin_diff_delete($page); break; default: $retval = plugin_diff_view($page); break; } return $retval; }
function plugin_preview_action() { global $vars; $page = isset($vars['page']) ? $vars['page'] : ''; if (is_page($page)) { check_readable($page, true, true); $source = get_source($page); array_splice($source, 10); $body = convert_html($source); pkwk_common_headers(); header('Content-type: text/xml'); print '<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n"; print $body; } exit; }
function plugin_source_action() { global $vars; //, $_source_messages; // if (PKWK_SAFE_MODE) die_message('PKWK_SAFE_MODE prohibits this'); if (auth::check_role('safemode')) { die_message('PKWK_SAFE_MODE prohibits this'); } $page = isset($vars['page']) ? $vars['page'] : ''; $vars['refer'] = $page; if (!is_page($page) || !check_readable($page, false, false)) { return array('msg' => _(' $1 was not found.'), 'body' => _('cannot display the page source.')); } $source = join('', get_source($page)); auth::is_role_page($source); return array('msg' => _('Source of $1'), 'body' => '<pre id="source">' . htmlspecialchars($source) . '</pre>'); }
function plugin_source_action() { global $vars, $script; if (PKWK_SAFE_MODE) { die_message('PKWK_SAFE_MODE prohibits this'); } $page = isset($vars['page']) ? $vars['page'] : ''; $vars['refer'] = $page; $editable = ss_admin_check(); if (!$editable) { header("Location: {$script}"); exit; } $qm = get_qm(); if (!is_page($page) || !check_readable($page, false, false)) { return array('msg' => $qm->m['plg_source']['title_notfound'], 'body' => $qm->m['plg_source']['err_notfound']); } return array('msg' => $qm->m['plg_source']['title'], 'body' => '<pre id="source">' . htmlspecialchars(join('', get_source($page))) . '</pre>'); }
function plugin_referer_action() { global $vars, $referer; global $_referer_msg; // Setting: Off if (!$referer) { return array('msg' => '', 'body' => ''); } if (isset($vars['page']) && is_page($vars['page'])) { check_readable($vars['page'], false); $sort = empty($vars['sort']) ? '0d' : $vars['sort']; return array('msg' => $_referer_msg['msg_H0_Refer'], 'body' => plugin_referer_body($vars['page'], $sort)); } $pages = auth::get_existpages(REFERER_DIR, '.ref'); if (empty($pages)) { return array('msg' => '', 'body' => ''); } else { return array('msg' => 'referer list', 'body' => page_list($pages, 'referer', FALSE)); } }
function plugin_grepall_grep() { global $vars, $defaultpage; $page = isset($vars['page']) ? $vars['page'] : $defultpage; $filter = isset($vars['filter']) ? $vars['filter'] : ''; $grep = isset($vars['grep']) ? $vars['grep'] : ''; // page lists if ($page !== '') { if (!is_page($page)) { $body = '<p>' . htmlspecialchars($page) . ' does not exist.</p>'; return $body; } $pages = (array) $page; } else { $pages = get_existpages(); if ($filter !== '') { $pages = preg_grep('/' . preg_quote($filter, '/') . '/', $pages); } } // grep $body = ''; foreach ($pages as $page) { if (!check_readable($page)) { $body = '<p>' . htmlspecialchars($page) . ' is not readable.</p>'; return $body; } $lines = get_source($page); $lines = preg_grep('/' . preg_quote($grep, '/') . '/', $lines); if (empty($lines)) { continue; } $contents = ''; foreach ($lines as $i => $line) { $contents .= sprintf('%04d:', $i) . htmlspecialchars($line); } $body .= make_pagelink($page) . '<br />' . "\n"; $body .= '<pre>' . htmlspecialchars($contents) . '</pre>'; } return $body; }
/** * Grep a page * * @author sonots * @license http://www.gnu.org/licenses/gpl.html GPL v2 * @version $Id: grep.inc.php,v 1.1 2007-06-10 11:14:46 sonots $ * @package plugin */ function plugin_grep_action() { global $vars, $defaultpage; $page = isset($vars['page']) ? $vars['page'] : $defultpage; if (!is_page($page)) { $body = '<p>' . htmlspecialchars($page) . ' does not exist.</p>'; return array('msg' => 'Grep Plugin', 'body' => $body); } if (!check_readable($page)) { $body = '<p>' . htmlspecialchars($page) . ' is not readable.</p>'; return array('msg' => 'Grep Plugin', 'body' => $body); } $grep = isset($vars['grep']) ? $vars['grep'] : ''; $lines = get_source($page); $lines = preg_grep('/' . preg_quote($grep, '/') . '/', $lines); $contents = ''; foreach ($lines as $i => $line) { $contents .= sprintf('%04d:', $i) . htmlspecialchars($line); } $body = '<pre>' . htmlspecialchars($contents) . '</pre>'; return array('msg' => 'Grep Plugin', 'body' => $body); }
function plugin_splitinclude_convert() { global $script, $vars, $get, $post; global $_msg_splitinclude_restrict; static $splitinclude_list = array(); //処理済ページ名の配列 if (func_num_args() == 0) { return; } $splitinclude_list[$vars['page']] = TRUE; $func_vars_num = func_num_args(); $func_vars_array = func_get_args(); $incbody = ""; foreach ($func_vars_array as $page) { $page = strip_bracket($page); if (!is_page($page) or isset($splitinclude_list[$page])) { return ''; } $splitinclude_list[$page] = TRUE; $_page = $vars['page']; $get['page'] = $post['page'] = $vars['page'] = $page; // splitincludeのときは、認証画面をいちいち出さず、後始末もこちらでつける if (check_readable($page, false, false)) { if (function_exists('convert_filter')) { $body = convert_html(convert_filter(get_source($page))); } else { $body = convert_html(get_source($page)); } } else { $body = str_replace('$1', $page, $_msg_splitinclude_restrict); } $get['page'] = $post['page'] = $vars['page'] = $_page; $incbody .= "<div style=\"width:" . intval(96 / $func_vars_num) . "%;margin:0px 2px;vartical-align:top;float:left;\">{$body}</div>\n"; } $incbody = "<div style=\"width:100%\">\n{$incbody}</div>\n<div style=\"display:block;\"></div>\n"; return $incbody; }
function plugin_sitemap_filter_pages(&$pages) { global $non_list, $read_auth; foreach ($GLOBALS['PLUGIN_SITEMAP_SYSTEM_PAGE_VARS'] as $var) { if (isset($GLOBALS[$var])) { $page = $GLOBALS[$var]; $key = encode($page) . '.txt'; unset($pages[$key]); } } if (PLUGIN_SITEMAP_WHITE_LIST !== '') { $includes = preg_grep('/' . PLUGIN_SITEMAP_WHITE_LIST . '/', $pages); } else { $includes = array(); } if (PLUGIN_SITEMAP_BLACK_LIST !== '') { $pattern = '/(?:' . $non_list . ')|(?:' . PLUGIN_SITEMAP_BLACK_LIST . ')/'; } else { $pattern = '/' . $non_list . '/'; } if (version_compare(PHP_VERSION, '4.2.0', '>=')) { $pages = preg_grep($pattern, $pages, PREG_GREP_INVERT); } else { $pages = array_diff($pages, preg_grep($pattern, $pages)); } if ($includes) { $pages += $includes; } if ($read_auth) { foreach ($pages as $key => $page) { if (check_readable($page, false, false) === false) { unset($pages[$key]); } } } }
function plugin_include_convert() { global $script, $vars, $get, $post, $menubar, $_msg_include_restrict; static $included = array(); static $count = 1; if (func_num_args() == 0) { return PLUGIN_INCLUDE_USAGE . '<br />' . "\n"; } // $menubar will already be shown via menu plugin if (!isset($included[$menubar])) { $included[$menubar] = true; } // Loop yourself $root = isset($vars['page']) ? $vars['page'] : ''; $included[$root] = true; // Get arguments $args = func_get_args(); // strip_bracket() is not necessary but compatible $page = isset($args[0]) ? get_fullname(strip_bracket(array_shift($args)), $root) : ''; $with_title = PLUGIN_INCLUDE_WITH_TITLE; if (isset($args[0])) { switch (strtolower(array_shift($args))) { case 'title': $with_title = true; break; case 'notitle': $with_title = false; break; } } $s_page = htmlsc($page); $r_page = rawurlencode($page); $link = '<a href="' . $script . '?' . $r_page . '">' . $s_page . '</a>'; // Read link // I'm stuffed if (isset($included[$page])) { return '#include(): Included already: ' . $link . '<br />' . "\n"; } if (!is_page($page)) { return '#include(): No such page: ' . $s_page . '<br />' . "\n"; } if ($count > PLUGIN_INCLUDE_MAX) { return '#include(): Limit exceeded: ' . $link . '<br />' . "\n"; } else { ++$count; } // One page, only one time, at a time $included[$page] = true; // Include A page, that probably includes another pages $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_include_restrict); } $get['page'] = $post['page'] = $vars['page'] = $root; // Put a title-with-edit-link, before including document if ($with_title) { $link = '<a href="' . $script . '?cmd=edit&page=' . $r_page . '">' . $s_page . '</a>'; if ($page == $menubar) { $body = '<span align="center"><h5 class="side_label">' . $link . '</h5></span><small>' . $body . '</small>'; } else { $body = '<h1>' . $link . '</h1>' . "\n" . $body . "\n"; } } return $body; }
function plugin_template_action() { global $script, $vars; // global $_title_edit; // global $_msg_template_start, $_msg_template_end, $_msg_template_page, $_msg_template_refer; // global $_btn_template_create, $_title_template; // global $_err_template_already, $_err_template_invalid, $_msg_template_force; $_title_edit = _('Edit of $1'); $_msg_template_start = _('Start:<br />'); $_msg_template_end = _('End:<br />'); $_msg_template_page = _('$1/copy'); $_msg_template_refer = _('Page:'); $_msg_template_force = _('Edit with a page name which already exists'); $_err_template_already = _(' $1 already exists.'); $_err_template_invalid = _(' $1 is not a valid page name.'); $_btn_template_create = _('Create'); $_title_template = _('create a new page, using $1 as a template.'); // if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing'); // if (auth::check_role('readonly')) die_message('PKWK_READONLY prohibits editing'); if (auth::check_role('safemode') || auth::check_role('readonly')) { die_message(_('Prohibited')); } if (!isset($vars['refer']) || !is_page($vars['refer'])) { return FALSE; } if (!is_page($vars['refer']) || !check_readable($vars['refer'], false, false)) { return array('msg' => _(' $1 was not found.'), 'body' => _('cannot display the page source.')); } $lines = get_source($vars['refer']); auth::is_role_page($lines); // Remove '#freeze' if (!empty($lines) && strtolower(rtrim($lines[0])) == '#freeze') { array_shift($lines); } $begin = isset($vars['begin']) && is_numeric($vars['begin']) ? $vars['begin'] : 0; $end = isset($vars['end']) && is_numeric($vars['end']) ? $vars['end'] : count($lines) - 1; if ($begin > $end) { $temp = $begin; $begin = $end; $end = $temp; } $page = isset($vars['page']) ? $vars['page'] : ''; $is_page = is_page($page); // edit if ($is_pagename = is_pagename($page) && (!$is_page || !empty($vars['force']))) { $postdata = join('', array_splice($lines, $begin, $end - $begin + 1)); $retvar['msg'] = $_title_edit; $retvar['body'] = edit_form($vars['page'], $postdata); $vars['refer'] = $vars['page']; return $retvar; } $begin_select = $end_select = ''; for ($i = 0; $i < count($lines); $i++) { $line = htmlspecialchars(mb_strimwidth($lines[$i], 0, MAX_LEN, '...')); $tag = $i == $begin ? ' selected="selected"' : ''; $begin_select .= "<option value=\"{$i}\"{$tag}>{$line}</option>\n"; $tag = $i == $end ? ' selected="selected"' : ''; $end_select .= "<option value=\"{$i}\"{$tag}>{$line}</option>\n"; } $_page = htmlspecialchars($page); $msg = $tag = ''; if ($is_page) { $msg = $_err_template_already; $tag = '<input type="checkbox" name="force" value="1" />' . $_msg_template_force; } else { if ($page != '' && !$is_pagename) { $msg = str_replace('$1', $_page, $_err_template_invalid); } } $s_refer = htmlspecialchars($vars['refer']); $s_page = $page == '' ? str_replace('$1', $s_refer, $_msg_template_page) : $_page; $ret = <<<EOD <form action="{$script}" method="post"> <div> <input type="hidden" name="plugin" value="template" /> <input type="hidden" name="refer" value="{$s_refer}" /> {$_msg_template_start} <select name="begin" size="10">{$begin_select}</select><br /><br /> {$_msg_template_end} <select name="end" size="10">{$end_select}</select><br /><br /> <label for="_p_template_refer">{$_msg_template_refer}</label> <input type="text" name="page" id="_p_template_refer" value="{$s_page}" /> <input type="submit" name="submit" value="{$_btn_template_create}" /> {$tag} </div> </form> EOD; $retvar['msg'] = $msg == '' ? $_title_template : $msg; $retvar['body'] = $ret; return $retvar; }
function plugin_search2_do_search($word, $type = 'AND', $non_format = FALSE, $base = '') { global $script, $whatsnew, $non_list, $search_non_list, $foot_explain; global $search_auth, $show_passage, $username, $vars; $qm = get_qm(); $retval = array(); $b_type = $type == 'AND'; // AND:TRUE OR:FALSE mb_language('Japanese'); $word = mb_convert_encoding($word, SOURCE_ENCODING, "UTF-8,EUC-JP,SJIS,ASCII,JIS"); $word = mb_ereg_replace(" ", " ", $word); $keys = get_search_words(preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY)); foreach ($keys as $key => $value) { $keys[$key] = '/' . $value . '/S'; } $pages = get_existpages(); // Avoid if ($base != '') { $pages = preg_grep('/^' . preg_quote($base, '/') . '/S', $pages); } if (!$search_non_list) { $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages)); } $pages = array_flip($pages); unset($pages[$whatsnew]); $count = count($pages); // Search for page contents global $ignore_plugin, $strip_plugin, $strip_plugin_inline; $titles = array(); $head10s = array(); // 一時的に認証を外す $user_name = null; if (isset($_SESSION['usr'])) { $user_name = $_SESSION['usr']; unset($_SESSION['usr']); } foreach (array_keys($pages) as $page) { $vars['page'] = $page; $b_match = FALSE; // Search auth for page contents if (!check_readable($page, false, false, TRUE)) { unset($pages[$page]); continue; } $lines = get_source($page, TRUE, FALSE); //--- 検索専用のデータの作成、更新 --- $srh_fname = CACHE_DIR . encode($page) . '_search.txt'; if (!file_exists($srh_fname) || filemtime($srh_fname) < filemtime(get_filename($page))) { $p_title = $page; $p_heads = ''; foreach ($lines as $k => $l) { if (preg_match($ignore_plugin, $l)) { // 省く $lines = array(); break; } if (preg_match($strip_plugin, $l, $ms)) { // 省く unset($lines[$k]); } if (preg_match('/^TITLE:(.*)/', $l, $ms)) { $p_title = trim($ms[1]); if ($p_title !== $page) { $p_title = $p_title . ' ' . $page; } unset($lines[$k]); } if (preg_match('/^(?:!|(\\*){1,3})(.*)\\[#\\w+\\]\\s?/', $l, $ms)) { $p_heads .= trim($ms[2]) . ' '; unset($lines[$k]); } } $lines = preg_replace($strip_plugin_inline, '', $lines); // 省く $html = convert_html($lines); $html = preg_replace('/<(script|style)[^>]*>.*?<\\/\\1>/i', '', $html); $html = preg_replace('/<img\\b[^>]*alt="(.*?)"[^>]*>/i', '\\1', $html); $p_body = trim(strip_tags($html)); foreach ($foot_explain as $id => $note) { $p_body .= "\n" . strip_tags($note); } $foot_explain = array(); $p_body = count($lines) > 0 ? $p_title . "\n" . $p_heads . "\n" . $p_body : ''; file_put_contents($srh_fname, $p_body); } else { $fp = fopen($srh_fname, "r"); flock($fp, LOCK_SH); $lines = file($srh_fname); flock($fp, LOCK_UN); fclose($fp); $p_title = trim($lines[0]); unset($lines[0]); $p_heads = trim($lines[1]); unset($lines[1]); $p_body = implode('', $lines); } ////////////////////////////////////////////// // // 検索スタート! // /////////////////////////////////////////////// $match_title = 0; $match_heads = 0; $match_body = 0; //--- ページタイトル検索 --- $point = 0; $ok = false; if (!$non_format) { foreach ($keys as $key) { $b_match = preg_match($key, $p_title); if (!$b_match) { $ok = false; break; } else { $ok = true; $point += 15; } } if ($ok) { $match_title = $point; } } //--- ヘッダー検索 --- $point = 0; $ok = false; foreach ($keys as $key) { $b_match = preg_match_all($key, $p_title, $ms); if (!$b_match) { $ok = false; break; } else { $ok = true; $point += 10; } } if ($ok) { $match_heads = $point; } //--- コンテンツ検索 --- foreach ($keys as $key) { $b_match = preg_match_all($key, $p_body, $ms); if (!$b_match) { $ok = false; break; } else { $ok = true; $point += count($ms[0]); } } if ($ok) { $match_body = $point; } //検索結果 $total = $match_title + $match_heads + $match_body; if ($total == 0) { unset($pages[$page]); // Miss } else { $pages[$page] = $total; $titles[$page] = $p_title; $head10s[$page] = mb_substr($p_body, 0, 60 * 3); } } if ($user_name !== null) { $_SESSION['usr'] = $user_name; } $vars['page'] = ''; //注釈の削除 $foot_explain = array(); if ($non_format) { return array_keys($pages); } $r_word = rawurlencode($word); $s_word = h($word); if (empty($pages)) { return str_replace('$1', $s_word, '$1 を含むページは見つかりませんでした。'); } arsort($pages); $retval = '<div class="container-fluid"><div class="list-group">' . "\n"; foreach ($pages as $page => $v) { $title = $titles[$page]; if ($title !== $page) { $rpos = strrpos($title, $page); if ($rpos !== FALSE) { $title = trim(substr($title, 0, $rpos)); } $title = $title . ' - ' . $page; } $r_page = rawurlencode($page); $tmp_li = ' <div class="list-group-item" style="border-style:none;"><a class="list-group-item-heading" href="' . $script . '?cmd=read&page=' . $r_page . '&word=' . $r_word . '" style="font-weight:bold;">' . h($title) . '</a><p class="list-group-item-text text-muted" style="margin: 5px 0;">' . $head10s[$page] . '</p></div>' . "\n"; $retval .= $tmp_li; } $retval .= '</div><p>' . "\n"; $retval .= str_replace('$1', $s_word, str_replace('$2', count($pages), str_replace('$3', $count, $b_type ? '$1 のすべてを含むページは <strong>$3</strong> ページ中、 <strong>$2</strong> ページ見つかりました。' : '$1 のいずれかを含むページは <strong>$3</strong> ページ中、 <strong>$2</strong> ページ見つかりました。'))); $retval .= '</p></div>'; return $retval; }
function toString($flat) { global $_title_cannotread; if (!check_readable($this->page, FALSE, FALSE)) { return str_replace('$1', make_pagelink($this->page), $_title_cannotread); } else { if ($flat) { return $this->to_flat(); } } $ret = ''; $files = array_keys($this->files); sort($files); foreach ($files as $file) { $_files = array(); foreach (array_keys($this->files[$file]) as $age) { $_files[$age] = $this->files[$file][$age]->toString(FALSE, TRUE); } if (!isset($_files[0])) { $_files[0] = htmlsc($file); } ksort($_files); $_file = $_files[0]; unset($_files[0]); $ret .= " <li>{$_file}\n"; if (count($_files)) { $ret .= "<ul>\n<li>" . join("</li>\n<li>", $_files) . "</li>\n</ul>\n"; } $ret .= " </li>\n"; } return make_pagelink($this->page) . "\n<ul>\n{$ret}</ul>\n"; }
function plugin_contents2_1($args, $calledby = 'convert') { global $vars; global $script; global $_contents2_1_msg_err; // true or false のオプション $params = array('fromhere' => PLUGIN_CONTENTS2_1_FROMHERE, 'compact' => PLUGIN_CONTENTS2_1_COMPACT, 'include' => PLUGIN_CONTENTS2_1_INCLUDE, 'fixed_anchor' => PLUGIN_CONTENTS2_1_FIXEDANCHOR); // その他の引数を持つオプション $argparams = array('page' => '', 'depth' => '', 'number' => '', 'except' => '', 'display' => PLUGIN_CONTENTS2_1_DISPLAY); // その他の引数を持ち、値が HTML に出力されるオプション( 要 htmlspecialchars ) $arghtmlparams = array('inline_before' => PLUGIN_CONTENT22_1_DISPLAY_INLINE_BEFORE, 'inline_delimiter' => PLUGIN_CONTENTS2_1_DISPLAY_INLINE_DELIMITER, 'inline_after' => PLUGIN_CONTENTS2_1_DISPLAY_INLINE_AFTER); array_walk($args, 'plugin_contents2_1_check_params', &$params); array_walk($args, 'plugin_contents2_1_check_argparams', &$argparams); array_walk($args, 'plugin_contents2_1_check_arghtmlparams', &$arghtmlparams); $params = array_merge($params, $argparams, $arghtmlparams); // inline プラグイン時は強制 display=inline。 if ($calledby == 'inline') { $params['display'] = 'inline'; } // ページ名処理 if ($params['page'] == '') { $page = $vars['page']; } else { $page = $params['page']; } if (!is_page($page) || !check_readable($page, false, false)) { return sprintf($_contents2_1_msg_err, htmlspecialchars($page)); } // page オプションを利用し、現在表示ページと違うページの見出しリンクを作る場合アンカーだけでは足りない。 if ($page != $vars['page']) { $r_page = rawurlencode($page); $href = $script . '?cmd=read&page=' . $r_page; $params['href'] = $href; // 表示ページと違うページが指定されていれば強制 FALSE $params['fromhere'] = false; } else { $params['href'] = ''; } // depth オプション解析 if ($params['depth'] != '') { list($params['lowdepth'], $params['highdepth']) = plugin_contents2_1_depth_option_analysis($params['depth']); } // number オプション解析 if ($params['number'] != '') { if (!preg_match('/^\\d+$/', $params['number'])) { $params['number'] = ''; } } $params['result'] = $params['saved'] = array(); $params['page_anchor_counter'] = PLUGIN_CONTENTS2_1_PAGE_ANCHOR_ORIGIN; $params['number_counter'] = 0; $params['fromhere_detected'] = false; plugin_contents2_1_get_headings($page, $params); if ($params['display'] == 'inline') { if ($calledby == 'inline') { $tag = 'span'; } else { $tag = 'div'; } return "<{$tag} class=\"" . PLUGIN_CONTENTS2_1_CSS_CLASS . "\">" . join("", $params['result']) . join("", $params['saved']) . "</{$tag}>"; } else { return join("\n", $params['result']) . join("\n", $params['saved']); } }
function plugin_calendar_viewer_convert() { global $vars, $get, $post, $weeklabels; // global $_msg_calendar_viewer_right, $_msg_calendar_viewer_left; // global $_msg_calendar_viewer_restrict, $_err_calendar_viewer_param2; $_err_calendar_viewer_param2 = _('Wrong second parameter.'); $_msg_calendar_viewer_right = _('Next %d>>'); $_msg_calendar_viewer_left = _('<< Prev %d'); $_msg_calendar_viewer_restrict = _('Due to the blocking, the calendar_viewer cannot refer to $1.'); 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(): ' . $_err_calendar_viewer_param2 . '<br />' . "\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 = htmlspecialchars($pagename); return "#calendar_viewer(): You already view: {$s_page}<br />"; } 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); } if (PLUGIN_CALENDAR_VIEWER_DATE_FORMAT !== FALSE) { $time = strtotime(basepagename($page)); // $date_sep must be assumed '-' or ''! if ($time == -1 || $time == FALSE) { $s_page = htmlspecialchars($page); // Failed. Why? } else { $week = $weeklabels[date('w', $time)]; $s_page = htmlspecialchars(str_replace(array('$w'), array($week), date(PLUGIN_CALENDAR_VIEWER_DATE_FORMAT, $time))); } } else { $s_page = htmlspecialchars($page); } // if (PKWK_READONLY) { if (auth::check_role('readonly')) { $link = get_page_uri($page); } else { $link = get_cmd_uri('edit', $page); } $link = '<a href="' . $link . '">' . $s_page . '</a>'; $head = '<h1>' . $link . '</h1>' . "\n"; $return_body .= $head . $body; ++$tmp; } // ここで、前後のリンクを表示 // ?plugin=calendar_viewer&file=ページ名&date=yyyy-mm $enc_pagename = rawurlencode(substr($pagepattern, 0, $pagepattern_len - 1)); 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($_msg_calendar_viewer_left, $limit_pitch); } if ($limit_base + $limit_pitch >= count($pagelist)) { $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); $left_link = $right_link = ''; $link = get_cmd_uri('calendar_viewer', '', '', 'mode=' . $mode . '&file=' . $enc_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は<<新 旧>> 他は<<旧 新>> $return_body .= '<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; return $return_body; }
function plugin_backup_convert() { global $vars, $script; // global $_msg_backuplist, $_msg_diff, $_msg_nowdiff, $_msg_source, $_msg_nobackup; // global $_title_backup_delete; $page = isset($vars['page']) ? $vars['page'] : ''; check_readable($page, false); $_msg_backuplist = _('List of Backups'); $_msg_diff = _('diff'); $_msg_nowdiff = _('diff current'); $_msg_source = _('source'); $_msg_nobackup = _('There are no backup(s) of $1.'); $_title_backup_delete = _('Deleting backup of $1'); // Get arguments $with_label = TRUE; $args = func_get_args(); while (isset($args[0])) { switch (array_shift($args)) { case 'default': $diff_mode = 0; break; case 'nowdiff': $diff_mode = 1; break; case 'visualdiff': $diff_mode = 2; break; case 'label': $with_label = TRUE; break; case 'nolabel': $with_label = FALSE; break; } } $r_page = rawurlencode($page); $s_page = htmlspecialchars($page); $retval = array(); $date = get_date("m/d", get_filetime($page)); if ($with_label) { $retval[0] = <<<EOD <form class="center_form" action=""><div><label>Versions: <select onchange="javascript:location.href=this[this.selectedIndex].value"> EOD; $retval[1] = "\n"; $retval[2] = <<<EOD </select></label></div> </form> EOD; } else { $retval[0] = <<<EOD <form class="center_form" action=""><div> <select onchange="javascript:location.href=this[this.selectedIndex].value"> EOD; $retval[1] = "\n"; $retval[2] = <<<EOD </select> </div></form> EOD; } $backups = _backup_file_exists($page) ? get_backup($page) : array(); if (count($backups) == 0) { $retval[1] .= '<option value="' . get_page_uri($page) . '" selected="selected">' . _('->') . " {$date}(No.1)</option>\n"; return join('', $retval); } $maxcnt = count($backups) + 1; $retval[1] .= '<option value="' . get_page_uri($page) . '" selected="selected">' . _('->') . " {$date}(No.{$maxcnt})</option>\n"; $backups = array_reverse($backups, True); foreach ($backups as $age => $data) { $time = isset($data['real']) ? $data['real'] : $data['time']; $date = get_date('m/d', $time); $href = $script . '?cmd=backup&page=' . $r_page . '&age=' . $age; $retval[1] .= '<option value="' . $href; switch ($diff_mode) { case 2: $retval[1] .= '&action=visualdiff'; break; case 1: $retval[1] .= '&action=nowdiff'; break; } $retval[1] .= '">' . $date . ' (No.' . $age . ')</option>' . "\n"; } return join('', $retval); }
function do_search_fuzzy($word, $type = 'AND', $non_format = FALSE, $non_fuzzy = FALSE) { global $whatsnew, $non_list, $search_non_list; global $search_auth, $search_fuzzy; static $fuzzypattern = array('ヴァ' => 'バ', 'ヴィ' => 'ビ', 'ヴェ' => 'ベ', 'ヴォ' => 'ボ', 'ヴ' => 'ブ', 'ヰ' => 'イ', 'ヱ' => 'エ', 'ヵ' => 'カ', 'ァ' => 'ア', 'ィ' => 'イ', 'ゥ' => 'ウ', 'ェ' => 'エ', 'ォ' => 'オ', 'ャ' => 'ヤ', 'ュ' => 'ユ', 'ョ' => 'ヨ'); $retval = array(); $b_type = $type == 'AND'; // AND:TRUE OR:FALSE $keys = get_search_words(preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY)); $_pages = get_existpages(); $pages = array(); $non_list_pattern = '/' . $non_list . '/'; foreach ($_pages as $page) { if ($page == $whatsnew || !$search_non_list && preg_match($non_list_pattern, $page)) { continue; } // 検索対象ページの制限をかけるかどうか (ページ名は制限外) if ($search_auth && !check_readable($page, false, false)) { $source = get_source(); // 検索対象ページ内容を空に。 } else { $source = get_source($page); } if (!$non_format) { array_unshift($source, $page); } // ページ名も検索対象に $b_match = FALSE; //miko modified if (!$search_fuzzy || $non_fuzzy) { foreach ($keys as $key) { $tmp = preg_grep('/' . $key . '/', $source); $b_match = !empty($tmp); if ($b_match xor $b_type) { break; } } if ($b_match) { $pages[$page] = get_filetime($page); } } else { $fuzzy_from = array_keys($fuzzypattern); $fuzzy_to = array_values($fuzzypattern); $words = preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY); $_source = mb_strtolower(mb_convert_kana(join("\n", $source), 'KVCas')); for ($i = 0; $i < count($fuzzy_from); $i++) { $_source = mb_ereg_replace($fuzzy_from[$i], $fuzzy_to[$i], $_source); } $_source = mb_ereg_replace('[ッー・゛゜、。]', '', $_source); foreach ($keys as $key) { $_keyword = mb_strtolower(mb_convert_kana($word, 'KVCas')); for ($i = 0; $i < count($fuzzy_from); $i++) { $_keyword = mb_ereg_replace($fuzzy_from[$i], $fuzzy_to[$i], $_keyword); } $_keyword = mb_ereg_replace('[ッー・゛゜、。]', '', $_keyword); $b_match = mb_ereg(mb_ereg_quote($_keyword), $_source); } if ($b_match) { $pages[$page] = get_filetime($page); } } //miko modified } if ($non_format) { return array_keys($pages); } $r_word = rawurlencode($word); $s_word = htmlspecialchars($word); if (empty($pages)) { return str_replace('$1', $s_word, $_string['notfoundresult']); } ksort($pages); $retval = '<ul>' . "\n"; foreach ($pages as $page => $time) { $s_page = htmlspecialchars($page); $passage = get_passage($time); $retval .= ' <li><a href="' . get_page_uri($page, '', 'word=' . $r_word) . '">' . $s_page . '</a>' . $passage . '</li>' . "\n"; } $retval .= '</ul>' . "\n"; $retval .= str_replace('$1', $s_word, str_replace('$2', count($pages), str_replace('$3', count($_pages), $b_type ? $_string['andresult'] : $_string['orresult']))); return $retval; }
function plugin_minicalendar_viewer_convert() { global $vars, $get, $post, $script, $weeklabels; global $_err_calendar_viewer_param, $_err_calendar_viewer_param2; global $_msg_calendar_viewer_right, $_msg_calendar_viewer_left; global $_msg_calendar_viewer_restrict; global $_symbol_paraedit, $trackback; static $viewed = array(); if (func_num_args() < 2) { return PLUGIN_MINICALENDAR_VIEWER_USAGE . '<br />' . "\n"; } $func_vars_array = func_get_args(); // デフォルト値をセット $pagename = $func_vars_array[0]; // 基準となるページ名 $limit_page = 7; // 表示する件数制限 $date_YM = ''; // 一覧表示する年月 $mode = 'past'; // 動作モード $date_sep = '-'; // 日付のセパレータ calendar2なら"-" calendarなら"" // Check $func_args[1] if (preg_match("/[0-9]{4}" . $date_sep . "[0-9]{2}/", $func_vars_array[1])) { //指定年月の一覧表示 $page_YM = $func_vars_array[1]; $limit_base = 0; $limit_page = 31; //手抜き。31日分をリミットとする。 } else { if (preg_match("/this/si", $func_vars_array[1])) { //今月の一覧表示 $page_YM = get_date('Y' . $date_sep . 'm'); $limit_base = 0; $limit_page = 31; } else { if (preg_match("/^[0-9]+\$/", $func_vars_array[1])) { //n日分表示 $limit_pitch = $func_vars_array[1]; $limit_page = $limit_pitch; $limit_base = 0; $page_YM = ''; } else { if (preg_match("/([0-9]+)\\*([0-9]+)/", $func_vars_array[1], $reg_array)) { $limit_pitch = $reg_array[2]; $limit_page = $reg_array[1] + $limit_pitch; $limit_base = $reg_array[1]; $page_YM = ''; } else { return '#calendar_viewer(): ' . $_err_calendar_viewer_param2 . '<br />' . "\n"; } } } } // $func_args[2]: Change default delimiter if (isset($func_vars_array[2]) && preg_match("/^(past|pastex|view|viewex|future|futureex)\$/si", $func_vars_array[2])) { $mode = $func_vars_array[2]; } // $func_args[3]: Change default delimiter if (isset($func_vars_array[3])) { $date_sep = $func_vars_array[3]; } // Avoid Loop etc. if (isset($viewed[$pagename])) { if ($viewed[$pagename] > PLUGIN_MINICALENDAR_MAX_VIEWS) { $s_page = htmlspecialchars($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); // $pageがカレンダー形式なのかチェック デフォルトでは yyyy-mm-dd if (plugin_minicalendar_viewer_isValidDate($page_date, $date_sep) == FALSE) { continue; } // mode毎に別条件ではじく // pastex modeでは今日を含む未来のページはNG // futureex modeでは今日を含む過去のページはNG // past modeでは未来のページはNG // future modeでは過去のページはNG if ($page_date >= $_date && $mode == 'pastex') { continue; } if ($page_date <= $_date && $mode == 'futureex') { continue; } if ($page_date > $_date && $mode == 'past') { continue; } if ($page_date < $_date && $mode == 'future') { continue; } $pagelist[] = $page; } } closedir($dir); // まずソート if ($mode == 'past' || $mode == 'pastex' || $mode == 'viewex') { rsort($pagelist); } else { sort($pagelist); } // ここからインクルード $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)) { if (function_exists('convert_filter')) { $body = convert_html(convert_filter(get_source($page))); } else { $body = convert_html(get_source($page)); } } else { $body = str_replace('$1', $page, $_msg_calendar_viewer_restrict); } $r_page = rawurlencode($page); $s_page = htmlspecialchars($page); if (PLUGIN_MINICALENDAR_VIEWER_DATE_FORMAT !== FALSE) { $time = strtotime(basepagename($page)); // $date_sep must be assumed '-' or ''! if ($time == -1 || $time == FALSE) { $s_page = htmlspecialchars($page); // Failed. Why? } else { $week = $weeklabels[date('w', $time)]; $s_page = htmlspecialchars(str_replace(array('$w'), array($week), date(PLUGIN_CALENDAR_VIEWER_DATE_FORMAT, $time))); } } $refpage = rawurlencode($tmppage); $page_title = basepagename($page); $s_page_title = htmlspecialchars($page_title); // if (PKWK_READONLY) { if (auth::check_role('readonly')) { $link = get_page_uri($page); } else { $link = get_cmd_uri('edit', $page, '', 'refpage=' . $refpage); } $link = '<a class="anchor_super" href="' . $link . '">' . $_symbol_paraedit . '</a>'; $head = '<h3 class="minicalendar">' . $s_page_title . ' ' . $link . '</h3>' . "\n"; $tail = ''; if (PLUGIN_MINICALENDAR_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)); $monthlabel = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $mmstr = $monthlabel[$mm]; $h_today = public_holiday($yy, $mm, $dd); if ($h_today['rc'] != 0) { $classname = 'date_holiday'; } else { if ($h_today['w'] == 0) { $classname = 'date_holiday'; } else { if ($h_today['w'] == 6) { $classname = 'date_weekend'; } else { $classname = 'date_weekday'; } } } $head = '<h3 class="' . $classname . '"><span class="day">' . sprintf('%02d', $dd) . '</span> <br />' . '<b>' . $mmstr . '</b>, <b>' . $yy . '</b>' . $link . '</h3>' . "\n"; } } if (PLUGIN_MINICALENDAR_VIEWER_COMMENT === TRUE) { if (is_page(':config/plugin/addline/comment') && exist_plugin_inline('addline')) { $comm = convert_html(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_MINICALENDAR_VIEWER_TRACKBACK === TRUE) { if ($trackback) { $tb_id = tb_get_id($page); $tail .= '<a href="' . $script . '?plugin=tb&__mode=view&tb_id=' . $tb_id . '">' . '<img src="' . IMAGE_URI . 'plus/trackback.png" width="15" height="15" alt="" title="" />Trackback(' . tb_count($page) . ')' . '</a>' . "\n"; } } if ($tail != '') { $tail = '<div class="trackback">' . $tail . '</div>'; } $return_body .= $head . '<div class="minicalendar_viewer">' . $body . '</div>' . $tail; ++$tmp; } //ここで、前後のリンクを表示 //?plugin=minicalendar_viewer&file=ページ名&date=yyyy-mm $enc_pagename = rawurlencode(substr($pagepattern, 0, $pagepattern_len - 1)); 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); $next_YMX = sprintf('%04d%02d', $next_year, $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); $prev_YMX = sprintf('%04d%02d', $prev_year, $prev_month); // if ($mode == "past" || $mode == "pastex") { // $right_YM = $prev_YM; // $right_YMX = $prev_YMX; // $right_text = $prev_YM.">>"; // $left_YM = $next_YM; // $left_YMX = $next_YMX; // $left_text = "<<".$next_YM; // } else { $left_YM = $prev_YM; $left_YMX = $prev_YMX; $left_text = '<<' . $prev_YM; $right_YM = $next_YM; $right_YMX = $next_YMX; $right_text = $next_YM . '>>'; // } } else { // n件表示時 if ($limit_base >= count($pagelist)) { $right_YM = ''; } else { $right_base = $limit_base + $limit_pitch; $right_YM = $right_base . '*' . $limit_pitch; $right_text = sprintf($_msg_calendar_viewer_right, $limit_pitch); } $left_base = $limit_base - $limit_pitch; if ($left_base >= 0) { $left_YM = $left_base . '*' . $limit_pitch; $left_text = sprintf($_msg_calendar_viewer_left, $limit_pitch); } else { $left_YM = ''; } $prev_YMX = ''; $next_YMX = ''; } // ナビゲート用のリンクを末尾に追加 $s_date_sep = htmlspecialchars($date_sep); if ($left_YM != '') { if ($left_YMX != '') { $left_link = '<a href="' . $script . '?plugin=minicalendar&file=' . $enc_pagename . '&date=' . $left_YMX . '">' . $left_text . '</a>'; } else { $left_link = '<a href="' . $script . '?plugin=minicalendar_viewer&file=' . $enc_pagename . '&date=' . $left_YM . '&date_sep=' . $s_date_sep . '&mode=' . $mode . '">' . $left_text . '</a>'; } } else { $left_link = ''; } if ($right_YM != '') { if ($right_YMX != '') { $right_link = '<a href="' . $script . '?plugin=minicalendar&file=' . $enc_pagename . '&date=' . $right_YMX . '">' . $right_text . '</a>'; } else { $right_link = '<a href="' . $script . '?plugin=minicalendar_viewer&file=' . $enc_pagename . '&date=' . $right_YM . '&date_sep=' . $s_date_sep . '&mode=' . $mode . '">' . $right_text . '</a>'; } } else { $right_link = ''; } //past modeは<<新 旧>> 他は<<旧 新>> $return_body .= '<div class="prevnext">'; $return_body .= '<div class="prevnext_r">' . $right_link . '</div>'; $return_body .= '<div class="prevnext_l">' . $left_link . '</div>'; $return_body .= '</div><br style="display:block;clear:both" />'; $get['page'] = $post['page'] = $vars['page'] = $tmppage; return $return_body; }
function check_readable($page, $flag, $flag) { return check_readable($page, $flag, $flag); }
function do_search($word, $type = 'AND', $non_format = FALSE, $base = '') { global $script, $whatsnew, $non_list, $search_non_list; global $_msg_andresult, $_msg_orresult, $_msg_notfoundresult; global $search_auth, $show_passage; $retval = array(); $b_type = $type == 'AND'; // AND:TRUE OR:FALSE $keys = get_search_words(preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY)); foreach ($keys as $key => $value) { $keys[$key] = '/' . $value . '/S'; } $pages = get_existpages(); // Avoid if ($base != '') { $pages = preg_grep('/^' . preg_quote($base, '/') . '/S', $pages); } if (!$search_non_list) { $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages)); } $pages = array_flip($pages); unset($pages[$whatsnew]); $count = count($pages); foreach (array_keys($pages) as $page) { $b_match = FALSE; // Search for page name if (!$non_format) { foreach ($keys as $key) { $b_match = preg_match($key, $page); if ($b_type xor $b_match) { break; } // OR } if ($b_match) { continue; } } // Search auth for page contents if ($search_auth && !check_readable($page, false, false)) { unset($pages[$page]); --$count; } // Search for page contents foreach ($keys as $key) { $b_match = preg_match($key, get_source($page, TRUE, TRUE)); if ($b_type xor $b_match) { break; } // OR } if ($b_match) { continue; } unset($pages[$page]); // Miss } if ($non_format) { return array_keys($pages); } $r_word = rawurlencode($word); $s_word = htmlspecialchars($word); if (empty($pages)) { return str_replace('$1', $s_word, $_msg_notfoundresult); } ksort($pages); $retval = '<ul>' . "\n"; foreach (array_keys($pages) as $page) { $r_page = rawurlencode($page); $s_page = htmlspecialchars($page); $passage = $show_passage ? ' ' . get_passage(get_filetime($page)) : ''; $retval .= ' <li><a href="' . $script . '?cmd=read&page=' . $r_page . '&word=' . $r_word . '">' . $s_page . '</a>' . $passage . '</li>' . "\n"; } $retval .= '</ul>' . "\n"; $retval .= str_replace('$1', $s_word, str_replace('$2', count($pages), str_replace('$3', $count, $b_type ? $_msg_andresult : $_msg_orresult))); return $retval; }
function plugin_backup_action() { global $vars, $do_backup, $hr, $script; global $layout_pages, $style_name; $qm = get_qm(); $editable = edit_auth($page, FALSE, FALSE); if (!$editable) { header("Location: {$script}"); exit; } if (!$do_backup) { return; } $page = isset($vars['page']) ? $vars['page'] : ''; if ($page == '') { return array('msg' => $qm->m['plg_backup']['title_backuplist'], 'body' => plugin_backup_get_list_all()); } //レイアウト部品の場合、スタイルを変更する $is_layout = FALSE; if (isset($layout_pages) && isset($layout_pages[$page])) { $style_name = '..'; $is_layout = TRUE; } check_readable($page, true, true); $s_page = htmlspecialchars($page); $r_page = rawurlencode($page); $action = isset($vars['action']) ? $vars['action'] : ''; if ($action == 'delete') { return plugin_backup_delete($page); } $s_action = $r_action = ''; if ($action != '') { $s_action = htmlspecialchars($action); $r_action = rawurlencode($action); } $s_age = isset($vars['age']) && is_numeric($vars['age']) ? $vars['age'] : 0; if ($s_age <= 0) { $title = $is_layout ? h($layout_pages[$page]) . 'のバックアップ一覧' : $qm->m['plg_backup']['title_pagebackuplist']; return array('msg' => $title, 'body' => plugin_backup_get_list($page)); } $script = get_script_uri(); $body = '<ul>' . "\n"; if (!$is_layout) { $body .= ' <li><a href="' . $script . '?cmd=backup">' . $qm->m['plg_backup']['backuplist'] . '</a></li>' . "\n"; } $href = $script . '?cmd=backup&page=' . $r_page . '&age=' . $s_age; $is_page = is_page($page); if ($is_page && $action != 'diff') { $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '&action=diff">' . $qm->m['plg_backup']['diff'] . '</a>', $qm->m['plg_backup']['view']) . '</li>' . "\n"; } if ($is_page && $action != 'nowdiff') { $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '&action=nowdiff">' . $qm->m['plg_backup']['nowdiff'] . '</a>', $qm->m['plg_backup']['view']) . '</li>' . "\n"; } if ($action != 'source') { $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '&action=source">' . $qm->m['plg_backup']['source'] . '</a>', $qm->m['plg_backup']['view']) . '</li>' . "\n"; } if (!PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING && $action) { $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '">' . $qm->m['plg_backup']['backup'] . '</a>', $qm->m['plg_backup']['view']) . '</li>' . "\n"; } if ($is_page && $is_layout) { $body .= ' <li><a href="' . $script . '?cmd=edit&page=' . $r_page . '">' . h($layout_pages[$page]) . 'を編集する</a>'; } else { if ($is_page) { $body .= ' <li>' . str_replace('$1', '<a href="' . $script . '?' . $r_page . '">' . $s_page . '</a>', $qm->m['fmt_msg_goto']) . "\n"; } else { $body .= ' <li>' . str_replace('$1', $s_page, $qm->m['plg_backup']['deleted']) . "\n"; } } $backups = get_backup($page); $backups_count = count($backups); if ($s_age > $backups_count) { $s_age = $backups_count; } if ($backups_count > 0) { $body .= ' <ul>' . "\n"; foreach ($backups as $age => $val) { $date = format_date($val['time'], TRUE); $body .= $age == $s_age ? ' <li><em>' . $age . ' ' . $date . '</em></li>' . "\n" : ' <li><a href="' . $script . '?cmd=backup&action=' . $r_action . '&page=' . $r_page . '&age=' . $age . '">' . $age . ' ' . $date . '</a></li>' . "\n"; } $body .= ' </ul>' . "\n"; } $body .= ' </li>' . "\n"; $body .= '</ul>' . "\n"; if ($action == 'diff') { $title = $is_layout ? h($layout_pages[$page]) . ' のバックアップ差分(No.$2)' : $qm->m['plg_backup']['title_backupdiff']; $old = $s_age > 1 ? join('', $backups[$s_age - 1]['data']) : ''; $cur = join('', $backups[$s_age]['data']); $body .= plugin_backup_diff(do_diff($old, $cur)); } else { if ($s_action == 'nowdiff') { $title = $is_layout ? h($layout_pages[$page]) . ' のバックアップの現在との差分(No.$2)' : $qm->m['plg_backup']['title_backupnowdiff']; $old = join('', $backups[$s_age]['data']); $cur = join('', get_source($page)); $body .= plugin_backup_diff(do_diff($old, $cur)); } else { if ($s_action == 'source') { $title = $is_layout ? h($layout_pages[$page]) . ' のバックアップソース(No.$2)' : $qm->m['plg_backup']['title_backupsource']; $body .= '<pre>' . htmlspecialchars(join('', $backups[$s_age]['data'])) . '</pre>' . "\n"; } else { if (PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING) { die_message($qm->m['fmt_err_prohibited']); } else { $title = $is_layout ? h($layout_pages[$page]) . ' のバックアップ(No.$2)' : $qm->m['plg_backup']['title_backup']; $body .= $hr . "\n" . drop_submit(convert_html($backups[$s_age]['data'])); } } } } return array('msg' => str_replace('$2', $s_age, $title), 'body' => $body); }