function is_editable($page) { static $is_editable = array(); if (!isset($is_editable[$page])) { $is_editable[$page] = is_pagename($page) && !is_freeze($page) && !is_cantedit($page); } return $is_editable[$page]; }
function plugin_freeze_action() { global $script, $vars, $function_freeze; $_title_isfreezed = _(' $1 has already been frozen'); $_title_freezed = _(' $1 has been frozen.'); $_title_freeze = _('Freeze $1'); $_msg_invalidpass = _('Invalid password.'); $_msg_freezing = _('Please input the password for freezing.'); $_btn_freeze = _('Freeze'); $page = isset($vars['page']) ? $vars['page'] : ''; if (!$function_freeze || is_cantedit($page) || !is_page($page)) { return array('msg' => '', 'body' => ''); } $pass = isset($vars['pass']) ? $vars['pass'] : NULL; $msg = $body = ''; if (is_freeze($page)) { // Freezed already $msg =& $_title_isfreezed; $body = str_replace('$1', htmlspecialchars(strip_bracket($page)), $_title_isfreezed); } else { if (!auth::check_role('role_adm_contents') || $pass !== NULL && pkwk_login($pass)) { // Freeze $postdata = get_source($page); array_unshift($postdata, "#freeze\n"); file_write(DATA_DIR, $page, join('', $postdata), TRUE); // Update is_freeze($page, TRUE); $vars['cmd'] = 'read'; $msg =& $_title_freezed; $body = ''; } else { // Show a freeze form $msg =& $_title_freeze; $s_page = htmlspecialchars($page); $body = $pass === NULL ? '' : "<p><strong>{$_msg_invalidpass}</strong></p>\n"; $body .= <<<EOD <p>{$_msg_freezing}</p> <form action="{$script}" method="post"> <div> <input type="hidden" name="cmd" value="freeze" /> <input type="hidden" name="page" value="{$s_page}" /> <input type="password" name="pass" size="12" /> <input type="submit" name="ok" value="{$_btn_freeze}" /> </div> </form> EOD; } } return array('msg' => $msg, 'body' => $body); }
function plugin_related_action() { global $vars, $defaultpage; $_page = isset($vars['page']) ? $vars['page'] : ''; if ($_page == '') { $_page = $defaultpage; } // Get related from cache $data = links_get_related_db($_page); if (!empty($data)) { // Hide by array keys (not values) foreach (array_keys($data) as $page) { if (is_cantedit($page) || check_non_list($page)) { unset($data[$page]); } } } // Result $s_word = htmlspecialchars($_page); $msg = 'Backlinks for: ' . $s_word; $retval = '<a href="' . get_page_uri($_page) . '">' . 'Return to ' . $s_word . '</a><br />' . "\n"; if (empty($data)) { $retval .= '<ul><li>No related pages found.</li></ul>' . "\n"; } else { // Show count($data)? ksort($data, SORT_STRING); $retval .= '<ul>' . "\n"; foreach ($data as $page => $time) { $s_page = htmlspecialchars($page); $passage = get_passage($time); $retval .= ' <li><a href="' . get_page_uri($page) . '">' . $s_page . '</a> ' . $passage . '</li>' . "\n"; } $retval .= '</ul>' . "\n"; } return array('msg' => $msg, 'body' => $retval); }
function plugin_rename_getselecttag($page) { global $whatsnew; $pages = array(); foreach (Auth::get_existpages() as $_page) { if (is_cantedit($_page)) { continue; } $selected = $_page === $page ? ' selected' : ''; $s_page = htmlsc($_page); $pages[$_page] = '<option value="' . $s_page . '"' . $selected . '>' . $s_page . '</option>'; } ksort($pages, SORT_STRING); $list = join("\n" . ' ', $pages); return <<<EOD <select name="refer" class="form-control"> \t<option value="" disabled="disabled" selected="selected">--------------------</option> \t{$list} </select> EOD; }
function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE) { global $script, $vars, $rows, $cols, $hr, $function_freeze; global $load_template_func, $load_refer_related; global $notimeupdate; global $_button, $_string; global $ajax, $ctrl_unload; // Newly generate $digest or not if ($digest === FALSE) { $digest = md5(get_source($page, TRUE, TRUE)); } $refer = $template = $addtag = $add_top = $add_ajax = ''; $checked_top = isset($vars['add_top']) ? ' checked="checked"' : ''; $checked_time = isset($vars['notimestamp']) ? ' checked="checked"' : ''; if (isset($vars['add'])) { $addtag = '<input type="hidden" name="add" value="true" />'; $add_top = '<input type="checkbox" name="add_top" value="true"' . $checked_top . ' /><span class="small">' . $_button['addtop'] . '</span>'; } if ($load_template_func && $b_template) { $pages = array(); foreach (auth::get_existpages() as $_page) { if (is_cantedit($_page) || check_non_list($_page)) { continue; } $s_page = htmlspecialchars($_page); $pages[$_page] = ' <option value="' . $s_page . '">' . $s_page . '</option>'; } ksort($pages, SORT_STRING); $s_pages = join("\n", $pages); $template = <<<EOD <select name="template_page"> <option value="">-- {$_button['template']} --</option> {$s_pages} </select> <input type="submit" name="template" value="{$_button['load']}" accesskey="r" /> <br /> EOD; if ($load_refer_related) { if (isset($vars['refer']) && $vars['refer'] != '') { $refer = '[[' . strip_bracket($vars['refer']) . ']]' . "\n\n"; } } } $r_page = rawurlencode($page); $s_page = htmlspecialchars($page); $s_digest = htmlspecialchars($digest); $s_postdata = htmlspecialchars($refer . $postdata); $s_original = isset($vars['original']) ? htmlspecialchars($vars['original']) : $s_postdata; $s_id = isset($vars['id']) ? htmlspecialchars($vars['id']) : ''; $b_preview = isset($vars['preview']); // TRUE when preview $btn_preview = $b_preview ? $_button['repreview'] : $_button['preview']; $s_ticket = md5(MUTIME); if (function_exists('pkwk_session_start') && pkwk_session_start() != 0) { // BugTrack/95 fix Problem: browser RSS request with session $_SESSION[$s_ticket] = md5(get_ticket() . $digest); $_SESSION['origin' . $s_ticket] = md5(get_ticket() . str_replace("\r", '', $s_original)); } if ($ajax && !is_mobile()) { $add_ajax = '<input type="button" name="add_ajax" value="' . $btn_preview . '" accesskey="p" onclick="pukiwiki_apx(this.form.page.value)" />'; } else { $add_ajax = '<input type="submit" name="preview" value="' . $btn_preview . '" accesskey="p" />'; } $add_notimestamp = ''; if ($notimeupdate != 0 && is_page($page)) { // enable 'do not change timestamp' $add_notimestamp = <<<EOD <input type="checkbox" name="notimestamp" id="_edit_form_notimestamp" value="true"{$checked_time} /> <label for="_edit_form_notimestamp"><span class="small">{$_button['notchangetimestamp']}</span></label> EOD; if ($notimeupdate == 2 && auth::check_role('role_adm_contents')) { // enable only administrator $add_notimestamp .= <<<EOD <input type="password" name="pass" size="12" /> EOD; } $add_notimestamp .= ' '; } $refpage = isset($vars['refpage']) ? htmlspecialchars($vars['refpage']) : ''; $add_assistant = edit_form_assistant(); $body = <<<EOD <div id="realview_outer"><div id="realview"></div><br /></div> <form action="{$script}" method="post" id="form"> <div class="edit_form" onmouseup="pukiwiki_pos()" onkeyup="pukiwiki_pos()"> {$template} {$addtag} <input type="hidden" name="cmd" value="edit" /> <input type="hidden" name="page" value="{$s_page}" /> <input type="hidden" name="digest" value="{$s_digest}" /> <input type="hidden" name="ticket" value="{$s_ticket}" /> <input type="hidden" name="id" value="{$s_id}" /> <textarea id="msg" name="msg" rows="{$rows}" cols="{$cols}" onselect="pukiwiki_apv(this.form.page.value,this)" onfocus="pukiwiki_apv(this.form.page.value,this)" onkeyup="pukiwiki_apv(this.form.page.value,this)" onmouseup="pukiwiki_apv(this.form.page.value,this)">{$s_postdata}</textarea> <br /> {$add_assistant} <br /> <input type="submit" name="write" value="{$_button['update']}" accesskey="s" /> {$add_top} {$add_ajax} {$add_notimestamp} <input type="submit" id="cancel" name="cancel" value="{$_button['cancel']}" accesskey="c" /> <textarea id="original" name="original" rows="1" cols="1" style="display:none">{$s_original}</textarea> </div> </form> EOD; if ($ajax) { global $head_tags; $head_tags[] = ' <script type="text/javascript" charset="utf-8" src="' . SKIN_URI . 'ajax/msxml.js"></script>'; $head_tags[] = ' <script type="text/javascript" charset="utf-8" src="' . SKIN_URI . 'ajax/realedit.js"></script>'; } if ($ctrl_unload) { global $head_tags; $head_tags[] = ' <script type="text/javascript" charset="utf-8" src="' . SKIN_URI . 'ajax/ctrl_unload.js"></script>'; } return $body; }
function links_init() { // if (PKWK_READONLY) return; // Do nothing if (auth::check_role('readonly')) { return; } // Do nothing if (ini_get('safe_mode') == '0') { set_time_limit(0); } // Init database foreach (get_existfiles(CACHE_DIR, '.ref') as $cache) { unlink($cache); } foreach (get_existfiles(CACHE_DIR, '.rel') as $cache) { unlink($cache); } $ref = array(); // 参照元 foreach (get_existpages() as $page) { if (is_cantedit($page)) { continue; } $rel = array(); // 参照先 $links = links_get_objects($page); foreach ($links as $_obj) { if (!isset($_obj->type) || $_obj->type != 'pagename' || $_obj->name == $page || $_obj->name == '') { continue; } if (is_a($_obj, 'Link_autoalias')) { $_aliases = get_autoaliases($_obj->name); foreach ($_aliases as $_alias) { if (is_pagename($_alias)) { $rel[] = $_alias; } } } else { $rel[] = $_obj->name; } } $rel = array_unique($rel); foreach ($rel as $_name) { if (!isset($ref[$_name][$page])) { $ref[$_name][$page] = 1; } if (!is_a($_obj, 'Link_autolink')) { $ref[$_name][$page] = 0; } } if (!empty($rel)) { $fp = fopen(CACHE_DIR . encode($page) . '.rel', 'w') or die_message('cannot write ' . htmlspecialchars(CACHE_DIR . encode($page) . '.rel')); fputs($fp, join("\t", $rel)); fclose($fp); } } foreach ($ref as $page => $arr) { $fp = fopen(CACHE_DIR . encode($page) . '.ref', 'w') or die_message('cannot write ' . htmlspecialchars(CACHE_DIR . encode($page) . '.ref')); foreach ($arr as $ref_page => $ref_auto) { fputs($fp, $ref_page . "\t" . $ref_auto . "\n"); } fclose($fp); } }
function plugin_popular_convert() { global $vars; // global $_popular_plugin_frame, $_popular_plugin_today_frame; static $localtime; $_popular_plugin_frame_s = _('popular(%d)'); $_popular_plugin_today_frame_s = _('today\'s(%d)'); $_popular_plugin_yesterday_frame_s = _('yesterday\'s(%d)'); $_popular_plugin_recent_frame_s = _('recent\'s(%d)'); $_popular_plugin_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_frame_s); $_popular_plugin_today_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_today_frame_s); $_popular_plugin_yesterday_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_yesterday_frame_s); $_popular_plugin_recent_frame = sprintf('<h5>%s</h5><div>%%s</div>', $_popular_plugin_recent_frame_s); $view = 'total'; $max = PLUGIN_POPULAR_DEFAULT; $except = ''; if (!isset($localtime)) { list($zone, $zonetime) = set_timezone(DEFAULT_LANG); $localtime = UTIME + $zonetime; } $today = gmdate('Y/m/d', $localtime); // $yesterday = gmdate('Y/m/d', strtotime('yesterday', $localtime)); $yesterday = gmdate('Y/m/d', gmmktime(0, 0, 0, gmdate('m', $localtime), gmdate('d', $localtime) - 1, gmdate('Y', $localtime))); $array = func_get_args(); switch (func_num_args()) { case 3: switch ($array[2]) { case 'today': case 'true': $view = 'today'; break; case 'yesterday': $view = 'yesterday'; break; case 'recent': $view = 'recent'; break; case 'total': case 'false': default: $view = 'total'; break; } case 2: $except = $array[1]; case 1: $max = $array[0]; } $counters = array(); foreach (auth::get_existpages(COUNTER_DIR, '.count') as $file => $page) { if ($except != '' && ereg($except, $page) || is_cantedit($page) || check_non_list($page) || !is_page($page)) { continue; } $array = file(COUNTER_DIR . $file); $count = rtrim($array[0]); $date = rtrim($array[1]); $today_count = rtrim($array[2]); $yesterday_count = rtrim($array[3]); $counters['_' . $page] = 0; if ($view == 'today' or $view == 'recent') { // $pageが数値に見える(たとえばencode('BBS')=424253)とき、 // array_splice()によってキー値が変更されてしまうのを防ぐ // ため、キーに '_' を連結する if ($today == $date) { $counters['_' . $page] = $today_count; } } if ($view == 'yesterday' or $view == 'recent') { if ($today == $date) { $counters['_' . $page] += $yesterday_count; } elseif ($yesterday == $date) { $counters['_' . $page] += $today_count; } } if ($view == 'total') { $counters['_' . $page] = $count; } if ($counters['_' . $page] == 0) { unset($counters['_' . $page]); } } asort($counters, SORT_NUMERIC); // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5 $counters = array_reverse($counters, TRUE); // with array_splice() $counters = array_splice($counters, 0, $max); $items = ''; if (!empty($counters)) { $items = '<ul class="popular_list">' . "\n"; foreach ($counters as $page => $count) { $page = substr($page, 1); $s_page = htmlspecialchars($page); if ($page == $vars['page']) { // No need to link itself, notifies where you just read $pg_passage = get_pg_passage($page, FALSE); $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' . $s_page . '<span class="counter">(' . $count . ')</span></span></li>' . "\n"; } else { $items .= ' <li>' . make_pagelink($page, $s_page . '<span class="counter">(' . $count . ')</span>') . '</li>' . "\n"; } } $items .= '</ul>' . "\n"; } switch ($view) { case 'today': $frame = $_popular_plugin_today_frame; break; case 'yesterday': $frame = $_popular_plugin_yesterday_frame; break; case 'recent': $frame = $_popular_plugin_recent_frame; break; case 'total': default: $frame = $_popular_plugin_frame; break; } return sprintf($frame, count($counters), $items); }