-<?
-// $Id: comment.inc.php,v 1.5 2002/07/01 11:53:20 masui Exp $
-
-global $name_cols, $comment_cols, $msg_format, $name_format;
-global $msg_format, $now_format, $comment_format;
-global $comment_ins, $comment_mail, $comment_no;
-
+<?php
+/////////////////////////////////////////////////
+// PukiWiki - Yet another WikiWikiWeb clone.
+//
+// $Id: comment.inc.php,v 1.22 2004/07/13 13:34:05 henoheno Exp $
+//
/////////////////////////////////////////////////
// ¥³¥á¥ó¥È¤Î̾Á°¥Æ¥¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
-$name_cols = 15;
+define('COMMENT_NAME_COLS',15);
/////////////////////////////////////////////////
// ¥³¥á¥ó¥È¤Î¥Æ¥¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
-$comment_cols = 70;
+define('COMMENT_COLS',70);
/////////////////////////////////////////////////
// ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È
-$name_format = '[[$name]]';
-$msg_format = '$msg';
-$now_format = 'SIZE(10):$now';
+define('COMMENT_NAME_FORMAT','[[$name]]');
+define('COMMENT_MSG_FORMAT','$msg');
+define('COMMENT_NOW_FORMAT','&new{$now};');
/////////////////////////////////////////////////
// ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È(¥³¥á¥ó¥ÈÆâÍÆ)
-$comment_format = '$msg -- $name $now';
+define('COMMENT_FORMAT',"\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
/////////////////////////////////////////////////
// ¥³¥á¥ó¥È¤òÁÞÆþ¤¹¤ë°ÌÃÖ 1:Íó¤ÎÁ° 0:Íó¤Î¸å
-$comment_ins = 1;
+define('COMMENT_INS','1');
/////////////////////////////////////////////////
// ¥³¥á¥ó¥È¤¬Åê¹Æ¤µ¤ì¤¿¾ì¹ç¡¢ÆâÍƤò¥á¡¼¥ë¤ÇÁ÷¤ëÀè
-$comment_mail = FALSE;
-
-// initialize
-$comment_no = 0;
+//define('COMMENT_MAIL',FALSE);
function plugin_comment_action()
{
- global $post,$vars,$script,$cols,$rows,$del_backup,$do_backup,$update_exec,$now;
- global $name_cols,$comment_cols,$name_format,$msg_format,$now_format,$comment_format,$comment_ins;
- global $_title_collided,$_msg_collided,$_title_updated;
- global $_msg_comment_collided,$_title_comment_collided;
-
- if(get_magic_quotes_gpc() {
- if($post["name"]) $post["name"] = stripslashes($post["name"]);
+ global $script, $vars, $now;
+ global $_title_updated, $_no_name;
+ global $_msg_comment_collided, $_title_comment_collided;
+
+ if (! isset($vars['msg']) || $vars['msg'] == '') {
+ return array('msg'=>'', 'body'=>'');
+ } else {
+ $vars['msg'] = preg_replace("/\n/", '', $vars['msg']);
}
-
- $_comment_format = $comment_format;
- if($post["nodate"]=="1") {
- $_comment_format = str_replace('$now','',$_comment_format);
- }
- if($post["msg"]=="") {
- $retvars["msg"] = $name;
- $post["page"] = $post["refer"];
- $vars["page"] = $post["refer"];
- $retvars["body"] = convert_html(join("",file(get_filename(encode($post["refer"])))));
- return $retvars;
- }
- if($post["msg"])
+
+ $head = '';
+ $match = array();
+ if (preg_match('/^(-{1,2})(.*)/', $vars['msg'], $match))
{
- $post["msg"] = preg_replace("/\n/","",$post["msg"]);
+ $head = $match[1];
+ $vars['msg'] = $match[2];
+ }
+ unset($match);
+
+ $_msg = str_replace('$msg', $vars['msg'], COMMENT_MSG_FORMAT);
- $postdata = "";
- $postdata_old = file(get_filename(encode($post["refer"])));
- $comment_no = 0;
+ $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
+ $_name = ($_name == '') ? '' : str_replace('$name', $_name, COMMENT_NAME_FORMAT);
- if($post["name"])
+ $_now = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, COMMENT_NOW_FORMAT);
+
+ $comment = str_replace("\x08MSG\x08", $_msg, COMMENT_FORMAT);
+ $comment = str_replace("\x08NAME\x08",$_name,$comment);
+ $comment = str_replace("\x08NOW\x08", $_now, $comment);
+ $comment = $head . $comment;
+
+ $postdata = '';
+ $postdata_old = get_source($vars['refer']);
+ $comment_no = 0;
+ $comment_ins = ($vars['above'] == '1');
+
+ foreach ($postdata_old as $line)
+ {
+ if (!$comment_ins)
{
- $name = str_replace('$name',$post["name"],$name_format);
+ $postdata .= $line;
}
- if($post["msg"])
+ if (preg_match('/^#comment/', $line) and $comment_no++ == $vars['comment_no'])
{
- if(preg_match("/^(-{1,2})(.*)/",$post["msg"],$match))
+ $postdata = rtrim($postdata)."\n-$comment\n";
+ if ($comment_ins)
{
- $head = $match[1];
- $post["msg"] = $match[2];
+ $postdata .= "\n";
}
-
- $comment = str_replace('$msg',str_replace('$msg',$post["msg"],$msg_format),$_comment_format);
- $comment = str_replace('$name',$name,$comment);
- $comment = str_replace('$now',str_replace('$now',$now,$now_format),$comment);
- $comment = $head.$comment;
}
-
- foreach($postdata_old as $line)
+ if ($comment_ins)
{
- if(!$comment_ins) $postdata .= $line;
- if(preg_match("/^#comment/",$line))
- {
- if($comment_no == $post["comment_no"] && $post[msg]!="")
- {
- $postdata .= "-$comment\n";
- }
- $comment_no++;
- }
- if($comment_ins) $postdata .= $line;
+ $postdata .= $line;
}
-
- $postdata_input = "-$comment\n";
}
-
+
$title = $_title_updated;
- if(md5(@join("",@file(get_filename(encode($post["refer"]))))) != $post["digest"])
+ $body = '';
+ if (md5(@join('',get_source($vars['refer']))) != $vars['digest'])
{
$title = $_title_comment_collided;
- $body = $_msg_comment_collided . make_link($post["refer"]);
+ $body = $_msg_comment_collided . make_pagelink($vars['refer']);
}
- $postdata = user_rules_str($postdata);
-
- // º¹Ê¬¥Õ¥¡¥¤¥ë¤ÎºîÀ®
- if(is_page($post["refer"]))
- $oldpostdata = join("",file(get_filename(encode($post["refer"]))));
- else
- $oldpostdata = "\n";
- if($postdata)
- $diffdata = do_diff($oldpostdata,$postdata);
- file_write(DIFF_DIR,$post["refer"],$diffdata);
- // ¥Ð¥Ã¥¯¥¢¥Ã¥×¤ÎºîÀ®
- if(is_page($post["refer"]))
- $oldposttime = filemtime(get_filename(encode($post["refer"])));
- else
- $oldposttime = time();
-
- // ÊÔ½¸ÆâÍƤ¬²¿¤â½ñ¤«¤ì¤Æ¤¤¤Ê¤¤¤È¥Ð¥Ã¥¯¥¢¥Ã¥×¤âºï½ü¤¹¤ë?¤·¤Ê¤¤¤Ç¤¹¤è¤Í¡£
- if(!$postdata && $del_backup)
- backup_delete(BACKUP_DIR.encode($post["refer"]).".txt");
- else if($do_backup && is_page($post["refer"]))
- make_backup(encode($post["refer"]).".txt",$oldpostdata,$oldposttime);
-
- // ¥Õ¥¡¥¤¥ë¤Î½ñ¤¹þ¤ß
- file_write(DATA_DIR,$post["refer"],$postdata);
-
- // is_page¤Î¥¥ã¥Ã¥·¥å¤ò¥¯¥ê¥¢¤¹¤ë¡£
- is_page($post["refer"],true);
-
- $retvars["msg"] = $title;
- $retvars["body"] = $body;
+ page_write($vars['refer'], $postdata);
- $post["page"] = $post["refer"];
- $vars["page"] = $post["refer"];
+ $retvars['msg'] = $title;
+ $retvars['body'] = $body;
+
+ $vars['page'] = $vars['refer'];
return $retvars;
}
+
function plugin_comment_convert()
{
- global $script,$comment_no,$vars,$name_cols,$comment_cols,$digest;
- global $_btn_comment,$_btn_name,$_msg_comment,$vars;
-
- $options = func_get_args();
+ global $script, $vars, $digest;
+ global $_btn_comment, $_btn_name, $_msg_comment;
+ static $numbers = array();
- $nametags = "$_btn_name<input type=\"text\" name=\"name\" size=\"$name_cols\" />\n";
- if(is_array($options) && in_array("noname",$options)) {
- $nametags = $_msg_comment;
+ if (! isset($numbers[$vars['page']])) {
+ $numbers[$vars['page']] = 0;
}
-
- $nodate = '0';
- if(is_array($options) && in_array("nodate",$options)) {
- $nodate = '1';
+ $comment_no = $numbers[$vars['page']]++;
+
+ $options = func_num_args() ? func_get_args() : array();
+
+ if (in_array('noname',$options)) {
+ $nametags = $_msg_comment;
+ } else {
+ $nametags = $_btn_name . '<input type="text" name="name" size="' . COMMENT_NAME_COLS . "\" />\n";
}
-
- if((arg_check("read")||$vars["cmd"] == ""||arg_check("unfreeze")||arg_check("freeze")||$vars["write"]||$vars["comment"]))
- $button = "<input type=\"submit\" name=\"comment\" value=\"$_btn_comment\" />\n";
-
- $string = "<br /><form action=\"$script\" method=\"post\">\n"
- ."<div>\n"
- ."<input type=\"hidden\" name=\"comment_no\" value=\"$comment_no\" />\n"
- ."<input type=\"hidden\" name=\"refer\" value=\"$vars[page]\" />\n"
- ."<input type=\"hidden\" name=\"plugin\" value=\"comment\" />\n"
- ."<input type=\"hidden\" name=\"nodate\" value=\"$nodate\" />\n"
- ."<input type=\"hidden\" name=\"digest\" value=\"$digest\" />\n"
- ."$nametags"
- ."<input type=\"text\" name=\"msg\" size=\"$comment_cols\" />\n"
- .$button
- ."</div>\n"
- ."</form>";
-
- $comment_no++;
-
+
+ $nodate = in_array('nodate', $options) ? '1' : '0';
+ $above = in_array('above', $options) ? '1' : (in_array('below', $options) ? '0' : COMMENT_INS);
+
+ $s_page = htmlspecialchars($vars['page']);
+ $comment_cols = COMMENT_COLS;
+ $string = <<<EOD
+<br />
+<form action="$script" method="post">
+ <div>
+ <input type="hidden" name="comment_no" value="$comment_no" />
+ <input type="hidden" name="refer" value="$s_page" />
+ <input type="hidden" name="plugin" value="comment" />
+ <input type="hidden" name="nodate" value="$nodate" />
+ <input type="hidden" name="above" value="$above" />
+ <input type="hidden" name="digest" value="$digest" />
+ $nametags
+ <input type="text" name="msg" size="$comment_cols" />
+ <input type="submit" name="comment" value="$_btn_comment" />
+ </div>
+</form>
+EOD;
+
return $string;
}
?>