2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: comment.inc.php,v 1.31 2005/05/06 01:59:34 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");
17 function plugin_comment_action()
19 global $script, $vars, $now, $_title_updated, $_no_name;
20 global $_msg_comment_collided, $_title_comment_collided;
22 if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
24 if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing
26 $vars['msg'] = preg_replace("/\n/", '', $vars['msg']); // Cut LFs
29 if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) {
31 $vars['msg'] = & $match[2];
33 if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing
35 $comment = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
36 if(isset($vars['name']) || ($vars['nodate'] != '1')) {
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') ? '' :
41 str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
43 $comment = str_replace("\x08MSG\x08", $comment, PLUGIN_COMMENT_FORMAT_STRING);
44 $comment = str_replace("\x08NAME\x08", $_name, $comment);
45 $comment = str_replace("\x08NOW\x08", $_now, $comment);
47 $comment = $head . ' ' . $comment;
50 $postdata_old = get_source($vars['refer']);
52 $comment_ins = ($vars['above'] == '1');
54 foreach ($postdata_old as $line) {
55 if (! $comment_ins) $postdata .= $line;
56 if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
57 $postdata = rtrim($postdata) . "\n" .
58 '-' . $comment . "\n";
59 if ($comment_ins) $postdata .= "\n";
61 if ($comment_ins) $postdata .= $line;
64 $title = $_title_updated;
66 if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
67 $title = $_title_comment_collided;
68 $body = $_msg_comment_collided . make_pagelink($vars['refer']);
71 page_write($vars['refer'], $postdata);
73 $retvars['msg'] = $title;
74 $retvars['body'] = $body;
76 $vars['page'] = $vars['refer'];
81 function plugin_comment_convert()
83 global $vars, $digest, $_btn_comment, $_btn_name, $_msg_comment;
84 static $numbers = array();
85 static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
87 if (PKWK_READONLY) return ''; // Show nothing
89 if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
90 $comment_no = $numbers[$vars['page']]++;
92 $options = func_num_args() ? func_get_args() : array();
93 if (in_array('noname', $options)) {
94 $nametags = '<label for="_p_comment_comment_' . $comment_no . '">' .
95 $_msg_comment . '</label>';
97 $nametags = '<label for="_p_comment_name_' . $comment_no . '">' .
98 $_btn_name . '</label>' .
99 '<input type="text" name="name" id="_p_comment_name_' .
100 $comment_no . '" size="' . PLUGIN_COMMENT_SIZE_NAME .
103 $nodate = in_array('nodate', $options) ? '1' : '0';
104 $above = in_array('above', $options) ? '1' :
105 (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
107 $script = get_script_uri();
108 $s_page = htmlspecialchars($vars['page']);
111 <form action="$script" method="post">
113 <input type="hidden" name="plugin" value="comment" />
114 <input type="hidden" name="refer" value="$s_page" />
115 <input type="hidden" name="comment_no" value="$comment_no" />
116 <input type="hidden" name="nodate" value="$nodate" />
117 <input type="hidden" name="above" value="$above" />
118 <input type="hidden" name="digest" value="$digest" />
120 <input type="text" name="msg" id="_p_comment_comment_{$comment_no}" size="$comment_cols" />
121 <input type="submit" name="comment" value="$_btn_comment" />