2 // PukiWiki - Yet another WikiWikiWeb clone
5 // 2002-2020 PukiWiki Development Team
6 // 2001-2002 Originally written by yu-ji
7 // License: GPL v2 or (at your option) any later version
11 define('PLUGIN_COMMENT_DIRECTION_DEFAULT', '1'); // 1: above 0: below
14 define('PLUGIN_COMMENT_FORMAT_MSG', '$msg');
15 define('PLUGIN_COMMENT_FORMAT_NAME', '[[$name]]');
16 define('PLUGIN_COMMENT_FORMAT_NOW', '&new{$now};');
17 define('PLUGIN_COMMENT_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
19 function plugin_comment_action()
21 global $vars, $now, $_title_updated, $_no_name;
22 global $_msg_comment_collided, $_title_comment_collided;
23 global $_comment_plugin_fail_msg;
25 if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
27 if (! isset($vars['msg'])) return array('msg'=>'', 'body'=>''); // Do nothing
29 $vars['msg'] = str_replace("\n", '', $vars['msg']); // Cut LFs
32 if (preg_match('/^(-{1,2})-*\s*(.*)/', $vars['msg'], $match)) {
34 $vars['msg'] = & $match[2];
36 if ($vars['msg'] == '') return array('msg'=>'', 'body'=>''); // Do nothing
38 $comment = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
39 if(isset($vars['name']) || ($vars['nodate'] != '1')) {
40 $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
41 $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
42 $_now = ($vars['nodate'] == '1') ? '' :
43 str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
44 $comment = str_replace("\x08MSG\x08", $comment, PLUGIN_COMMENT_FORMAT_STRING);
45 $comment = str_replace("\x08NAME\x08", $_name, $comment);
46 $comment = str_replace("\x08NOW\x08", $_now, $comment);
48 $comment = '-' . $head . ' ' . $comment;
52 $above = (isset($vars['above']) && $vars['above'] == '1');
53 $comment_added = FALSE;
54 foreach (get_source($vars['refer']) as $line) {
55 if (! $above) $postdata .= $line;
56 if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
57 $comment_added = TRUE;
59 $postdata = rtrim($postdata) . "\n" .
61 "\n"; // Insert one blank line above #commment, to avoid indentation
63 $postdata = rtrim($postdata) . "\n" .
67 if ($above) $postdata .= $line;
69 $title = $_title_updated;
73 if (md5(get_source($vars['refer'], TRUE, TRUE)) !== $vars['digest']) {
74 $title = $_title_comment_collided;
75 $body = $_msg_comment_collided . make_pagelink($vars['refer']);
77 page_write($vars['refer'], $postdata);
79 // failed to add the comment
80 $title = $_title_comment_collided;
81 $body = $_comment_plugin_fail_msg . make_pagelink($vars['refer']);
83 $retvars['msg'] = $title;
84 $retvars['body'] = $body;
85 $vars['page'] = $vars['refer'];
89 function plugin_comment_convert()
91 global $vars, $digest, $_btn_comment, $_btn_name, $_msg_comment;
92 static $numbers = array();
94 if (PKWK_READONLY) return ''; // Show nothing
96 $page = $vars['page'];
97 if (! isset($numbers[$page])) $numbers[$page] = 0;
98 $comment_no = $numbers[$page]++;
100 $options = func_num_args() ? func_get_args() : array();
101 if (in_array('noname', $options)) {
102 $nametags = '<label for="_p_comment_comment_' . $comment_no . '">' .
103 $_msg_comment . '</label>';
105 $nametags = '<label for="_p_comment_name_' . $comment_no . '">' .
106 $_btn_name . '</label>' .
107 '<input type="text" name="name" id="_p_comment_name_' .
108 $comment_no . '" class="_p_comment_name" />' . "\n";
110 $nodate = in_array('nodate', $options) ? '1' : '0';
111 $above = in_array('above', $options) ? '1' :
112 (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
114 $script = get_page_uri($page);
115 $s_page = htmlsc($page);
118 <form action="$script" method="post">
120 <input type="hidden" name="plugin" value="comment" />
121 <input type="hidden" name="refer" value="$s_page" />
122 <input type="hidden" name="comment_no" value="$comment_no" />
123 <input type="hidden" name="nodate" value="$nodate" />
124 <input type="hidden" name="above" value="$above" />
125 <input type="hidden" name="digest" value="$digest" />
127 <input type="text" name="msg" id="_p_comment_comment_{$comment_no}" class="_p_comment_msg" />
128 <input type="submit" name="comment" value="$_btn_comment" />