// http://factage.com/sng/pukiwiki/ // // Special thanks // YukiWiki by Hiroshi Yuki // // http://www.hyuki.com/yukiwiki/ // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // //# $Id: pukiwiki.php 1.3 2002/02/24 13:05:41 sng Exp sng $ ///////////////////////////////////////////////// ///////////////////////////////////////////////// // 設定ファイルの場所 define("INI_FILE","./pukiwiki.ini.php"); //** 初期設定 ** define("S_VERSION","1.3"); define("UTIME",time()); define("HTTP_USER_AGENT",$HTTP_SERVER_VARS["HTTP_USER_AGENT"]); define("PHP_SELF",$HTTP_SERVER_VARS["PHP_SELF"]); define("SERVER_NAME",$HTTP_SERVER_VARS["SERVER_NAME"]); define("MUTIME",getmicrotime()); $script = basename($PHP_SELF); $WikiName = '([A-Z][a-z]+([A-Z][a-z]+)+)'; $BracketName = '\[\[(\[*[^\s\]]+?\]*)\]\]'; $InterWikiName = '\[\[(\[*[^\s\]]+?\]*):(\[*[^>\]]+?\]*)\]\]'; //** 入力値の整形 ** $post = $HTTP_POST_VARS; $get = $HTTP_GET_VARS; if($get["page"]) $get["page"] = rawurldecode($get["page"]); if($post["word"]) $post["word"] = rawurldecode($post["word"]); if($get["word"]) $get["word"] = rawurldecode($get["word"]); if(get_magic_quotes_gpc()) { if($get["page"]) $get["page"] = stripslashes($get["page"]); if($post["page"]) $post["page"] = stripslashes($post["page"]); if($get["word"]) $get["word"] = stripslashes($get["word"]); if($post["word"]) $post["word"] = stripslashes($post["word"]); if($post["msg"]) $post["msg"] = stripslashes($post["msg"]); } if($post["msg"]) { $post["msg"] = preg_replace("/<\/(textarea[^>]*)>/i", "</$1>", $post["msg"]); $post["msg"] = preg_replace("/(\x0D\x0A)/","\n",$post["msg"]); $post["msg"] = preg_replace("/(\x0D)/","\n",$post["msg"]); $post["msg"] = preg_replace("/(\x0A)/","\n",$post["msg"]); } $vars = array_merge($post,$get); $arg = rawurldecode($HTTP_SERVER_VARS["argv"][0]); //** 初期処理 ** $update_exec = ""; // 設定ファイルの読込 @require(INI_FILE); @require(LANG.".lng"); // 設定ファイルの変数チェック $wrong_ini_file = ""; if(!isset($rss_max)) $wrong_ini_file .= '$rss_max '; if(!isset($page_title)) $wrong_ini_file .= '$page_title '; if(!isset($note_hr)) $wrong_ini_file .= '$note_hr '; if(!isset($related_link)) $wrong_ini_file .= '$related_link '; if(!isset($show_passage)) $wrong_ini_file .= '$show_passage '; if(!isset($rule_related_str)) $wrong_ini_file .= '$rule_related_str '; if(!isset($load_template_func)) $wrong_ini_file .= '$load_template_func '; if(!defined("LANG")) $wrong_ini_file .= 'LANG '; if(!defined("PLUGIN_DIR")) $wrong_ini_file .= 'PLUGIN_DIR '; if(!is_writable(DATA_DIR)) die_message("DATA_DIR is not found or not writable."); if(!is_writable(DIFF_DIR)) die_message("DIFF_DIR is not found or not writable."); if($do_backup && !is_writable(BACKUP_DIR)) die_message("BACKUP_DIR is not found or not writable."); if(!file_exists(INI_FILE)) die_message("INI_FILE is not found."); if($wrong_ini_file) die_message("The setting file runs short of information.
The version of a setting file may be old.

These option are not found : $wrong_ini_file"); //if(ini_get("register_globals") !== "0") // die_message("Wrong PHP4 setting in 'register_globals',set value 'Off' to httpd.conf or .htaccess."); if(!file_exists(SKIN_FILE)) die_message("SKIN_FILE is not found."); if(!file_exists(LANG.".lng")) die_message(LANG.".lng(language file) is not found."); if(!file_exists(get_filename(encode($defaultpage)))) touch(get_filename(encode($defaultpage))); if(!file_exists(get_filename(encode($whatsnew)))) touch(get_filename(encode($whatsnew))); if(!file_exists(get_filename(encode($interwiki)))) touch(get_filename(encode($interwiki))); $ins_date = date($date_format,UTIME); $ins_time = date($time_format,UTIME); $ins_week = "(".$weeklabels[date("w",UTIME)].")"; $now = "$ins_date $ins_week $ins_time"; // ** メイン処理 ** // Plug-in hook if(isset($vars["plugin"])) { if(!file_exists(PLUGIN_DIR.$vars["plugin"].".inc.php")) { $vars["plugin"] = ""; } else { require_once(PLUGIN_DIR.$vars["plugin"].".inc.php"); if(!function_exists("plugin_".$vars["plugin"]."_action")) { $vars["plugin"] = ""; } } } // Plug-in action if(!empty($vars["plugin"])) { $retvars = @call_user_func("plugin_".$vars["plugin"]."_action"); $title = strip_bracket($vars["refer"]); $page = make_search($vars["refer"]); if($retvars["msg"]) { $title = str_replace("$1",$title,$retvars["msg"]); $page = str_replace("$1",$page,$retvars["msg"]); } if(!empty($retvars["body"])) { $body = $retvars["body"]; } else { $cmd = "read"; $vars["page"] = $vars["refer"]; $body = @join("",@file(get_filename(encode($vars["refer"])))); $body = convert_html($body); } } // 一覧の表示 else if(arg_check("list")) { header_lastmod($whatsnew); $page = $title = $_title_list; $body = "\n"; } // ファイル名一覧の表示 else if(arg_check("filelist")) { header_lastmod($whatsnew); $page = $title = $_title_filelist; $body = "\n"; } // 編集不可能なページを編集しようとしたとき else if(((arg_check("add") || arg_check("edit") || arg_check("preview")) && (is_freeze($vars["page"]) || !is_editable($vars["page"]) || $vars["page"] == ""))) { $body = $title = str_replace('$1',strip_bracket($vars["page"]),$_title_cannotedit); $page = str_replace('$1',make_search($vars["page"]),$_title_cannotedit); if(is_freeze($vars["page"])) $body .= "($_msg_unfreeze)"; } // 追加 // else if(arg_check("add")) // { // $title = str_replace('$1',strip_bracket($get["page"]),$_title_add); // $page = str_replace('$1',make_search($get["page"]),$_title_add); // $body = "\n"; // $body .= edit_form("",$get["page"],true); // } // 編集 // else if(arg_check("edit")) // { // $postdata = @join("",@file(get_filename(encode($get["page"])))); // // $title = str_replace('$1',strip_bracket($get["page"]),$_title_edit); // $page = str_replace('$1',make_search($get["page"]),$_title_edit); // $body = edit_form($postdata,$get["page"]); //} // プレビュー else if(arg_check("preview") || $post["preview"] || $post["template"]) { if($post["template"] && file_exists(get_filename(encode($post["template_page"])))) { $post["msg"] = @join("",@file(get_filename(encode($post["template_page"])))); } $post["msg"] = preg_replace("/^#freeze\n/","",$post["msg"]); $postdata_input = $post["msg"]; if($post["add"]) { if($post["add_top"]) { $postdata = $post["msg"]; $postdata .= "\n\n"; $postdata .= @join("",@file(get_filename(encode($post["page"])))); } else { $postdata = @join("",@file(get_filename(encode($post["page"])))); $postdata .= "\n\n"; $postdata .= $post["msg"]; } } else { $postdata = $post["msg"]; } $title = str_replace('$1',strip_bracket($post["page"]),$_title_preview); $page = str_replace('$1',make_search($post["page"]),$_title_preview); $body = "$_msg_preview
\n"; if($postdata == "") $body .= "$_msg_preview_delete
\n"; else $body .= "
\n"; if($postdata != "") { $postdata = convert_html($postdata); $body .= "\n" ."\n" ."
\n" .$postdata ."\n
\n"; } if($post["add"]) { if($post["add_top"]) $checked_top = " checked"; $addtag = ''; $add_top = 'ページの上に追加'; } if($post["notimestamp"]) $checked_time = "checked"; $body .= "
\n" ."\n" ."\n" ."\n" ."$addtag\n" ."
\n" ."\n" ."\n" ."$add_top\n" ."$_btn_notchangetimestamp\n" ."
\n"; } // 書き込みもしくは追加もしくはコメントの挿入 else if($post["write"]) { $post["msg"] = preg_replace("/^#freeze\n/","",$post["msg"]); $postdata_input = $post["msg"]; if($post["add"]) { if($post["add_top"]) { $postdata = $post["msg"]; $postdata .= "\n\n"; $postdata .= @join("",@file(get_filename(encode($post["page"])))); } else { $postdata = @join("",@file(get_filename(encode($post["page"])))); $postdata .= "\n\n"; $postdata .= $post["msg"]; } } else { $postdata = $post["msg"]; } if(md5(@join("",@file(get_filename(encode($post["page"]))))) != $post["digest"]) { $title = str_replace('$1',strip_bracket($post["page"]),$_title_collided); $page = str_replace('$1',make_search($post["page"]),$_title_collided); $body .= "$_msg_collided\n"; $body .= "
\n" ."\n" ."\n" ."
\n" ."
\n"; } else { $postdata = user_rules_str($postdata); // 差分ファイルの作成 if(is_page($post["page"])) $oldpostdata = join("",file(get_filename(encode($post["page"])))); else $oldpostdata = "\n"; if($postdata) $diffdata = do_diff($oldpostdata,$postdata); file_write(DIFF_DIR,$post["page"],$diffdata); // バックアップの作成 if(is_page($post["page"])) $oldposttime = filemtime(get_filename(encode($post["page"]))); else $oldposttime = time(); // 編集内容が何も書かれていないとバックアップも削除する?しないですよね。 if(!$postdata && $del_backup) backup_delete(BACKUP_DIR.encode($post["page"]).".txt"); else if($do_backup && is_page($post["page"])) make_backup(encode($post["page"]).".txt",$oldpostdata,$oldposttime); // ファイルの書き込み file_write(DATA_DIR,$post["page"],$postdata); // is_pageのキャッシュをクリアする。 is_page($post["page"],true); if($postdata) { $title = str_replace('$1',strip_bracket($post["page"]),$_title_updated); $page = str_replace('$1',make_search($post["page"]),$_title_updated); $body = convert_html($postdata); } else { $title = str_replace('$1',strip_bracket($post["page"]),$_title_deleted); $page = str_replace('$1',make_search($post["page"]),$_title_deleted); $body = str_replace('$1',strip_bracket($post["page"]),$_title_deleted); } } } // 凍結 else if(arg_check("freeze") && $vars["page"] && $function_freeze) { if(is_freeze($vars["page"])) { $title = str_replace('$1',strip_bracket($vars["page"]),$_title_isfreezed); $page = str_replace('$1',make_search($vars["page"]),$_title_isfreezed); $body = str_replace('$1',strip_bracket($vars["page"]),$_title_isfreezed); } else if(md5($post["pass"]) == $adminpass) { $postdata = file(get_filename(encode($post["page"]))); $postdata = join("",$postdata); $postdata = "#freeze\n".$postdata; file_write(DATA_DIR,$vars["page"],$postdata); $title = str_replace('$1',strip_bracket($vars["page"]),$_title_freezed); $page = str_replace('$1',make_search($vars["page"]),$_title_freezed); $postdata = join("",file(get_filename(encode($vars["page"])))); $postdata = convert_html($postdata); $body = $postdata; } else { $title = str_replace('$1',strip_bracket($vars["page"]),$_title_freeze); $page = str_replace('$1',make_search($vars["page"]),$_title_freeze); $body.= "
\n"; if($post["pass"]) $body .= "$_msg_invalidpass
\n"; else $body.= "$_msg_freezing
\n"; $body.= "
\n"; $body.= "\n"; $body.= "\n"; $body.= "\n"; $body.= "
\n"; } } //凍結の解除 else if(arg_check("unfreeze") && $vars["page"] && $function_freeze) { if(!is_freeze($vars["page"])) { $title = str_replace('$1',strip_bracket($vars["page"]),$_title_isunfreezed); $page = str_replace('$1',make_search($vars["page"]),$_title_isunfreezed); $body = str_replace('$1',strip_bracket($vars["page"]),$_title_isunfreezed); } else if(md5($post["pass"]) == $adminpass) { $postdata = file(get_filename(encode($post["page"]))); array_shift($postdata); $postdata = join("",$postdata); file_write(DATA_DIR,$vars["page"],$postdata); $title = str_replace('$1',strip_bracket($vars["page"]),$_title_unfreezed); $page = str_replace('$1',make_search($vars["page"]),$_title_unfreezed); $postdata = join("",file(get_filename(encode($vars["page"])))); $postdata = convert_html($postdata); $body = $postdata; } else { $title = str_replace('$1',strip_bracket($vars["page"]),$_title_unfreeze); $page = str_replace('$1',make_search($vars["page"]),$_title_unfreeze); $body.= "
\n"; if($post["pass"]) $body .= "$_msg_invalidpass
\n"; else $body.= "$_msg_unfreezing
\n"; $body.= "
\n"; $body.= "\n"; $body.= "\n"; $body.= "\n"; $body.= "
\n"; } } // 差分の表示 else if(arg_check("diff")) { $pagename = strip_bracket($get["page"]); if(!is_page($get["page"])) { $title = $pagename; $page = make_search($vars["page"]); $body = "指定されたページは見つかりませんでした。"; } else { $link = str_replace('$1',"$pagename",$_msg_goto); $body = "\n" ."$hr\n"; } if(!file_exists(DIFF_DIR.encode($get["page"]).".txt") && is_page($get["page"])) { $title = str_replace('$1',strip_bracket($get["page"]),$_title_diff); $page = str_replace('$1',make_search($get["page"]),$_title_diff); $diffdata = file(get_filename(encode($get["page"]))); $body .= "\n" ."
\n"
			.join("",$diffdata)
			."\n"
			."
\n" ."
\n"; } else if(file_exists(DIFF_DIR.encode($get["page"]).".txt")) { $title = str_replace('$1',strip_bracket($get["page"]),$_title_diff); $page = str_replace('$1',make_search($get["page"]),$_title_diff); $diffdata = file(DIFF_DIR.encode($get["page"]).".txt"); $diffdata = preg_replace("//",">",$diffdata); $diffdata = preg_replace("/^(\-)(.*)/"," $2",$diffdata); $diffdata = preg_replace("/^(\+)(.*)/"," $2",$diffdata); $body .= "
\n"
			.join("",$diffdata)
			."\n"
			."
\n"; } } // 検索 else if(arg_check("search")) { if($vars["word"]) { $title = $page = str_replace('$1',$vars["word"],$_title_result); } else { $page = $title = $_title_search; } if($vars["word"]) $body = do_search($vars["word"],$vars["type"]); else $body = "
\n$_msg_searching"; if($vars["type"]=="AND" || !$vars["type"]) $and_check = "checked"; else if($vars["type"]=="OR") $or_check = "checked"; $body .= "
\n" ."\n" ."$_btn_and\n" ."$_btn_or\n" ." \n" ."
\n"; } // バックアップ else if($do_backup && arg_check("backup")) { if($get["page"] && $get["age"] && (file_exists(BACKUP_DIR.encode($get["page"]).".txt") || file_exists(BACKUP_DIR.encode($get["page"]).".gz"))) { $pagename = strip_bracket($get["page"]); $body = "\n
\n$backupdata
\n"; } else { $pagename = strip_bracket($get["page"]); $title = str_replace('$1',$pagename,$_title_backup)."(No.$get[age])"; $page = str_replace('$1',make_search($get["page"]),$_title_backup)."(No.$get[age])"; $backupdata = join("",get_backup($get[age],encode($get["page"]).".txt")); $backupdata = convert_html($backupdata); $body .= "\n" ."$hr\n"; $body .= $backupdata; } if(arg_check("backup_diff") || arg_check("backup_nowdiff")) { $diffdata = preg_replace("//",">",$diffdata); $diffdata = preg_replace("/^(\-)(.*)/"," $2",$diffdata); $diffdata = preg_replace("/^(\+)(.*)/"," $2",$diffdata); $body .= "
\n" ."
  • $_msg_addline
  • \n" ."
  • $_msg_delline
  • \n" ."\n" ."$hr\n" ."
    \n".join("\n",$diffdata)."
    \n"; } } else if($get["page"] && (file_exists(BACKUP_DIR.encode($get["page"]).".txt") || file_exists(BACKUP_DIR.encode($get["page"]).".gz"))) { $title = str_replace('$1',strip_bracket($get["page"]),$_title_pagebackuplist); $page = str_replace('$1',make_search($get["page"]),$_title_pagebackuplist); $body = get_backup_list($get["page"]); } else { $page = $title = $_title_backuplist; $body = get_backup_list(); } } // ヘルプの表示 else if(arg_check("help")) { $title = $page = "ヘルプ"; $body = catrule(); } // MD5パスワードへの変換 else if($vars["md5"]) { $title = $page = "Make password of MD5"; $body = "$vars[md5] : ".md5($vars["md5"]); } else if(arg_check("rss")) { if(!arg_check("rss10")) catrss(1); else catrss(2); die(); } // ページの表示とInterWikiNameの解釈 else if((arg_check("read") && $vars["page"] != "") || (!arg_check("read") && $arg != "" && $vars["page"] == "")) { // アクションを明示的に指定していない場合ページ名として解釈 if($arg != "" && $vars["page"] == "" && $vars["cmd"] == "") { $post["page"] = $arg; $get["page"] = $arg; $vars["page"] = $arg; } // ページ名がWikiNameでなく、BracketNameでなければBracketNameとして解釈 if(!preg_match("/^(($WikiName)|($BracketName)|($InterWikiName))$/",$get["page"])) { $vars["page"] = "[[$vars[page]]]"; $get["page"] = $vars["page"]; } // WikiName、BracketNameが示すページを表示 if(is_page($get["page"])) { $postdata = join("",file(get_filename(encode($get["page"])))); $postdata = convert_html($postdata); $title = strip_bracket($get["page"]); $page = make_search($get["page"]); $body = $postdata; header_lastmod($vars["page"]); } else if(preg_match("/($InterWikiName)/",$get["page"],$match)) { // InterWikiNameの判別とページの表示 $interwikis = open_interwikiname_list(); if(!$interwikis[$match[2]]["url"]) { $title = $page = $_title_invalidiwn; $body = str_replace('$1',strip_bracket($get[page]),str_replace('$2',"InterWikiName",$_msg_invalidiwn)); } else { // 文字エンコーディング if($interwikis[$match[2]]["opt"] == "yw") { // YukiWiki系 if(!preg_match("/$WikiName/",$match[3])) $match[3] = "[[".mb_convert_encoding($match[3],"SJIS","auto")."]]"; } else if($interwikis[$match[2]]["opt"] == "moin") { // moin系 if(function_exists("mb_convert_encoding")) { $match[3] = rawurlencode(mb_convert_encoding($match[3],"EUC-JP","auto")); $match[3] = str_replace("%","_",$match[3]); } else $not_mb = 1; } else if($interwikis[$match[2]]["opt"] == "" || $interwikis[$match[2]]["opt"] == "std") { // 内部文字エンコーディングのままURLエンコード $match[3] = rawurlencode($match[3]); } else if($interwikis[$match[2]]["opt"] == "asis" || $interwikis[$match[2]]["opt"] == "raw") { // URLエンコードしない $match[3] = $match[3]; } else if($interwikis[$match[2]]["opt"] != "") { // エイリアスの変換 if($interwikis[$match[2]]["opt"] == "sjis") $interwikis[$match[2]]["opt"] = "SJIS"; else if($interwikis[$match[2]]["opt"] == "euc") $interwikis[$match[2]]["opt"] = "EUC-JP"; else if($interwikis[$match[2]]["opt"] == "utf8") $interwikis[$match[2]]["opt"] = "UTF-8"; // その他、指定された文字コードへエンコードしてURLエンコード if(function_exists("mb_convert_encoding")) $match[3] = rawurlencode(mb_convert_encoding($match[3],$interwikis[$match[2]]["opt"],"auto")); else $not_mb = 1; } if(strpos($interwikis[$match[2]]["url"],'$1') !== FALSE) $url = str_replace('$1',$match[3],$interwikis[$match[2]]["url"]); else $url = $interwikis[$match[2]]["url"] . $match[3]; if($not_mb) { $title = $page = "Not support mb_jstring."; $body = "This server's PHP does not have \"mb_jstring\" module.Cannot convert encoding."; } else { header("Location: $url"); die(); } } } // WikiName、BracketNameが見つからず、InterWikiNameでもない場合 else { //$title = strip_bracket($get["page"]); //$page = make_search($get["page"]); //$body = "指定されたページは見つかりませんでした。"; $title = str_replace('$1',strip_bracket($get["page"]),$_title_edit); $page = str_replace('$1',make_search($get["page"]),$_title_edit); $body = edit_form("",$get["page"]); } } // 何も指定されない場合、トップページを表示 else { $postdata = join("",file(get_filename(encode($defaultpage)))); $vars["page"] = $defaultpage; $title = strip_bracket($defaultpage); $page = make_search($vars["page"]); $body = convert_html($postdata); header_lastmod($vars["page"]); } // ** 出力処理 ** catbody($title,$page,$body); // ** 各種関数 ** // 本文をページ名から出力 function catbodyall($page,$title="",$pg="") { if($title === "") $title = strip_bracket($page); if($pg === "") $pg = make_search($page); $body = join("",file(get_filename(encode($page)))); $body = convert_html($body); header_lastmod($vars["page"]); catbody($title,$pg,$body); die(); } // 本文を出力 function catbody($title,$page,$body) { global $script,$vars,$arg,$do_backup,$modifier,$modifierlink,$defaultpage,$whatsnew,$hr; global $date_format,$weeklabels,$time_format,$longtaketime,$related_link; global $HTTP_SERVER_VARS,$cantedit; if($vars["page"] && !arg_check("backup") && $vars["page"] != $whatsnew) { $is_page = 1; } $link_add = "$script?cmd=add&page=".rawurlencode($vars["page"]); $link_edit = "$script?cmd=edit&page=".rawurlencode($vars["page"]); $link_diff = "$script?cmd=diff&page=".rawurlencode($vars["page"]); $link_top = "$script?$defaultpage"; $link_list = "$script?cmd=list"; $link_filelist = "$script?cmd=filelist"; $link_search = "$script?cmd=search"; $link_whatsnew = "$script?$whatsnew"; $link_backup = "$script?cmd=backup&page=".rawurlencode($vars["page"]); $link_help = "$script?cmd=help"; if(is_page($vars["page"]) && $is_page) { $fmt = @filemtime(get_filename(encode($vars["page"]))); } if(is_page($vars["page"]) && $related_link && $is_page && !arg_check("edit") && !arg_check("freeze") && !arg_check("unfreeze")) { $related = make_related($vars["page"],false); } if(is_page($vars["page"]) && !in_array($vars["page"],$cantedit) && !arg_check("backup") && !arg_check("edit") && !$vars["preview"]) { $is_read = TRUE; } //if(!$longtaketime) $longtaketime = getmicrotime() - MUTIME; $taketime = sprintf("%01.03f",$longtaketime); require(SKIN_FILE); } // ファイルへの出力 function file_write($dir,$page,$str) { global $post,$update_exec; if($str == "") { @unlink($dir.encode($page).".txt"); } else { if($post["notimestamp"] && is_page($page)) { $timestamp = @filemtime($dir.encode($page).".txt"); } $fp = fopen($dir.encode($page).".txt","w"); while(!flock($fp,LOCK_EX)); fputs($fp,$str); flock($fp,LOCK_UN); fclose($fp); if($timestamp) touch($dir.encode($page).".txt",$timestamp); } if(!$timestamp) put_lastmodified(); if($update_exec) { system($update_exec." > /dev/null &"); } } // バックアップ一覧の取得 function get_backup_list($_page="") { global $script,$date_format,$time_format,$weeklabels,$cantedit; global $_msg_backuplist,$_msg_diff,$_msg_nowdiff,$_msg_source; $ins_date = date($date_format,$val); $ins_time = date($time_format,$val); $ins_week = "(".$weeklabels[date("w",$val)].")"; $ins = "$ins_date $ins_week $ins_time"; if (($dir = @opendir(BACKUP_DIR)) && !$_page) { while($file = readdir($dir)) { if(function_exists(gzopen)) $file = str_replace(".txt",".gz",$file); if($file == ".." || $file == ".") continue; $page = decode(trim(preg_replace("/(\.txt)|(\.gz)$/"," ",$file))); if(in_array($page,$cantedit)) continue; $page_url = rawurlencode($page); $name = $page; $name = strip_bracket($name); if(is_page($page)) $vals[$name]["link"] = "
  • $name
  • "; else $vals[$name]["link"] = "
  • $name
  • "; $vals[$name]["name"] = $page; } closedir($dir); $vals = list_sort($vals); $retvars[] = "\n"; $retval2[$page] .= "
  • $head
  • \n\n"; $retval2[$page] .= "
  • $_msg_symbol
  • \n\n"; $retval2[$page] .= "
  • $_msg_other
  • \n\n"; $top_link = "
    $top_link

    \n"; array_unshift($retval2,$top_link); } else { $retval2 = $retval; } return join("",$retval2); } // 編集フォームの表示 function edit_form($postdata,$page,$add=0) { global $script,$rows,$cols,$hr,$vars,$function_freeze; global $_btn_addtop,$_btn_preview,$_btn_update,$_btn_freeze,$_msg_help,$_btn_notchangetimestamp; global $whatsnew,$_btn_template,$_btn_load,$non_list,$load_template_func; $digest = md5(@join("",@file(get_filename(encode($page))))); if($add) { $addtag = ''; $add_top = ''.$_btn_addtop.''; } if($vars["help"] == "true") $help = $hr.catrule(); else $help = "
    \n\n"; if($function_freeze) $str_freeze = ''; if($load_template_func) { $vals = array(); if ($dir = @opendir(DATA_DIR)) { while($file = readdir($dir)) { $pg_org = decode(trim(preg_replace("/\.txt$/"," ",$file))); if($file == ".." || $file == "." || $pg_org == $whatsnew) continue; if(preg_match("/$non_list/",$pg_org)) continue; $name = strip_bracket($pg_org); $vals[$name] = " "; } closedir($dir); } @ksort($vals); $template = " \n" ."
    \n"; if($vars["refer"]) $refer = $vars["refer"]."\n\n"; } return '
    '.$addtag.'
    '.$template.'
    '.$add_top.' '.$_btn_notchangetimestamp.'
    '.$str_freeze.'
    ' . $help; } // ファイル名を得る(エンコードされている必要有り) function get_filename($pagename) { return DATA_DIR.$pagename.".txt"; } // ページが存在するかしないか function is_page($page,$reload=false) { global $InterWikiName,$_ispage; if(($_ispage[$page] === true || $_ispage[$page] === false) && !$reload) return $_ispage[$page]; if(preg_match("/($InterWikiName)/",$page)) $_ispage[$page] = false; else if(!file_exists(get_filename(encode($page)))) $_ispage[$page] = false; else $_ispage[$page] = true; return $_ispage[$page]; } // ページが編集可能か function is_editable($page) { global $BracketName,$WikiName,$InterWikiName,$cantedit,$_editable; if($_editable === true || $_editable === false) return $_editable; if(preg_match("/^$InterWikiName$/",$page)) $_editable = false; elseif(!preg_match("/^$BracketName$/",$page) && !preg_match("/^$WikiName$/",$page)) $_editable = false; else if(in_array($page,$cantedit)) $_editable = false; else $_editable = true; return $_editable; } // ページが凍結されているか function is_freeze($page) { global $_freeze; if(!is_page($page)) return false; if($_freeze === true || $_freeze === false) return $_freeze; $lines = file(get_filename(encode($page))); if($lines[0] == "#freeze\n") $_freeze = true; else $_freeze = false; return $_freeze; } // プログラムへの引数のチェック function arg_check($str) { global $arg,$vars; return preg_match("/^".$str."/",$vars["cmd"]); } // ページリストのソート function list_sort($values) { if(!is_array($values)) return array(); // ksortのみだと、[[日本語]]、[[英文字]]、英文字のみ、に順に並べ替えられる ksort($values); $vals1 = array(); $vals2 = array(); $vals3 = array(); // 英文字のみ、[[英文字]]、[[日本語]]、の順に並べ替える foreach($values as $key => $val) { if(preg_match("/\[\[[^\w]+\]\]/",$key)) $vals3[$key] = $val; else if(preg_match("/\[\[[\W]+\]\]/",$key)) $vals2[$key] = $val; else $vals1[$key] = $val; } return array_merge($vals1,$vals2,$vals3); } // ページ名のエンコード function encode($key) { $enkey = ''; $arych = preg_split("//", $key, -1, PREG_SPLIT_NO_EMPTY); foreach($arych as $ch) { $enkey .= sprintf("%02X", ord($ch)); } return $enkey; } // ファイル名のデコード function decode($key) { $dekey = ''; for($i=0;$i$top"; foreach ($lines as $line) { if(!preg_match("/^\/\/(.*)/",$line,$comment_out) && $table != 0) { if(!preg_match("/^\|(.+)\|$/",$line,$out)) array_push($result, ""); if(!$out[1] || $table != count(explode("|",$out[1]))) $table = 0; } $comment_out = $comment_out[1]; if(preg_match("/^(\*{1,3})(.*)/",$line,$out)) { $result = array_merge($result,$saved); $saved = array(); $str = inline($out[2]); $level = strlen($out[1]) + 1; array_push($result, "$str $top_link"); $arycontents[] = str_repeat("-",$level-1)."".strip_htmltag($str)."\n"; $content_id++; } else if(preg_match("/^(-{1,4})(.*)/",$line,$out)) { if(strlen($out[1]) == 4) { $result = array_merge($result,$saved); $saved = array(); array_push($result, $hr); } else { back_push('ul', strlen($out[1])); array_push($result, '
  • ' . inline($out[2]) . '
  • '); } } else if (preg_match("/^:([^:]+):(.*)/",$line,$out)) { back_push('dl', 1); array_push($result, '
    ' . inline($out[1]) . '
    ', '
    ' . inline($out[2]) . '
    '); } else if(preg_match("/^(>{1,3})(.*)/",$line,$out)) { back_push('blockquote', strlen($out[1])); array_push($result, ltrim(inline($out[2]))); } else if (preg_match("/^\s*$/",$line,$out)) { $result = array_merge($result,$saved); $saved = array(); //array_unshift($saved, "

    "); array_push($result, "

    "); } else if(preg_match("/^(\s+.*)/",$line,$out)) { back_push('pre', 1); array_push($result, htmlspecialchars($out[1],ENT_NOQUOTES)); } else if(preg_match("/^\|(.+)\|$/",$line,$out)) { $arytable = explode("|",$out[1]); if(!$table) { $result = array_merge($result,$saved); $saved = array(); array_push($result,""); $table = count($arytable); } array_push($result,""); foreach($arytable as $td) { array_push($result,""); } array_push($result,""); } else if(strlen($comment_out) != 0) { array_push($result," "); } else { array_push($result, inline($line)); } } if($table) array_push($result, "
    "); array_push($result,ltrim(inline($td))); array_push($result,"
    "); $result_last = $result = array_merge($result,$saved); $saved = array(); if($content_id != 0) { $result = array(); $saved = array(); foreach($arycontents as $line) { if(preg_match("/^(-{1,3})(.*)/",$line,$out)) { back_push('ul', strlen($out[1])); array_push($result, '

  • '.$out[2].'
  • '); } } $result = array_merge($result,$saved); $saved = array(); $contents = "\n"; $contents .= join("\n",$result); if($strip_link_wall) { $contents = preg_replace("/\[\[([^\]]+)\]\]/","$1",$contents); } } $result_last = inline2($result_last); $result_last = preg_replace("/^#contents/",$contents,$result_last); $str = join("\n", $result_last); if($foot_explain) { $str .= "\n"; $str .= "$note_hr\n"; //$str .= "

    \n"; $str .= join("\n",inline2($foot_explain)); //$str .= "

    \n"; } $longtaketime = getmicrotime() - $start_mtime; $str = preg_replace("/&((lt;)|(gt;))/","&$1",$str); return $str; } // $tagのタグを$levelレベルまで詰める。 function back_push($tag, $level) { global $result,$saved; while (count($saved) > $level) { array_push($result, array_shift($saved)); } if ($saved[0] != "") { $result = array_merge($result,$saved); $saved = array(); } while (count($saved) < $level) { array_unshift($saved, ""); array_push($result, "<$tag>"); } } // リンクの付加その他 function inline($line) { $line = htmlspecialchars($line); $line = preg_replace("/( (\(\(([^\(\)]+)\)\)) | (\(\((.+)\)\)) )/ex","make_note(\"$1\")",$line); return $line; } // リンクの付加その他2 function inline2($str) { global $WikiName,$BracketName,$InterWikiName,$vars,$related,$related_link,$script; $cnts_plain = array(); $cnts_plugin = array(); $arykeep = array(); for($cnt=0;$cnt$1",$str); // Italic $str = preg_replace("/''([^']+?)''/s","$1",$str); // Bold $str = preg_replace("/ ( (\[\[([^\]]+)\:(https?|ftp|news)(:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)\]\]) | (\[(https?|ftp|news)(:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)\s([^\]]+)\]) | (https?|ftp|news)(:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+) | ([[:alnum:]\-_.]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+) | (\[\[([^\]]+)\:([[:alnum:]\-_.]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)\]\]) | ($InterWikiName) | ($BracketName) | ($WikiName) )/ex","make_link('$1')",$str); $str = preg_replace("/#related/",make_related($vars["page"],true),$str); $str = make_user_rules($str); $aryplugins = preg_replace("/^\#([^\(]+)$/ex","plugin_convert('$1','$2')",$aryplugins); $aryplugins = preg_replace("/^\#([^\(]+)\((.*)\)$/ex","plugin_convert('$1','$2')",$aryplugins); $tmp = $str; $str = preg_replace("/^#norelated$/","",$str); if($tmp != $str) $related_link = 0; foreach($cnts_plain as $cnt) $str[$cnt] = $arykeep[$cnt]; foreach($cnts_plugin as $cnt) $str[$cnt] = $aryplugins[$cnt]; return $str; } // Plug-in function plugin_convert($plugin_name,$plugin_args) { $invalid_return = "#${plugin_name}(${plugin_args})"; if($plugin_args !== "") $aryargs = explode(",",$plugin_args); else $aryargs = array(); $retvar = call_user_func_array("plugin_${plugin_name}_convert",$aryargs); if($retvar === FALSE) return $invalid_return; else return $retvar; } // 関連するページ function make_related($page,$_isrule) { global $related_str,$rule_related_str,$related,$_make_related,$vars; $page_name = strip_bracket($vars["page"]); if(!is_array($_make_related)) { $aryrelated = do_search($page,"OR",1); if(is_array($aryrelated)) { foreach($aryrelated as $key => $val) { $new_arylerated[$key.md5($val)] = $val; } } if(is_array($related)) { foreach($related as $key => $val) { $new_arylerated[$key.md5($val)] = $val; } } @krsort($new_arylerated); $_make_related = @array_unique($new_arylerated); } if($_isrule) { if(is_array($_make_related)) { foreach($_make_related as $str) { preg_match("/([^<]+)<\/a>(.*)/",$str,$out); if($out[3]) $title = " title=\"$out[2] $out[3]\""; $aryret[$out[2]] = "$out[2]"; } @ksort($aryret); } } else { $aryret = $_make_related; } if($_isrule) $str = $rule_related_str; else $str = $related_str; return @join($str,$aryret); } // 注釈処理 function make_note($str) { global $note_id,$foot_explain; $str = preg_replace("/^\(\(/","",$str); $str = preg_replace("/\)\)$/","",$str); $str= str_replace("\\'","'",$str); $str = make_user_rules($str); $foot_explain[] = "*$note_id $str
    \n"; $note = "*$note_id"; $note_id++; return $note; } // リンクを付加する function make_link($name) { global $BracketName,$WikiName,$InterWikiName,$script,$link_target,$interwiki_target; global $related,$show_passage,$vars,$defaultpage; $aryconv_htmlspecial = array("&","<",">"); $aryconv_html = array("&","<",">"); $page = $name; if(preg_match("/^\[\[([^\]]+)\:((https?|ftp|news)([^\]]+))\]\]$/",$name,$match)) { $match[2] = str_replace($aryconv_htmlspecial,$aryconv_html,$match[2]); return "$match[1]"; } else if(preg_match("/^\[((https?|ftp|news)([^\]\s]+))\s([^\]]+)\]$/",$name,$match)) { $match[1] = str_replace($aryconv_htmlspecial,$aryconv_html,$match[1]); return "$match[4]"; } else if(preg_match("/^(https?|ftp|news).*?(\.gif|\.png|\.jpeg|\.jpg)?$/",$name,$match)) { $name = str_replace($aryconv_htmlspecial,$aryconv_html,$name); if($match[2]) return ""; else return "$page"; } else if(preg_match("/^\[\[([^\]]+)\:([[:alnum:]\-_.]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)\]\]/",$name,$match)) { $match[1] = str_replace($aryconv_htmlspecial,$aryconv_html,$match[1]); $match[2] = str_replace($aryconv_htmlspecial,$aryconv_html,$match[2]); return "$match[1]"; } else if(preg_match("/^([[:alnum:]\-_]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)/",$name)) { $name = str_replace($aryconv_htmlspecial,$aryconv_html,$name); return "$page"; } else if(preg_match("/^($InterWikiName)$/",str_replace($aryconv_htmlspecial,$aryconv_html,$name))) { $page = strip_bracket($page); $percent_name = str_replace($aryconv_htmlspecial,$aryconv_html,$name); $percent_name = rawurlencode($percent_name); return "$page"; } else if(preg_match("/^($BracketName)|($WikiName)$/",str_replace($aryconv_htmlspecial,$aryconv_html,$name))) { if(preg_match("/^([^>]+)>([^>]+)$/",strip_bracket(str_replace($aryconv_htmlspecial,$aryconv_html,$name)),$match)) { $page = $match[1]; $name = $match[2]; if(!preg_match("/^($BracketName)|($WikiName)$/",$page)) $page = "[[$page]]"; if(!preg_match("/^($BracketName)|($WikiName)$/",$name)) $name = "[[$name]]"; } if(preg_match("/^\[\[\.\/([^\]]*)\]\]/",str_replace($aryconv_htmlspecial,$aryconv_html,$name),$match)) { if(!$match[1]) $name = $vars["page"]; else $name = "[[".strip_bracket($vars[page])."/$match[1]]]"; } else if(preg_match("/^\[\[\..\/([^\]]+)\]\]/",str_replace($aryconv_htmlspecial,$aryconv_html,$name),$match)) { for($i=0;$i$pagename$str"; if($show_passage) { $str_title = "title=\"$pagename $str\""; } return "$page"; } else return "$page?"; } else { return $page; } } // ユーザ定義ルール(ソースを置換する) function user_rules_str($str) { global $str_rules; $arystr = split("\n",$str); // 日付・時刻置換処理 foreach($arystr as $str) { if(substr($str,0,1) != " ") { foreach($str_rules as $rule => $replace) { $str = preg_replace("/$rule/",$replace,$str); } } $retvars[] = $str; } return join("\n",$retvars); } // ユーザ定義ルール(ソースは置換せずコンバート) function make_user_rules($str) { global $user_rules; foreach($user_rules as $rule => $replace) { $str = preg_replace("/$rule/",$replace,$str); } return $str; } // InterWikiName List の解釈(返値:2次元配列) function open_interwikiname_list() { global $interwiki; $retval = array(); $aryinterwikiname = file(get_filename(encode($interwiki))); $cnt = 0; foreach($aryinterwikiname as $line) { if(preg_match("/\[((https?|ftp|news)(\:\/\/[[:alnum:]\+\$\;\?\.%,!#~\*\/\:@&=_\-]+))\s([^\]]+)\]\s?([^\s]*)/",$line,$match)) { $retval[$match[4]]["url"] = $match[1]; $retval[$match[4]]["opt"] = $match[5]; } } return $retval; } // zlib関数が使用できれば、圧縮して使用するためのファイルシステム関数 function backup_fopen($filename,$mode) { if(function_exists(gzopen)) return gzopen(str_replace(".txt",".gz",$filename),$mode); else return fopen($filename,$mode); } function backup_fputs($zp,$str) { if(function_exists(gzputs)) return gzputs($zp,$str); else return fputs($zp,$str); } function backup_fclose($zp) { if(function_exists(gzclose)) return gzclose($zp); else return fclose($zp); } function backup_file($filename) { if(function_exists(gzfile)) return @gzfile(str_replace(".txt",".gz",$filename)); else return @file($filename); } function backup_delete($filename) { if(function_exists(gzopen)) return @unlink(str_replace(".txt",".gz",$filename)); else return @unlink($filename); } // バックアップデータを作成する function make_backup($filename,$body,$oldtime) { global $splitter,$cycle,$maxage; $aryages = array(); $arystrout = array(); if(function_exists(gzfile)) $filename = str_replace(".txt",".gz",$filename); $realfilename = BACKUP_DIR.$filename; if(time() - @filemtime($realfilename) > (60 * 60 * $cycle)) { $aryages = read_backup($filename); if(count($aryages) >= $maxage) { array_shift($aryages); } foreach($aryages as $lines) { foreach($lines as $key => $line) { if($key && $key == "timestamp") { $arystrout[] = "$splitter " . rtrim($line); } else { $arystrout[] = rtrim($line); } } } $strout = join("\n",$arystrout); if(!preg_match("/\n$/",$strout) && trim($strout)) $strout .= "\n"; $body = "$splitter " . $oldtime . "\n" . $body; if(!preg_match("/\n$/",$body)) $body .= "\n"; $fp = backup_fopen($realfilename,"w"); backup_fputs($fp,$strout); backup_fputs($fp,$body); backup_fclose($fp); } return true; } // 特定の世代のバックアップデータを取得 function get_backup($age,$filename) { $aryages = read_backup($filename); foreach($aryages as $key => $lines) { if($key != $age) continue; foreach($lines as $key => $line) { if($key && $key == "timestamp") continue; $retvars[] = $line; } } return $retvars; } // バックアップ情報を返す function get_backup_info($filename) { global $splitter; $lines = array(); $retvars = array(); $lines = backup_file(BACKUP_DIR.$filename); if(!is_array($lines)) return array(); $age = 0; foreach($lines as $line) { preg_match("/^$splitter\s(\d+)$/",trim($line),$match); if($match[1]) { $age++; $retvars[$age] = $match[1]; } } return $retvars; } // バックアップデータ全体を取得 function read_backup($filename) { global $splitter; $lines = array(); $lines = backup_file(BACKUP_DIR.$filename); if(!is_array($lines)) return array(); $age = 0; foreach($lines as $line) { preg_match("/^$splitter\s(\d+)$/",trim($line),$match); if($match[1]) { $age++; $retvars[$age]["timestamp"] = $match[1] . "\n"; } else { $retvars[$age][] = $line; } } return $retvars; } // [[ ]] を取り除く function strip_bracket($str) { global $strip_link_wall; if($strip_link_wall) { preg_match("/^\[\[(.*)\]\]$/",$str,$match); if($match[1]) $str = $match[1]; } return $str; } // HTMLタグを取り除く function strip_htmltag($str) { //$str = preg_replace("/]+>\?<\/a>/","",$str); return preg_replace("/<[^>]+>/","",$str); } // テキスト整形ルールを表示する function catrule() { global $rule_body; return $rule_body; } // エラーメッセージを表示する function die_message($msg) { $title = $page = "Runtime error"; $body = "

    Runtime error

    \n"; $body .= "Error message : $msg\n"; catbody($title,$page,$body); die(); } // 指定されたページの経過時刻 function get_pg_passage($page,$sw=true) { global $_pg_passage,$show_passage; if(!$show_passage) return ""; if(isset($_pg_passage[$page])) { if($sw) return $_pg_passage[$page]["str"]; else return $_pg_passage[$page]["label"]; } if($pgdt = @filemtime(get_filename(encode($page)))) { $pgdt = UTIME - $pgdt; if(ceil($pgdt / 60) < 60) $_pg_passage[$page]["label"] = "(".ceil($pgdt / 60)."m)"; else if(ceil($pgdt / 60 / 60) < 24) $_pg_passage[$page]["label"] = "(".ceil($pgdt / 60 / 60)."h)"; else $_pg_passage[$page]["label"] = "(".ceil($pgdt / 60 / 60 / 24)."d)"; $_pg_passage[$page]["str"] = "".$_pg_passage[$page]["label"].""; } else { $_pg_passage[$page]["label"] = ""; $_pg_passage[$page]["str"] = ""; } if($sw) return $_pg_passage[$page]["str"]; else return $_pg_passage[$page]["label"]; } // 現在時刻をマイクロ秒で取得 function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$sec + (float)$usec); } // ページ名からページ名を検索するリンクを作成 function make_search($page) { global $script,$WikiName; $page = htmlspecialchars($page); $name = strip_bracket($page); $url = rawurlencode($page); //WikiWikiWeb like... //if(preg_match("/^$WikiName$/",$page)) // $name = preg_replace("/([A-Z][a-z]+)/","$1 ",$name); return "$name "; } // Last-Modified ヘッダ function header_lastmod($page) { global $lastmod; if($lastmod && is_page($page)) { header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime(get_filename(encode($page))))." GMT"); } } // RecentChanges の RSS を出力 function catrss($rss) { global $rss_max,$page_title,$WikiName,$BracketName,$script,$whatsnew; $lines = file(get_filename(encode($whatsnew))); header("Content-type: application/xml"); $item = ""; $rdf_li = ""; $cnt = 0; foreach($lines as $line) { if($cnt > $rss_max - 1) break; if(preg_match("/(($WikiName)|($BracketName))/",$line,$match)) { if($match[2]) { $title = $url = $match[1]; } else { if(function_exists("mb_convert_encoding")) $title = mb_convert_encoding(strip_bracket($match[1]),"UTF-8","auto"); else $title = strip_bracket($match[1]); $url = $match[1]; } $desc = date("D, d M Y H:i:s T",filemtime(get_filename(encode($match[1])))); if($rss==2) $items.= "\n"; else $items.= "\n"; $items.= " $title\n"; $items.= " http://".SERVER_NAME.PHP_SELF."?".rawurlencode($url)."\n"; $items.= " $desc\n"; $items.= "\n\n"; $rdf_li.= " \n"; } $cnt++; } if($rss==1) { ?> http://SERVER_NAMEPHP_SELF? PukiWiki RecentChanges ja http://SERVER_NAMEPHP_SELF? PukiWiki RecentChanges