2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: comment.inc.php,v 1.26 2005/01/23 07:01:56 henoheno Exp $
7 define('PLUGIN_COMMENT_DIRECTION_DEFAULT', '1'); // 1: above 0: below
8 define('PLUGIN_COMMENT_SIZE_MSG', 70);
9 define('PLUGIN_COMMENT_SIZE_NAME', 15);
12 define('PLUGIN_COMMENT_FORMAT_MSG', '$msg');
13 define('PLUGIN_COMMENT_FORMAT_NAME', '[[$name]]');
14 define('PLUGIN_COMMENT_FORMAT_NOW', '&new{$now};');
15 define('PLUGIN_COMMENT_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
16 function plugin_comment_action()
18 global $script, $vars, $now, $_title_updated, $_no_name;
19 global $_msg_comment_collided, $_title_comment_collided;
21 if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
22 if (! isset($vars['msg']) || $vars['msg'] == '')
23 return array('msg'=>'', 'body'=>'');
25 $vars['msg'] = preg_replace("/\n/", '', $vars['msg']);
29 if (preg_match('/^(-{1,2})(.*)/', $vars['msg'], $match)) {
31 $vars['msg'] = $match[2];
35 $_msg = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
37 $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
38 $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
40 $_now = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
42 $comment = str_replace("\x08MSG\x08", $_msg, PLUGIN_COMMENT_FORMAT_STRING);
43 $comment = str_replace("\x08NAME\x08", $_name, $comment);
44 $comment = str_replace("\x08NOW\x08", $_now, $comment);
45 $comment = $head . $comment;
48 $postdata_old = get_source($vars['refer']);
50 $comment_ins = ($vars['above'] == '1');
52 foreach ($postdata_old as $line) {
53 if (! $comment_ins) $postdata .= $line;
54 if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
55 $postdata = rtrim($postdata) . "\n-$comment\n";
56 if ($comment_ins) $postdata .= "\n";
58 if ($comment_ins) $postdata .= $line;
61 $title = $_title_updated;
63 if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
64 $title = $_title_comment_collided;
65 $body = $_msg_comment_collided . make_pagelink($vars['refer']);
68 page_write($vars['refer'], $postdata);
70 $retvars['msg'] = $title;
71 $retvars['body'] = $body;
73 $vars['page'] = $vars['refer'];
78 function plugin_comment_convert()
80 global $script, $vars, $digest;
81 global $_btn_comment, $_btn_name, $_msg_comment;
82 static $numbers = array();
84 if (PKWK_READONLY) return ''; // Show nothing
86 if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
87 $comment_no = $numbers[$vars['page']]++;
89 $options = func_num_args() ? func_get_args() : array();
91 if (in_array('noname', $options)) {
92 $nametags = $_msg_comment;
94 $nametags = $_btn_name .
95 '<input type="text" name="name" size="' . PLUGIN_COMMENT_SIZE_NAME . "\" />\n";
98 $nodate = in_array('nodate', $options) ? '1' : '0';
99 $above = in_array('above', $options) ? '1' :
100 (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
102 $s_page = htmlspecialchars($vars['page']);
103 static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
106 <form action="$script" method="post">
108 <input type="hidden" name="comment_no" value="$comment_no" />
109 <input type="hidden" name="refer" value="$s_page" />
110 <input type="hidden" name="plugin" value="comment" />
111 <input type="hidden" name="nodate" value="$nodate" />
112 <input type="hidden" name="above" value="$above" />
113 <input type="hidden" name="digest" value="$digest" />
115 <input type="text" name="msg" size="$comment_cols" />
116 <input type="submit" name="comment" value="$_btn_comment" />