<?php
-/////////////////////////////////////////////////
-// PukiWiki - Yet another WikiWikiWeb clone.
-//
-// $Id: comment.inc.php,v 1.21 2003/10/01 07:00:36 arino Exp $
+// PukiWiki - Yet another WikiWikiWeb clone
+// comment.inc.php
+// Copyright
+// 2002-2017 PukiWiki Development Team
+// 2001-2002 Originally written by yu-ji
+// License: GPL v2 or (at your option) any later version
//
+// Comment plugin
+
+define('PLUGIN_COMMENT_DIRECTION_DEFAULT', '1'); // 1: above 0: below
+define('PLUGIN_COMMENT_SIZE_MSG', 70);
+define('PLUGIN_COMMENT_SIZE_NAME', 15);
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤Î̾Á°¥Æ¥¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
-define('COMMENT_NAME_COLS',15);
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤Î¥Æ¥¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
-define('COMMENT_COLS',70);
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È
-define('COMMENT_NAME_FORMAT','[[$name]]');
-define('COMMENT_MSG_FORMAT','$msg');
-define('COMMENT_NOW_FORMAT','&new{$now};');
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È(¥³¥á¥ó¥ÈÆâÍÆ)
-define('COMMENT_FORMAT',"\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤òÁÞÆþ¤¹¤ë°ÌÃÖ 1:Íó¤ÎÁ° 0:Íó¤Î¸å
-define('COMMENT_INS','1');
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤¬Åê¹Æ¤µ¤ì¤¿¾ì¹ç¡¢ÆâÍƤò¥á¡¼¥ë¤ÇÁ÷¤ëÀè
-//define('COMMENT_MAIL',FALSE);
+// ----
+define('PLUGIN_COMMENT_FORMAT_MSG', '$msg');
+define('PLUGIN_COMMENT_FORMAT_NAME', '[[$name]]');
+define('PLUGIN_COMMENT_FORMAT_NOW', '&new{$now};');
+define('PLUGIN_COMMENT_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
function plugin_comment_action()
{
- global $script,$vars,$post,$now;
- global $_title_updated,$_no_name;
- global $_msg_comment_collided,$_title_comment_collided;
-
- $post['msg'] = preg_replace("/\n/",'',$post['msg']);
-
- if ($post['msg'] == '')
- {
- return array('msg'=>'','body'=>'');
- }
-
+ global $vars, $now, $_title_updated, $_no_name;
+ global $_msg_comment_collided, $_title_comment_collided;
+ global $_comment_plugin_fail_msg;
+
+ if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
+
+ if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing
+
+ $vars['msg'] = str_replace("\n", '', $vars['msg']); // Cut LFs
$head = '';
- if (preg_match('/^(-{1,2})(.*)/',$post['msg'],$match))
- {
- $head = $match[1];
- $post['msg'] = $match[2];
+ $match = array();
+ if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) {
+ $head = & $match[1];
+ $vars['msg'] = & $match[2];
}
-
- $_msg = str_replace('$msg',$post['msg'],COMMENT_MSG_FORMAT);
- $_name = $post['name'] == '' ? $_no_name : $post['name'];
- $_name = ($_name == '') ? '' : str_replace('$name',$_name,COMMENT_NAME_FORMAT);
- $_now = ($post['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($post['refer']);
- $comment_no = 0;
- $comment_ins = ($post['above'] == '1');
-
- foreach ($postdata_old as $line)
- {
- if (!$comment_ins)
- {
- $postdata .= $line;
- }
- if (preg_match('/^#comment/',$line) and $comment_no++ == $post['comment_no'])
- {
- $postdata = rtrim($postdata)."\n-$comment\n";
- if ($comment_ins)
- {
- $postdata .= "\n";
+ if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing
+
+ $comment = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
+ if(isset($vars['name']) || ($vars['nodate'] != '1')) {
+ $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
+ $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
+ $_now = ($vars['nodate'] == '1') ? '' :
+ str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
+ $comment = str_replace("\x08MSG\x08", $comment, PLUGIN_COMMENT_FORMAT_STRING);
+ $comment = str_replace("\x08NAME\x08", $_name, $comment);
+ $comment = str_replace("\x08NOW\x08", $_now, $comment);
+ }
+ $comment = '-' . $head . ' ' . $comment;
+
+ $postdata = '';
+ $comment_no = 0;
+ $above = (isset($vars['above']) && $vars['above'] == '1');
+ $comment_added = FALSE;
+ foreach (get_source($vars['refer']) as $line) {
+ if (! $above) $postdata .= $line;
+ if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
+ $comment_added = TRUE;
+ if ($above) {
+ $postdata = rtrim($postdata) . "\n" .
+ $comment . "\n" .
+ "\n"; // Insert one blank line above #commment, to avoid indentation
+ } else {
+ $postdata = rtrim($postdata) . "\n" .
+ $comment . "\n";
}
}
- if ($comment_ins)
- {
- $postdata .= $line;
- }
+ if ($above) $postdata .= $line;
}
-
$title = $_title_updated;
$body = '';
- if (md5(@join('',get_source($post['refer']))) != $post['digest'])
- {
+ if ($comment_added) {
+ // new comment added
+ if (md5(get_source($vars['refer'], TRUE, TRUE)) !== $vars['digest']) {
+ $title = $_title_comment_collided;
+ $body = $_msg_comment_collided . make_pagelink($vars['refer']);
+ }
+ page_write($vars['refer'], $postdata);
+ } else {
+ // failed to add the comment
$title = $_title_comment_collided;
- $body = $_msg_comment_collided . make_pagelink($post['refer']);
+ $body = $_comment_plugin_fail_msg . make_pagelink($vars['refer']);
}
-
- page_write($post['refer'],$postdata);
-
- $retvars['msg'] = $title;
+ $retvars['msg'] = $title;
$retvars['body'] = $body;
-
- $post['page'] = $vars['page'] = $post['refer'];
-
+ $vars['page'] = $vars['refer'];
return $retvars;
}
+
function plugin_comment_convert()
{
- global $script,$vars,$digest;
- global $_btn_comment,$_btn_name,$_msg_comment;
+ global $vars, $digest, $_btn_comment, $_btn_name, $_msg_comment;
static $numbers = array();
-
- if (!array_key_exists($vars['page'],$numbers))
- {
- $numbers[$vars['page']] = 0;
- }
+ static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
+
+ if (PKWK_READONLY) return ''; // Show nothing
+
+ if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
$comment_no = $numbers[$vars['page']]++;
-
+
$options = func_num_args() ? func_get_args() : array();
-
- if (in_array('noname',$options))
- {
- $nametags = $_msg_comment;
+ if (in_array('noname', $options)) {
+ $nametags = '<label for="_p_comment_comment_' . $comment_no . '">' .
+ $_msg_comment . '</label>';
+ } else {
+ $nametags = '<label for="_p_comment_name_' . $comment_no . '">' .
+ $_btn_name . '</label>' .
+ '<input type="text" name="name" id="_p_comment_name_' .
+ $comment_no . '" size="' . PLUGIN_COMMENT_SIZE_NAME .
+ '" />' . "\n";
}
- else
- {
- $nametags = $_btn_name.'<input type="text" name="name" size="'.COMMENT_NAME_COLS."\" />\n";
- }
-
- $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;
+ $nodate = in_array('nodate', $options) ? '1' : '0';
+ $above = in_array('above', $options) ? '1' :
+ (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
+
+ $script = get_base_uri();
+ $s_page = htmlsc($vars['page']);
$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="refer" value="$s_page" />
+ <input type="hidden" name="comment_no" value="$comment_no" />
<input type="hidden" name="nodate" value="$nodate" />
- <input type="hidden" name="above" value="$above" />
+ <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="text" name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" />
<input type="submit" name="comment" value="$_btn_comment" />
</div>
</form>
EOD;
-
+
return $string;
}
-?>